mimiqcircuits.operations.operator¶
AbstractOperator base class.
Classes
Base class for all N-qubit operators. |
Exceptions
|
Raised when a numeric matrix is requested for an operator whose parameters are still symbolic. |
- class AbstractOperator[source]¶
Bases:
OperationBase class for all N-qubit operators.
An operator is anything with a matrix representation, see
matrix(). It does not need to be unitary:Gateis the unitary subclass, while operators such asSigmaMinus,Projector0orDiagonalOpare not unitary.Non-unitary operators cannot be pushed to a circuit on their own. They are used to define Kraus channels (see
Kraus) and to compute expectation values (seeExpectationValue).Examples
>>> from mimiqcircuits import * >>> # a non-unitary operator, used here to measure an expectation value >>> op = SigmaMinus() >>> op.isunitary() False >>> c = Circuit() >>> c.push(ExpectationValue(op), 0, 0) 1-qubit, 1-zvar circuit with 1 instruction: └── ⟨SigmaMinus(1)⟩ @ q[0], z[0]
See also
- iswrapper()[source]¶
Whether the operator wraps another operation.
Truefor composite operators such asControl,Power,InverseorParallel,Falsefor plain operators and gates.- Returns:
bool
- static isunitary()[source]¶
Whether the operator is unitary.
- Returns:
Truefor gates,Falsefor general operators.- Return type:
- supports_canonical_rewrite()[source]¶
Whether
CanonicalRewritemay decompose this operator.- Returns:
Truefor gates,Falsefor other operators.- Return type:
- matrix()[source]¶
Return the SymEngine matrix representation of the operator.
Operators fully determined by their type (parameter-free gates and named wrappers such as
GateTorGateCX) build their matrix once per class and return a fresh copy of it on each call, so mutating the result never affects later calls. Numeric parametric operators build a SymEngine matrix through_matrix()and then evaluate each non-zero entry to a floating-point scalar. Symbolic operators return the SymEngine expressions without simplifying them; callers that want a simplified form apply their own simplification.- Returns:
The matrix representation.
- Return type:
symengine.Matrix
Examples
>>> from mimiqcircuits import * >>> GateX().matrix() [0, 1.0] [1.0, 0]
- inverse()[source]¶
Return the inverse of the operator.
General operators are not unitary and have no inverse here, so this always raises. Gates override it.
- Raises:
NotImplementedError – Always.
- rescale(scale)[source]¶
Return a copy of the operator multiplied by
scale.Every parameter in
parnamesis multiplied byscale, which is the right thing for operators linear in their parameters (projectors, sigmas,DiagonalOp,Operator). Operators that are not linear in their parameters override this.- Raises:
NotImplementedError – If the operator has no parameters to scale.
- rescale_inplace(scale)[source]¶
Multiply the operator by
scalein place and return it.In-place counterpart of
rescale().- Raises:
NotImplementedError – If the operator has no parameters to scale.
- power(n)[source]¶
Return the operator raised to the power
n.Powers of general operators are not supported, so this always raises. Gates override it.
- Parameters:
n – The exponent.
- Raises:
NotImplementedError – Always.
- 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]])
- evaluate(d)[source]¶
Substitute values for the symbols in the operator’s parameters.
Operators without parameters return themselves. Otherwise a new operator of the same type is built from the substituted parameters. Symbols missing from
dstay symbolic.- Parameters:
d (dict) – Map from symbols (or their names) to values.
- Returns:
The operator with the symbols substituted.
- Return type:
Examples
>>> from symengine import symbols >>> from mimiqcircuits import * >>> theta = symbols('theta') >>> # bind theta to a number >>> GateRX(theta).evaluate({theta: 0.5}) RX(0.5)