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:

matrix (list or 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]

Return the matrix unwrapped (if needed).

__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).

rescale(scale)[source]

Return a new rescaled Operator by scaling the matrix.

rescale_inplace(scale)[source]

In-place rescaling of the operator matrix.