mimiqcircuits.operations.decompositions.control

Functions

and_compute(circ, a, b, t)

Logical AND of a and b into t, which must be in |0>.

and_uncompute(circ, a, b, t, bit)

Undo and_compute(circ, a, b, t) by measurement, without T gates.

cnx_ladder(circ, controls, target, ancillas)

C_n(X) with m clean ancillas, m <= n - 2.

cnx_measured_ladder(circ, controls, target, ...)

C_n(X) with m clean ancillas, m <= n - 1, and a bit to measure into.

control_decompose(circ, operation, controls, ...)

Push operation on target controlled by controls to circ.

control_recursive_decompose(circ, operation, ...)

Push a multi-controlled operation to circ by recursion on its square root.

cx_decompose(circ, controls, target, ancillas)

Push an X gate on target controlled by controls to circ.

rccx(circ, a, b, t)

Relative-phase Toffoli.

control_decompose(circ, operation, controls, target)[source]

Push operation on target controlled by controls to circ.

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 target controlled by controls to circ.

Uses the free qubits in ancillas to 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 to control_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 operation to circ by recursion on its square root.

Follows Barenco et al. (1995): the gate with n controls is built from singly-controlled square roots of operation, multi-controlled X gates, and the same construction with n - 1 controls.

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 a and b into t, 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, t gives 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 returns t to |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.