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; qubit n_system is the most significant bit.

  • The eigenstate is prepared by state_prep; if None the system register is left in \(|0\rangle^{\otimes n_{\text{system}}}\).

  • The inverse QFT (no swaps) is applied to the precision register.

  • MEASURE instructions are appended on the precision register so that the resulting integer m decoded as bitstring b_{n-1} ... b_0 satisfies \(\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 Circuit representing one application of the unitary \(U\) on the system register (qubit indices 0 .. n_system - 1). The number of qubits in this fragment sets n_system.

  • state_prep (Circuit | None) – Optional Circuit that prepares the eigenstate on the system register. Must reference the same system qubits as unitary_circuit. If None, 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. When None (the default) the controlled \(U\) is repeated power times — correct but potentially slow for large n_precision.

  • measure (bool) – If True (default), append MEASURE instructions on the precision register at the end. Set False if you want to chain QPE into a larger circuit before measuring.

Returns:

Fresh Circuit with n_system + n_precision qubits.

Raises:

ValueErrorn_precision < 1 or unitary_circuit is empty.

Return type:

Circuit

uniqc.algorithms.core.circuits.qpe.qpe_example()[source]

Return a small QPE demo: estimate the T-gate phase (1/8) with 4 precision bits.

Return type:

Circuit