mimiqcircuits.operations.operators.custom¶
Classes
|
N-qubit operator given by a \(2^N \times 2^N\) matrix. |
- class Operator(mat)[source]¶
Bases:
AbstractOperatorN-qubit operator given by a \(2^N \times 2^N\) matrix.
The matrix does not have to be unitary. Only one- and two-qubit operators are supported. The matrix is stored as a SymEngine matrix in the
matattribute.- Parameters:
mat (symengine.Matrix | sympy.Matrix | numpy.ndarray) – The square matrix of the operator, of size 2 or 4.
- Raises:
TypeError – If
matis not a SymEngine, SymPy or NumPy matrix.ValueError – If
matis not square, its size is not a power of 2, or it acts on more than two qubits.
See also
AbstractOperator,ExpectationValue,KrausExamples
>>> 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]
- property parnames¶
("mat",).- Type:
Names of the parameters
- unwrappedmatrix()[source]¶
Return the numeric matrix of the operator as a NumPy array.
Use this instead of
matrix()when plain numbers are needed, for example to feed a simulator. Gates with a fast numeric path (seemimiqcircuits.numerics) skip SymEngine entirely; other operators build the SymEngine matrix and convert it.Operators fully determined by their type return a cached, read-only array. Copy it before modifying it.
- Returns:
The matrix, with dtype
complex128.- Return type:
- Raises:
UnexpectedSymbolics – If any parameter is still symbolic.
Examples
>>> from mimiqcircuits import * >>> GateX().unwrappedmatrix() array([[0.+0.j, 1.+0.j], [1.+0.j, 0.+0.j]])