uniqc.algorithms.core.circuits.qpe module¶
Quantum Phase Estimation (QPE) circuit fragment.
Estimates the phase \(\varphi \in [0, 1)\) of a unitary’s eigenvalue
\(e^{2\pi i\varphi}\) on a known eigenstate, using n_precision
ancilla qubits encoding the binary fraction of \(\varphi\).
The unitary_circuit is interpreted as a single application of \(U\)
on a system register; QPE applies controlled \(U^{2^k}\) for
k = 0, 1, ..., n_precision - 1. Internally the controlled powers are
implemented by repeating the controlled \(U\) 2^k times — exact but
not necessarily efficient. Callers wanting efficient \(U^{2^k}\) (e.g.
HHL or Shor) should pre-compute and pass a custom callable via
controlled_power.
Layout convention¶
Qubits
[0 .. n_system - 1]hold the system register.Qubits
[n_system .. n_system + n_precision - 1]hold the precision register; qubitn_systemis the most significant bit.The eigenstate is prepared by
state_prep; ifNonethe system register is left in \(|0\rangle^{\otimes n_{\text{system}}}\).The inverse QFT (no swaps) is applied to the precision register.
MEASUREinstructions are appended on the precision register so that the resulting integermdecoded as bitstringb_{n-1} ... b_0satisfies \(\tilde{\varphi} = m / 2^{n_{\text{precision}}}\).
- uniqc.algorithms.core.circuits.qpe.qpe_circuit(n_precision, unitary_circuit, *, state_prep=None, controlled_power=None, measure=True)[source]¶
Build a Quantum Phase Estimation circuit fragment.
- Parameters:
n_precision (int) – Number of precision qubits (output bits of the phase estimate). Must be
>= 1.unitary_circuit (Circuit) – A
Circuitrepresenting one application of the unitary \(U\) on the system register (qubit indices0 .. n_system - 1). The number of qubits in this fragment setsn_system.state_prep (Circuit | None) – Optional
Circuitthat prepares the eigenstate on the system register. Must reference the same system qubits asunitary_circuit. IfNone, the system register starts in \(|0\rangle^{\otimes n_{\text{system}}}\).controlled_power (Callable[[Circuit, Circuit, int, int], None] | None) –
Optional override to supply an efficient implementation of controlled \(U^{2^k}\). Signature:
controlled_power(fragment, unitary, control_qubit, power)
where
power == 2 ** k. WhenNone(the default) the controlled \(U\) is repeatedpowertimes — correct but potentially slow for largen_precision.measure (bool) – If
True(default), appendMEASUREinstructions on the precision register at the end. SetFalseif you want to chain QPE into a larger circuit before measuring.
- Returns:
Fresh
Circuitwithn_system + n_precisionqubits.- Raises:
ValueError –
n_precision < 1orunitary_circuitis empty.- Return type: