qpe_toolbox.estimation.hadamard_test

Functions

build_hadamard_test_circuit(init_mps, U_gate, ...)

Construct the quantum circuit implementing the Hadamard test.

run_hadamard_test(init_mps, U_gate, phase_gate_angle, ...)

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, U_gate, phase_gate_angle)[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 phase_gate_angle.

Parameters:
  • init_mps (MatrixProductState) – Initial state \(\ket{\psi}\) of the data register.

  • U_gate (Gate or list) – Unitary operator to be tested. If a Gate instance 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.

  • phase_gate_angle (float) – Phase angle \(\beta\) applied to the ancilla qubit. Typical values: - 0 for estimating the real part - -π/2 for estimating the imaginary part

Returns:

circ – Circuit implementing the Hadamard test.

Return type:

CircuitMPS

qpe_toolbox.estimation.hadamard_test.run_hadamard_test(init_mps, U_gate, phase_gate_angle, n_shots, *, 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 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_circuit method for accepted formats.

  • 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.

  • rng (numpy.random.Generator, optional) – Random generator forwarded to the circuit sampler (circ.sample). Ignored when n_shots is EXACT.

Returns:

Z – Estimated value of \(Z(\beta) = P(0) - P(1)\).

Return type:

float