mimiqcircuits.operations.power¶
Power operation.
Functions
|
Decorator to register a canonical Power subclass. |
|
Register an alias for a power gate definition |
|
Decorator to register a decomposition function for a gate type |
Classes
|
Power operation. |
- class mimiqcircuits.operations.power.Power(operation=None, exponent=None, *args, **kwargs)[source]¶
Bases:
GatePower operation.
Represents a Power operation raised to a specified exponent.
When a canonical subclass is registered (e.g., GateS for Power(GateZ(), 1/2)), constructing Power with matching arguments will return an instance of that subclass. This enables isinstance() checks to work correctly:
Examples
>>> from mimiqcircuits import * >>> isinstance(Power(GateZ(), 0.5), GateS) True >>> c= Circuit() >>> c.push(Power(GateX(),1/2),1) 2-qubit circuit with 1 instruction: └── SX @ q[1] >>> c.push(Power(GateX(),5),1) 2-qubit circuit with 2 instructions: ├── SX @ q[1] └── X**5 @ q[1] >>> c.decompose() 2-qubit circuit with 9 instructions: ├── U(0, 0, (-1/2)*pi, 0.0) @ q[1] ├── U((1/2)*pi, 0, pi, 0.0) @ q[1] ├── U(0, 0, (-1/2)*pi, 0.0) @ q[1] ├── U(0, 0, 0, (1/4)*pi) @ q[1] ├── U(pi, 0, pi, 0.0) @ q[1] ├── U(pi, 0, pi, 0.0) @ q[1] ├── U(pi, 0, pi, 0.0) @ q[1] ├── U(pi, 0, pi, 0.0) @ q[1] └── U(pi, 0, pi, 0.0) @ q[1]
- static __new__(cls, operation=None, exponent=None, *args, **kwargs)[source]¶
Create a Power instance, returning canonical subclass if registered.
If a canonical subclass is registered for (type(operation), exponent), an instance of that subclass is returned instead of a plain Power.
- Parameters:
- Returns:
Instance of Power or a registered canonical subclass
- property op¶
- property exponent¶
- 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:
- power(*args)[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.
- 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.
- 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)
- mimiqcircuits.operations.power.canonical_power(inner_gate_type, exponent)[source]¶
Decorator to register a canonical Power subclass.
When Power(inner_gate_type(), exponent) is called, it will return an instance of the decorated subclass instead.
- Parameters:
- Returns:
Decorator that registers the class
Example
>>> from mimiqcircuits import * >>> @canonical_power(GateZ, Fraction(1, 2)) ... class GateS(Power): ... pass >>> isinstance(Power(GateZ(), 0.5), GateS) True