Skip to content

Reference: Conditionally Clean Arithmetic Qubricks

Contents


CondCleanSelect Class

psiqworkbench.qubricks.qbk_conditionally_clean_arithmetic.CondCleanSelect

CondCleanSelect(**kwargs)

Bases: Qubrick

This is a way to perform tree transversal within the conditionally clean structre presented in "Rise of conditionally clean ancillae for efficient quantum circuit constructions" (arxiv:2407.17966 ⧉). The idea of utilising this for multiplexing is presented in Figure 9.

This Qubrick works by first constructing the all zero condition and applies the first index of the data. Then it sequentially moves through the indices by finding the MSB difference, undoing the structure to this point, and then redoing with the new condition utiliing the partial_compute() function.

Notes

This should be called with the filter >>toffoli-window-filter>> to take advantage of the cancellations that occur when you replace one condition with the next. This does the minimal work before calling the filter without hardcoding the cancellations. Hardcoding requires a bit more care, as gates that begin each layer in the conditionally clean structure include adjacent bits such that the gate that switches branch for bit i will need to be aware of the higher bit (i-1) to apply the correct cancellation.

compute

compute(index_reg: QUInt, target_reg: Qubits, data: list, avail_anc: Qubits = None, grey: bool = True, skip_zeros: bool = True)

Looks through indices, updating the gate conditions and applying the data item.

Parameters:

Name Type Description Default
index_reg QUInt

Qubit register acting as indicies.

required
target_reg Qubits

Register to load data items to.

required
data list

List of data values to load based on index.

required
avail_anc Qubits

Option to provide log*(n) clean auxiliary qubits.

None
grey bool

Option to use grey counting.

True
skip_zeros bool

Option to not write any data element equal to 0.

True

CondCleanIncrementer Class

psiqworkbench.qubricks.qbk_conditionally_clean_arithmetic.CondCleanIncrementer

CondCleanIncrementer(**kwargs)

Bases: Qubrick

This is a way to increment the value stored in a register within the conditionally clean structre presented in "Rise of conditionally clean ancillae for efficient quantum circuit constructions" (arxiv:2407.17966 ⧉).

This Qubrick works by first constructing the all ON condition on the register, except for the final qubit (most significant bit). It then applies an X gate to the MSB conditioned on this state. It then sequentially removes this bit as a condition from the structure and applies an X gate to the qubit storing the next highest bit conditioned on all but that bit being in the ON state.

compute

compute(val_reg: Qubits, avail_anc: Qubits | None = None, ctrl: Qubits | int | None = None)

Steps backwards through the registers (from most to least significant bit), applying X gates to the qubit registers to implement an increment.

Parameters:

Name Type Description Default
val_reg Qubits

Qubit register acting as indices.

required
avail_anc Qubits | None

Option to provide log*(n) clean auxiliary qubits.

None
ctrl Qubits | int | None

Control register to apply payload gates.

None

CondCleanLessThanConst Class

psiqworkbench.qubricks.qbk_conditionally_clean_arithmetic.CondCleanLessThanConst

CondCleanLessThanConst(**kwargs)

Bases: Qubrick

Quantum-classical comparator using conditionally clean construction. Taken from "Rise of conditionally clean ancillae for efficient quantum circuit constructions" (arxiv:2407.17966 ⧉) (Fig.8) with the following optimisations:

- Gate savings during equality testing layer: only do an X gate if classical bit is zero for idx > 0.
- If after some idx all bits of constant are zero, we can exit early, as the flag qubit already stores answer.

compute

compute(val_reg: QUInt | QUFixed, const: int, avail_anc: Qubits | None = None, flag_qubit: Qubits | None = None)

Perform comparison.

Parameters:

Name Type Description Default
val_reg QUInt | QUFixed

Register storing value to compare with classical constant.

required
const int

Constant integer to compare to.

required
avail_anc Qubits | None

Provide clean ancilla to utilize (requires log*(n)).

None