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(\theta)\). |
Module Contents¶
- qpe_toolbox.estimation.hadamard_test.build_hadamard_test_circuit(init_mps, U_gate, theta)[source]¶
Construct the quantum circuit implementing the Hadamard test.
The circuit prepares an ancilla qubit, applies a controlled unitary \(U\), applies a phase rotation on the ancilla, and measures the ancilla in the X basis.
This circuit can be used to estimate the real or imaginary part of \(\bra{\psi} U \ket{\psi}\) by choosing appropriate values of
theta.- Parameters:
init_mps (MatrixProductState) – Initial state \(\ket{\psi}\) of the data register.
U_gate (Gate or list) – Unitary operator to be tested. If a
Gateinstance is provided, it must act on all data qubits and be controlled by the ancilla qubit. If a list is provided, it is interpreted as a sequence of Trotter slices, each slice being a list of gate specifications.theta (float) – Phase angle applied to the ancilla qubit. Typical values: -
0for estimating the real part --π/2for estimating the imaginary part
- Returns:
circ – Circuit implementing the Hadamard test.
- Return type:
- qpe_toolbox.estimation.hadamard_test.run_hadamard_test(init_mps, U_gate, theta, n_shots, *, seed=None)[source]¶
Run the Hadamard test circuit and estimate the expectation value \(Z(\theta)\).
The returned value is
\[Z(\theta) = P(0) - P(1) = \mathrm{Re} \left[e^{i\theta} \bra{\psi} U \ket{\psi} \right]\]where \(P(0)\) and \(P(1)\) are the 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.
U_gate (Gate or list) – Unitary operator used in the Hadamard test. See
build_circuitmethod for accepted formats.theta (float) – Phase angle 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.seed (None or int, optional) – A random seed, passed to
numpy.random.seedif given.
- Returns:
Z – Estimated value of \(Z(\theta) = P(0) - P(1)\).
- Return type: