guppyalgos.primitives.subroutines.parity¶
Quantum parity implementations.
Functions
|
XOR input parity into a target using measurement-assisted computation. |
|
Return the total qubit count required by LAQCC parity. |
|
XOR the parity of the input register into a target qubit. |
- guppyalgos.primitives.subroutines.parity.parity_laqcc(q_target, qs_inputs)¶
XOR input parity into a target using measurement-assisted computation.
This operation implements
|x_0, ..., x_n-1>|t> -> |x_0, ..., x_n-1>|t XOR x_0 XOR ... XOR x_n-1>using a sequence of controlled operations and with ancilla qubits.This is a constant-depth implementation of the parity circuit, For fewer than four inputs, uses
parity_sequential(). Otherwise, the operation uses two ancilla registers of sizen_qs_qubits - 3and measurement feed-forward. The input qubits are unchanged in both cases.- Parameters:
q_target – Qubit into which the input parity is XORed.
qs_inputs – Input register. Its length determines the circuit and ancilla sizes at compile time.
Examples
Applied to inputs
|1, 0, 1, 1>and target|0>, this operation leaves the inputs unchanged and changes the target to|1>.
- guppyalgos.primitives.subroutines.parity.parity_laqcc_total_qubits(n_input_qubits)¶
Return the total qubit count required by LAQCC parity.
The count includes
n_input_qubitsinput qubits, one target qubit, and two ancilla registers of sizen_input_qubits - 3when there are at least four inputs. The sequential fallback uses no ancilla qubits.
- guppyalgos.primitives.subroutines.parity.parity_sequential(q_target, qs_inputs)¶
XOR the parity of the input register into a target qubit.
This operation implements
|x_0, ..., x_n-1>|t> -> |x_0, ..., x_n-1>|t XOR x_0 XOR ... XOR x_n-1>using a sequence of controlled operations and no ancilla qubits.- Parameters:
q_target – Qubit into which the input parity is XORed.
qs_inputs – Input register. Its length determines the circuit size at compile time.
Examples
For inputs
|1, 0, 1, 1>and target|0>, the target becomes|1>because0 XOR 1 XOR 0 XOR 1 XOR 1 = 1. The four input qubits are unchanged.