mimiqcircuits.operations.inverse

Inverse operation.

Functions

canonical_inverse(inner_gate_type)

Decorator to register a canonical Inverse subclass.

register_inverse_alias(exponent, gate_type, name)

Register an alias for an inverse gate definition

register_inverse_decomposition(gate_type)

Decorator to register a decomposition function for a gate type

Classes

Inverse([operation])

Inverse of the wrapped quantum operation.

class mimiqcircuits.operations.inverse.Inverse(operation=None, *args, **kwargs)[source]

Bases: Gate

Inverse of the wrapped quantum operation.

The inversion is not performed right away, but only when the circuit is cached or executed.

When a canonical subclass is registered (e.g., GateSDG for Inverse(GateS())), constructing Inverse with matching arguments will return an instance of that subclass. This enables isinstance() checks to work correctly:

Warning

Users should not use Inverse directly but rather the inverse method, which performs all the necessary simplifications (e.g., op.inverse().inverse() == op)

Examples

>>> from mimiqcircuits import *
>>> isinstance(Inverse(GateS()), GateSDG)
True
>>> Inverse(GateP(1)).matrix()
[1.0, 0]
[0, 0.54030230586814 - 0.841470984807897*I]

>>> c = Circuit()
>>> c.push(Inverse(GateP(1)), 1)
2-qubit circuit with 1 instruction:
└── P(1)† @ q[1]
static __new__(cls, operation=None, *args, **kwargs)[source]

Create an Inverse instance, returning canonical subclass if registered.

If a canonical subclass is registered for type(operation), an instance of that subclass is returned instead of a plain Inverse.

Parameters:
  • operation – Gate operation or gate class to invert

  • *args – Arguments to pass to operation constructor if a class is provided

  • **kwargs – Keyword arguments to pass to operation constructor

Returns:

Instance of Inverse or a registered canonical subclass

__init__(operation, *args, **kwargs)[source]
isopalias()[source]
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:

bool

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.

getparams()[source]
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.

control(*args)[source]
parallel(*args)[source]
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)
gettypekey()[source]
mimiqcircuits.operations.inverse.canonical_inverse(inner_gate_type)[source]

Decorator to register a canonical Inverse subclass.

When Inverse(inner_gate_type()) is called, it will return an instance of the decorated subclass instead.

Parameters:

inner_gate_type (Type) – Type of the inner gate

Returns:

Decorator that registers the class

Example

>>> from mimiqcircuits import *
>>> @canonical_inverse(GateS)
... class GateSDG(Inverse):
...     pass
>>> isinstance(Inverse(GateS()), GateSDG)
True