mimiqcircuits.operations.gates.customdiagonal¶
Custom diagonal gate definition.
Classes
|
Gate diagonal in the computational basis, given by its diagonal. |
- class mimiqcircuits.operations.gates.customdiagonal.GateCustomDiagonal(diagonal)[source]¶
Bases:
GateGate diagonal in the computational basis, given by its diagonal.
Same role as
GateCustom, but only the2**ndiagonal entries are stored, so a wide diagonal block costs2**nnumbers instead of4**n. Every entry must be a phase,abs(d) == 1.The entries follow the diagonal of the dense matrix, in the basis
|0...0>, ..., |1...1>with the first target qubit as the most significant bit — the same convention asGateCustom.Examples
>>> from mimiqcircuits import Circuit, GateCustomDiagonal >>> c = Circuit() >>> c.push(GateCustomDiagonal([1, 1, 1, -1]), 0, 1) 2-qubit circuit with 1 instruction: └── CustomDiagonal(...) @ q[0:1]
- matrix()[source]¶
Dense matrix, entries evaluated numerically where possible.
Not inherited from
AbstractOperatorfor the same reason asGateCustom.matrix(): that version memoises on the class for parameter-free operators, which would make every instance share whichever matrix was built first.
- unwrappeddiagonal()[source]¶
The diagonal as a
numpy.ndarray[complex128].- Raises:
TypeError – if any entry is still symbolic.
- unwrappedmatrix()[source]¶
Numeric matrix representation as a
numpy.ndarray[complex128].This is the Python analogue of Julia’s
unwrappedmatrix(::AbstractOperator): simulators and anything else that wants raw numbers (e.g. TensorWeaver) should call this instead ofmatrix(). It bypasses SymEngine entirely for gates that override_matrix_numeric()— seemimiqcircuits.numerics— and otherwise falls back to building the SymEngine matrix and casting it.Constant gates cache the result at class level.
- Raises:
UnexpectedSymbolics – If any parameter is still symbolic.
- Returns:
complex128matrix.- Return type:
- property num_qubits¶
- inverse()[source]¶
Raise an error, as non-unitary operators cannot be inverted.
This method is not implemented for non-unitary operators and will raise a NotImplementedError if called.
- Raises:
NotImplementedError – If the method is called.
- evaluate(d)[source]¶
Substitute the symbolic parameters of the operator with numerical values.
This method evaluates the operator’s symbolic parameters using the values provided in the dictionary d. If the operator has no parameters, it returns the same instance. Otherwise, it creates a new instance of the operator with updated numerical parameters.
- Parameters:
d (dict) – A dictionary where keys are symbolic parameter names and values are values for substitution.
Example
>>> from symengine import * >>> from mimiqcircuits import * >>> theta = symbols('theta') >>> op = GateRX(theta) >>> evaluated_op = op.evaluate({'theta': 0.5}) >>> print(evaluated_op) RX(0.5)