mimiqcircuits.operations.gates.gate

Abstract Gate base class.

Classes

Gate()

Base class for unitary gates.

class Gate[source]

Bases: AbstractOperator

Base class for unitary gates.

A gate acts on qubits only, has a unitary matrix, and can be inverted, raised to a power, controlled, repeated and run in parallel. Subclasses provide the matrix and the number of qubits.

power(), control(), parallel() and repeat() called without their count return a LazyExpr that takes it later.

Examples

>>> from mimiqcircuits import *
>>> GateX().control(2)
C₂X
>>> GateX().power(0.5)
SX
>>> GateH().parallel(3)
⨷ ³ H
>>> # without the count, a lazy expression is returned
>>> GateX().control()
lazy control(?, X)
iswrapper()[source]

Return False: a plain gate does not wrap another operation.

rescale(scale)[source]

Return a RescaledGate wrapping this gate with factor scale.

rescale_inplace(scale)[source]

Raise, as a gate cannot be rescaled in place. Use rescale().

inverse()[source]

Return the inverse of the gate.

Gates with a known inverse return it directly (for example GateS().inverse() is GateSDG()); otherwise the gate is wrapped in Inverse.

power(*args)[source]

Return the gate raised to a power.

Gates with a known power return it directly (for example GateZ().power(0.5) is GateS(), and GateRX(a).power(p) is GateRX(p * a)); otherwise the gate is wrapped in Power.

Parameters:

*args – The exponent. Without it, return a LazyExpr that 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_controls qubits.

Gates with a named controlled form return it directly (for example GateX().control(1) is GateCX()); otherwise the gate is wrapped in Control. The controls are the first qubits.

Parameters:

*args – The number of controls. Without it, return a LazyExpr that takes the number later.

Raises:

ValueError – If more than one argument is given.

parallel(*args)[source]

Return a Parallel applying the gate to separate qubit groups.

Parameters:

*args – The number of repetitions. Without it, return a LazyExpr that takes the number later.

Raises:

ValueError – If more than one argument is given.

repeat(*args)[source]

Return a Repeat applying the gate several times in sequence on the same qubits.

Parameters:

*args – The number of repetitions. Without it, return a LazyExpr that takes the number later.

Raises:

ValueError – If more than one argument is given.

evaluate(d)[source]

Substitute symbols in the gate parameters and return the result.

Parameters:

d (dict) – Map from symbols to the values to substitute.

Returns:

self if nothing changed, otherwise a new gate of the same type with the substituted parameters.

Return type:

Gate

gettypekey()[source]

Return the key used to look up registered decompositions: the gate class.

static isunitary()[source]

Return True: gates are unitary.