qrunch.quantum.algorithms.pauli.quantum_phase_estimation.hadamard_test

Hadamard test algorithm for estimating expectation values of a time-evolution unitary.

Classes

HadamardTest

Hadamard test for estimating \(\langle \psi | U | \psi \rangle\).

HadamardTestOptions

Options for HadamardTest.

HadamardTestPart

Which part of \(\langle \psi | U | \psi \rangle\) the Hadamard test estimates.

class HadamardTest

Bases: object

Hadamard test for estimating \(\langle \psi | U | \psi \rangle\).

Estimates the real or imaginary part of the expectation value of the time-evolution unitary \(U = e^{-iHt}\) with respect to a reference state \(|\psi\rangle\).

The circuit places one ancilla qubit at index 0 and the state register at qubits \(1 \ldots m\), where \(m\) is the number of qubits in state_preparation_circuit. Measuring the ancilla gives:

\[P(0) - P(1) = \mathrm{Re}\!\left(e^{i\phi} \langle \psi | U | \psi \rangle\right)\]

where \(\phi\) is the total phase offset: \(0\) for the real part, \(-\tfrac{\pi}{2}\) for the imaginary part, plus any additional offset supplied to run().

__init__(hamiltonian_encoder: TrotterizationHamiltonianEncoder, sampler: Sampler, shots: int | None = None, options: HadamardTestOptions | None = None) None

Initialise the Hadamard test.

Parameters:
  • hamiltonian_encoder (TrotterizationHamiltonianEncoder) – Trotterization encoder that constructs \(U = e^{-iHt}\). Encapsulates both the Trotterization strategy and the number of Trotter steps.

  • sampler (Sampler) – Sampler used to measure the final circuit.

  • shots (int | None) – Number of measurement shots to use.

  • options (HadamardTestOptions | None) – Algorithm options, including which part to estimate.

Return type:

None

run(state_preparation_circuit: Circuit, hamiltonian: HermitianPauliSum, time: float, offset: float = 0.0) ExpectationValue

Build and execute the Hadamard test circuit.

Returns \(\mathrm{Re}(e^{i\phi}\langle \psi | e^{-iHt} | \psi \rangle)\) where the total phase offset \(\phi\) is:

\[\begin{split}\phi = \begin{cases} 0 & \text{(REAL)} \\ -\tfrac{\pi}{2} & \text{(IMAGINARY)} \end{cases} + \text{offset}\end{split}\]
Parameters:
  • state_preparation_circuit (Circuit) – Circuit that prepares \(|\psi\rangle\) on the state register.

  • hamiltonian (HermitianPauliSum) – The Hermitian Pauli Hamiltonian \(H\) in \(U = e^{-iHt}\).

  • time (float) – Evolution time \(t\) passed to the Hamiltonian encoder.

  • offset (float) – Additional phase \(\phi_{\mathrm{extra}}\) applied to the ancilla after the controlled-\(U\). Shifts the measured quantity by \(\mathrm{Re}(e^{i \cdot \mathrm{offset}} \cdot \ldots)\).

Return type:

ExpectationValue

class HadamardTestOptions

Bases: object

Options for HadamardTest.

Parameters:

part – Which part of \(\langle \psi | U | \psi \rangle\) to estimate. HadamardTestPart.REAL measures the real part; HadamardTestPart.IMAGINARY measures the imaginary part.

__init__(*, part: HadamardTestPart = HadamardTestPart.REAL) None
Parameters:

part (HadamardTestPart)

Return type:

None

part: HadamardTestPart = 'real'
class HadamardTestPart

Bases: Enum

Which part of \(\langle \psi | U | \psi \rangle\) the Hadamard test estimates.

IMAGINARY = 'imaginary'
REAL = 'real'