mimiqcircuits.operations.operator¶
AbstractOperator base class.
Classes
Supertype for all N-qubit operators. |
Exceptions
|
Raised when |
- class mimiqcircuits.operations.operator.AbstractOperator[source]¶
Bases:
OperationSupertype for all N-qubit operators.
Note that objects of type AbstractOperator do not need to be unitary.
Operators can be used to define Kraus channels (noise) (see
krauschannel), or to compute expectation values (seeExpectationValue). However, they will return an error if directly applied to states.See also
- iswrapper()[source]¶
Check if the operator is a wrapper around another operator.
This method should be overridden in subclasses to return True if the operator is acting as a wrapper around another operation or object, and False otherwise.
- Returns:
Always returns False in the base class. Subclasses should override this method to provide the appropriate logic.
- Return type:
- static isunitary()[source]¶
Check if the object is unitary.
By default, this method returns False unless explicitly overridden in a subclass.
- matrix()[source]¶
Return the SymEngine matrix representation of the operator.
Constant (parameter-free) operators are cached at class level, so repeated calls on, say,
GateX()are O(1). Numeric parametric operators build a SymEngine matrix through_matrix()and then evaluate each non-zero entry to a floating-point scalar. Genuinely symbolic operators return the raw SymEngine expression untouched — the oldsympy.simplifystep is deliberately gone; it was the main hot spot and produced no information the caller couldn’t recover with their own simplification pass.- Returns:
The matrix representation.
- Return type:
symengine.Matrix
- 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.
- power(n)[source]¶
Raise an error, as powers of non-unitary operators are not supported.
This method is not implemented for non-unitary operators and will raise a NotImplementedError if called.
- Parameters:
n (int) – The exponent to which the operator would be raised.
- Raises:
NotImplementedError – If the method is called.
- 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 ofmatrix(). It bypasses SymEngine entirely for gates that override_matrix_numeric()— seemimiqcircuits.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:
complex128matrix.- Return type:
- 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)