mimiqcircuits.operations.decompositions.control¶
Functions
|
Logical AND of |
|
Undo |
|
C_n(X) with m clean ancillas, m <= n - 2. |
|
C_n(X) with m clean ancillas, m <= n - 1, and a bit to measure into. |
|
Push |
|
Push a multi-controlled |
|
Push an X gate on |
|
Relative-phase Toffoli. |
- control_decompose(circ, operation, controls, target)[source]¶
Push
operationontargetcontrolled bycontrolstocirc.With zero or one control the gate is pushed directly; with more, it is decomposed recursively into singly-controlled gates and multi-controlled X gates, following Barenco et al. (1995).
- Parameters:
circ – The circuit to push to.
operation – A single-qubit gate.
controls – The control qubits.
target – The target qubit.
- Returns:
The circuit
circ.
- cx_decompose(circ, controls, target, ancillas)[source]¶
Push an X gate on
targetcontrolled bycontrolstocirc.Uses the free qubits in
ancillasto decompose the gate into Toffoli gates (Lemmas 7.2 and 7.3 of Barenco et al., 1995). The ancillas are returned to their initial state, whatever it is. Without ancillas it falls back tocontrol_decompose().- Parameters:
circ – The circuit to push to.
controls – The control qubits.
target – The target qubit.
ancillas – Qubits not involved in the gate, usable as workspace.
- Returns:
The circuit
circ.
- control_recursive_decompose(circ, operation, controls, target)[source]¶
Push a multi-controlled
operationtocircby recursion on its square root.Follows Barenco et al. (1995): the gate with
ncontrols is built from singly-controlled square roots ofoperation, multi-controlled X gates, and the same construction withn - 1controls.- Parameters:
circ – The circuit to push to.
operation – A single-qubit gate.
controls – The control qubits, at least two.
target – The target qubit.
- Returns:
The circuit
circ.
- rccx(circ, a, b, t)[source]¶
Relative-phase Toffoli.
A Toffoli up to a diagonal phase on its three qubits, with 4 T gates. It is its own inverse.
- cnx_ladder(circ, controls, target, ancillas)[source]¶
C_n(X) with m clean ancillas, m <= n - 2.
The ladder stores in ancilla i the AND of the first i+1 controls. The remaining controls and the last ancilla control the target, then the ladder is undone. The relative phases of the ladder cancel: they are diagonal, and the middle gate only reads the ladder qubits. With m < n - 2 the middle gate still has 3 or more controls; it borrows the qubits the ladder has already read, which sit idle meanwhile.
- and_compute(circ, a, b, t)[source]¶
Logical AND of
aandbintot, which must be in|0>.The relative-phase Toffoli leaves a phase i on
|111>only, among the states it reaches from t = 0; the S-dagger removes it.
- and_uncompute(circ, a, b, t, bit)[source]¶
Undo
and_compute(circ, a, b, t)by measurement, without T gates.Measured in the X basis,
tgives a random bit; when it is 1 the state has picked up a phase -1 where a and b are both 1, which a CZ conditioned on the bit undoes. The reset returnstto|0>.
- cnx_measured_ladder(circ, controls, target, ancillas, bit)[source]¶
C_n(X) with m clean ancillas, m <= n - 1, and a bit to measure into.
As
cnx_ladder(), but each step is an exact AND, undone by measurement.