mimiqcircuits.decomposition.basis.rotation_cz

Decomposition bases targeting two rotation axes and GateCZ.

Classes

RXRYCZBasis([borrow, max_ancillas, ...])

Decomposition basis targeting GateRX, GateRY and GateCZ.

RXRZCZBasis([borrow, max_ancillas, ...])

Decomposition basis targeting GateRX, GateRZ and GateCZ.

class RXRZCZBasis(borrow=False, max_ancillas=0, allow_measurement=False)[source]

Bases: _RotationCZBasis

Decomposition basis targeting GateRX, GateRZ and GateCZ.

Rotations keep any angle, including symbolic ones. GateID is kept, so a circuit padded with it keeps its width. Non-gate operations that are terminal in CanonicalBasis (measurements, resets, barriers, noise, annotations, classical operations, …) are terminal here too. An IfStatement is terminal when its body is; otherwise its body is decomposed into this basis and stays conditional.

Every other operation is first rewritten by CanonicalRewrite into GateU and GateCX. Then:

  • GateU(theta, phi, lmbda) becomes RZ(lmbda - pi/2), RX(theta), RZ(phi + pi/2) (circuit order), or a single RZ(phi + lmbda) when theta = 0;

  • GateCX becomes CZ with the target conjugated by RZ(pi/2), RX(pi/2);

  • MeasureReset becomes Measure followed by Reset, which leaves the same state and bit as the canonical measurement and conditional X.

Global phases are dropped. Adjacent rotations are not merged; run merge_rotations() on the result for that.

Parameters:
  • borrow (bool) – Let decompositions borrow qubits of the circuit that the operation does not act on. A borrowed qubit can be in any state; the decomposition leaves it as it found it.

  • max_ancillas (int) – Let decompositions add up to this many clean ancillas, numbered after the qubits of the circuit and marked with AncillaAlloc and AncillaFree. Ancillas freed by one operation are reused by the next.

  • allow_measurement (bool) – With max_ancillas, let decompositions undo steps by measuring an ancilla into one extra bit, numbered after the bits of the circuit. A circuit without bits is refused with a ValueError.

The three ancilla options are off by default, and only change how multi-controlled X gates are decomposed, as in CanonicalBasis. Circuits whose width is unknown, such as a lone operation, get no ancillas.

Examples

>>> from mimiqcircuits import *
>>> c = Circuit().push(GateH(), 0)
>>> decompose(c, RXRZCZBasis())
1-qubit circuit with 3 instructions:
├── RZ((1/2)*pi) @ q[0]
├── RX((1/2)*pi) @ q[0]
└── RZ((1/2)*pi) @ q[0]
>>> # up to 2 clean ancillas, after the qubits of the circuit
>>> c = Circuit().push(Control(4, GateX()), 0, 1, 2, 3, 4)
>>> d = decompose(c, RXRZCZBasis(max_ancillas=2))
>>> ancillas(d)
[5, 6]
class RXRYCZBasis(borrow=False, max_ancillas=0, allow_measurement=False)[source]

Bases: _RotationCZBasis

Decomposition basis targeting GateRX, GateRY and GateCZ.

Rotations keep any angle, including symbolic ones. GateID is kept, so a circuit padded with it keeps its width. Non-gate operations that are terminal in CanonicalBasis (measurements, resets, barriers, noise, annotations, classical operations, …) are terminal here too. An IfStatement is terminal when its body is; otherwise its body is decomposed into this basis and stays conditional.

Every other operation is first rewritten by CanonicalRewrite into GateU and GateCX. Then:

  • GateU(theta, phi, lmbda) becomes RY(pi/2), RX(lmbda), RY(theta), RX(phi), RY(-pi/2) (circuit order), omitting rotations by zero;

  • GateCX becomes CZ with the target conjugated by RY(-pi/2);

  • MeasureReset becomes Measure followed by Reset, which leaves the same state and bit as the canonical measurement and conditional X.

Global phases are dropped. Adjacent rotations are not merged; run merge_rotations() on the result for that.

Parameters:
  • borrow (bool) – Let decompositions borrow qubits of the circuit that the operation does not act on. A borrowed qubit can be in any state; the decomposition leaves it as it found it.

  • max_ancillas (int) – Let decompositions add up to this many clean ancillas, numbered after the qubits of the circuit and marked with AncillaAlloc and AncillaFree. Ancillas freed by one operation are reused by the next.

  • allow_measurement (bool) – With max_ancillas, let decompositions undo steps by measuring an ancilla into one extra bit, numbered after the bits of the circuit. A circuit without bits is refused with a ValueError.

The three ancilla options are off by default, and only change how multi-controlled X gates are decomposed, as in CanonicalBasis. Circuits whose width is unknown, such as a lone operation, get no ancillas.

Examples

>>> from mimiqcircuits import *
>>> c = Circuit().push(GateCX(), 0, 1)
>>> decompose(c, RXRYCZBasis())
2-qubit circuit with 3 instructions:
├── RY((-1/2)*pi) @ q[1]
├── CZ @ q[0], q[1]
└── RY((1/2)*pi) @ q[1]
>>> # up to 2 clean ancillas, after the qubits of the circuit
>>> c = Circuit().push(Control(4, GateX()), 0, 1, 2, 3, 4)
>>> d = decompose(c, RXRYCZBasis(max_ancillas=2))
>>> ancillas(d)
[5, 6]