mimiqcircuits.operations.inverse¶
Inverse operation.
Functions
|
Decorator that registers a named subclass of |
|
Register a display name for the inverse of a gate. |
|
Decorator that registers a custom decomposition for the inverse of a gate. |
Classes
|
Inverse of a gate. |
- class Inverse(operation=None, *args, **kwargs)[source]¶
Bases:
GateInverse of a gate.
Inverse(gate)is the unitary \(U^\dagger\), where \(U\) is the matrix ofgate. The inverse is kept as a wrapper: it is not rewritten into another gate when built.The constructor takes the gate, or a gate class followed by its constructor arguments.
When a named subclass is registered for the gate type (see
canonical_inverse()), the constructor returns an instance of that subclass:Inverse(GateS())is aGateSDG.- Parameters:
operation – The gate to invert, or a gate class.
*args – Constructor arguments when
operationis a class.**kwargs – Constructor keyword arguments when
operationis a class.
- Raises:
ValueError – If
operationis not a gate or gate class.
Warning
Prefer the
inversemethod of a gate to buildingInversedirectly. The method simplifies where it can, for exampleGateH().inverse()isGateH()andop.inverse().inverse()isop.Examples
>>> from mimiqcircuits import * >>> # the generic form returns the named gate when one exists >>> isinstance(Inverse(GateS()), GateSDG) True >>> # the matrix is the conjugate transpose of the gate's matrix >>> 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
- isopalias()[source]¶
Whether the operation is a named alias of a wrapper.
Some named gates are defined as a wrapper around another operation, for example
GateSasGateZto the power 1/2. Such gates returnTrue. Not every such gate reports it:GateSDGandGateCXreturnFalse.- Returns:
Truefor a named alias of a wrapper that reports it,Falseotherwise.- Return type:
- get_operation()[source]¶
Return the operation that this one wraps, or the operation itself.
Wrappers such as
ControlorPowerreturn the operation they wrap; other operations return themselves.- Returns:
Operation
- getparams()[source]¶
Return the values of the operation’s parameters.
- Returns:
One value per name in
parnames, in the same order. Values may be numbers or symbolic expressions.- Return type:
Examples
>>> from mimiqcircuits import * >>> # GateU has a fourth parameter, the global phase, defaulting to 0 >>> g = GateU(0.1, 0.2, 0.3) >>> g.parnames ('theta', 'phi', 'lmbda', 'gamma') >>> g.getparams() [0.1, 0.2, 0.3, 0.0]
- power(*args)[source]¶
Return the gate raised to a power.
Gates with a known power return it directly (for example
GateZ().power(0.5)isGateS(), andGateRX(a).power(p)isGateRX(p * a)); otherwise the gate is wrapped inPower.- Parameters:
*args – The exponent. Without it, return a
LazyExprthat takes the exponent later.- Raises:
ValueError – If more than one argument is given.
TypeError – If the exponent is not a real number.
- control(*args)[source]¶
Return the gate controlled by
num_controlsqubits.Gates with a named controlled form return it directly (for example
GateX().control(1)isGateCX()); otherwise the gate is wrapped inControl. The controls are the first qubits.- Parameters:
*args – The number of controls. Without it, return a
LazyExprthat takes the number later.- Raises:
ValueError – If more than one argument is given.
- parallel(*args)[source]¶
Return a
Parallelapplying the gate to separate qubit groups.- Parameters:
*args – The number of repetitions. Without it, return a
LazyExprthat takes the number later.- Raises:
ValueError – If more than one argument is given.
- canonical_inverse(inner_gate_type)[source]¶
Decorator that registers a named subclass of
Inverse.After registration,
Inverse(g)withgan instance ofinner_gate_typebuilds an instance of the decorated class instead of a plainInverse. This is how named gates such asGateSDG(Inverse(GateS())) are defined.Registering a class for a type that already has one replaces it for the rest of the session.
- Parameters:
inner_gate_type (Type) – Class of the wrapped gate.
- Returns:
The decorator. It registers the class and returns it unchanged.
Examples
>>> from mimiqcircuits import * >>> # GateSDG is registered as the inverse of GateS >>> isinstance(Inverse(GateS()), GateSDG) True