mimiqcircuits.decomposition.basis.rotation_cz¶
Decomposition bases targeting two rotation axes and GateCZ.
Classes
|
Decomposition basis targeting |
|
Decomposition basis targeting |
- class RXRZCZBasis(borrow=False, max_ancillas=0, allow_measurement=False)[source]¶
Bases:
_RotationCZBasisDecomposition basis targeting
GateRX,GateRZandGateCZ.Rotations keep any angle, including symbolic ones.
GateIDis kept, so a circuit padded with it keeps its width. Non-gate operations that are terminal inCanonicalBasis(measurements, resets, barriers, noise, annotations, classical operations, …) are terminal here too. AnIfStatementis terminal when its body is; otherwise its body is decomposed into this basis and stays conditional.Every other operation is first rewritten by
CanonicalRewriteintoGateUandGateCX. Then:GateU(theta, phi, lmbda)becomesRZ(lmbda - pi/2),RX(theta),RZ(phi + pi/2)(circuit order), or a singleRZ(phi + lmbda)whentheta = 0;GateCXbecomesCZwith the target conjugated byRZ(pi/2),RX(pi/2);MeasureResetbecomesMeasurefollowed byReset, which leaves the same state and bit as the canonical measurement and conditionalX.
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
AncillaAllocandAncillaFree. 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 aValueError.
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:
_RotationCZBasisDecomposition basis targeting
GateRX,GateRYandGateCZ.Rotations keep any angle, including symbolic ones.
GateIDis kept, so a circuit padded with it keeps its width. Non-gate operations that are terminal inCanonicalBasis(measurements, resets, barriers, noise, annotations, classical operations, …) are terminal here too. AnIfStatementis terminal when its body is; otherwise its body is decomposed into this basis and stays conditional.Every other operation is first rewritten by
CanonicalRewriteintoGateUandGateCX. Then:GateU(theta, phi, lmbda)becomesRY(pi/2),RX(lmbda),RY(theta),RX(phi),RY(-pi/2)(circuit order), omitting rotations by zero;GateCXbecomesCZwith the target conjugated byRY(-pi/2);MeasureResetbecomesMeasurefollowed byReset, which leaves the same state and bit as the canonical measurement and conditionalX.
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
AncillaAllocandAncillaFree. 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 aValueError.
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]