mimiqcircuits.operations.operators.custom

Classes

Operator(mat)

N-qubit operator specified by a \(2^N \times 2^N\) matrix.

class mimiqcircuits.operations.operators.custom.Operator(mat)[source]

Bases: AbstractOperator

N-qubit operator specified by a \(2^N \times 2^N\) matrix.

Note

Only one and two qubit operators are supported.

This operator does not have to be unitary.

See also

AbstractOperator, ExpectationValue, KrausChannel

Parameters:

mat (symengine.Matrix | sympy.Matrix | np.ndarray) – The \(2^N \times 2^N\) matrix representing the operator.

Examples

>>> from mimiqcircuits import *
>>> from symengine import Matrix
>>> op = Operator(Matrix([[1, 2], [3, 4]]))
>>> op
1-qubit Operator:
├── 1 2
└── 3 4
>>> op = Operator(Matrix([[1, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 1]]))
>>> op
2-qubit Operator:
├── 1 0 0 1
├── 0 0 0 0
├── 0 0 0 0
└── 1 0 0 1

Operators can be used for expectation values:

>>> c = Circuit()
>>> c.push(ExpectationValue(Operator(Matrix([[0, 1], [0, 0]]))), 1, 1)
2-qubit, 2-zvar circuit with 1 instruction:
└── ⟨Operator([[0, 1], [0, 0]])⟩ @ q[1], z[1]
__init__(mat)[source]
static is_valid_power_of_2(n)[source]

Check if a number is a power of 2.

opname()[source]

Return the operator name.

property parnames

Return the parameter names.

iswrapper()[source]

Placeholder method.

unwrappedmatrix()[source]

Numeric matrix representation as a numpy.ndarray[complex128].

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.

Operators fully determined by their type cache the result at class level as a read-only array.

Raises:

UnexpectedSymbolics – If any parameter is still symbolic.

Returns:

complex128 matrix.

Return type:

numpy.ndarray

__repr__()[source]

Return a pretty-printed representation.

__str__()[source]

String representation for printing.

pretty_print()[source]

Return a detailed string representation of the operator.

opsquared()[source]

Return the operator squared (O’ * O).