guppyalgos.primitives.subroutines.parity

Quantum parity implementations.

Functions

parity_laqcc(q_target, qs_inputs)

XOR input parity into a target using measurement-assisted computation.

parity_laqcc_total_qubits(n_input_qubits)

Return the total qubit count required by LAQCC parity.

parity_sequential(q_target, qs_inputs)

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 size n_qs_qubits - 3 and 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_qubits input qubits, one target qubit, and two ancilla registers of size n_input_qubits - 3 when there are at least four inputs. The sequential fallback uses no ancilla qubits.

Parameters:

n_input_qubits (int) – Number of input qubits whose parity is computed.

Return type:

int

Returns:

Total number of input, target, and 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> because 0 XOR 1 XOR 0 XOR 1 XOR 1 = 1. The four input qubits are unchanged.