mimiqcircuits.operations.gates.customdiagonal

Custom diagonal gate definition.

Classes

GateCustomDiagonal(diagonal)

Gate diagonal in the computational basis, given by its diagonal.

class mimiqcircuits.operations.gates.customdiagonal.GateCustomDiagonal(diagonal)[source]

Bases: Gate

Gate diagonal in the computational basis, given by its diagonal.

Same role as GateCustom, but only the 2**n diagonal entries are stored, so a wide diagonal block costs 2**n numbers instead of 4**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 as GateCustom.

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]
__init__(diagonal)[source]
matrix()[source]

Dense matrix, entries evaluated numerically where possible.

Not inherited from AbstractOperator for the same reason as GateCustom.matrix(): that version memoises on the class for parameter-free operators, which would make every instance share whichever matrix was built first.

diagonal()[source]

The stored diagonal entries, evaluated numerically where possible.

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 of matrix(). It bypasses SymEngine entirely for gates that override _matrix_numeric() — see mimiqcircuits.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:

complex128 matrix.

Return type:

numpy.ndarray

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.

pretty_print()[source]
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)