qpe_toolbox.estimation.hadamard_test¶
Functions¶
|
Construct the quantum circuit implementing the Hadamard test. |
|
Run the Hadamard test circuit and estimate the expectation value \(Z(\beta)\). |
Module Contents¶
- qpe_toolbox.estimation.hadamard_test.build_hadamard_test_circuit(init_mps, unitary, phase_gate_angle, *, cutoff=1e-10, max_bond=None)[source]¶
Construct the quantum circuit implementing the Hadamard test.
The circuit prepares an ancilla qubit, applies a phase rotation and a controlled unitary \(U\), and measures the ancilla in the X basis. It is the single-phase-qubit Quantum Phase Estimation circuit, built with
qpe_circuit. The phase rotation is applied before the controlled unitary; both commute, so the output is identical to the textbook ordering where the rotation comes after.This circuit can be used to estimate the real or imaginary part of \(\bra{\psi} U \ket{\psi}\) by choosing appropriate values of
phase_gate_angle.- Parameters:
init_mps (MatrixProductState) – Initial state \(\ket{\psi}\) of the data register. A single ancilla qubit is prepended, giving a CircuitMPS.
unitary (Gate or iterable of Gate) – The unitary \(U\), acting on data-register-local qubit indices
[0, n_data)without controls (same convention as inqpe_circuit). Either a single gate (e.g. an exact \(U\)) or its gate decomposition as an iterable of gates (e.g. a Trotterized \(U\)). An iterable may be a one-shot generator, consumed exactly once.phase_gate_angle (float) – Phase angle \(\beta\) applied to the ancilla qubit. Typical values: -
0for estimating the real part --π/2for estimating the imaginary partcutoff (float, default
1e-10) – Singular-value truncation threshold of the underlying CircuitMPS.max_bond (int or None, default
None) – Maximum bond dimension of the underlying CircuitMPS. IfNone, no explicit limit is imposed.
- Returns:
circ – Circuit implementing the Hadamard test.
- Return type:
- qpe_toolbox.estimation.hadamard_test.run_hadamard_test(init_mps, unitary, phase_gate_angle, n_shots, *, cutoff=1e-10, max_bond=None, rng=None)[source]¶
Run the Hadamard test circuit and estimate the expectation value \(Z(\beta)\).
The returned value is
\[Z(\beta) = P(0) - P(1) = \mathrm{Re} \left[e^{i\beta} \bra{\psi} U \ket{\psi} \right]\]where \(P(0)\) and \(P(1)\) are the normalized probabilities of measuring the ancilla qubit in states \(\ket{0}\) and \(\ket{1}\).
- Parameters:
init_mps (MatrixProductState) – Initial state \(\ket{\psi}\) of the data register.
unitary (Gate or iterable of Gate) – The unitary \(U\) used in the Hadamard test, either a single gate (e.g. an exact \(U\)) or its gate decomposition as an iterable of gates (e.g. a Trotterized \(U\)). See
build_hadamard_test_circuitfor the convention. A one-shot generator is consumed by this call; build a fresh one per call.phase_gate_angle (float) – Phase angle \(\beta\) applied to the ancilla qubit.
n_shots (int or qpe_toolbox.EXACT) – Number of measurement shots. If
EXACT, probabilities are computed exactly, else probabilities are estimated by sampling.cutoff (float, default
1e-10) – Singular-value truncation threshold of the underlying CircuitMPS.max_bond (int or None, default
None) – Maximum bond dimension of the underlying CircuitMPS. IfNone, no explicit limit is imposed.rng (numpy.random.Generator, optional) – Random generator forwarded to the circuit sampler (
circ.sample). Ignored whenn_shotsisEXACT.
- Returns:
Z – Estimated value of \(Z(\beta) = P(0) - P(1)\).
- Return type: