Phase, amplitude, and overlap estimation

oracq.algorithms.common.estimation

Phase estimation, amplitude estimation and overlap measurement circuits; readout and statistics are done on the host side.

oracq.algorithms.common.estimation.phase_estimation(operation, *, precision=2)[source]

Standard quantum phase estimation, QPE.

Parameters:
  • operation – A complete Operation supporting controlled invocation. The caller must prepare its input state.

  • precision – Number of phase register bits, in the range 1..63.

Returns:

Keeps the original public registers and appends phase. For an eigenphase φ, the readout approximates 2**precision * φ.

Return type:

Operation

Raises:

ValidationError – The precision is invalid, the input occupies the phase name, or the required controlled invocation is unsupported.

The powers are kept in a Repeat; the generator does not expand the gate sequence per power.

oracq.algorithms.common.estimation.hadamard_test(unitary, preparation=None, *, component='real')[source]

Generate a Hadamard test circuit for a complex expectation value.

Parameters:
  • unitary – A complete unitary operation, or a block encoding with no signal and alpha=1.

  • preparation – Initial state preparation; when omitted the zero state of the target space is used. work must be cleaned.

  • component – real or imag, selecting the real or imaginary part of the expectation value to read out.

Returns:

Registers target, work and probe. The Z expectation of probe is the corresponding complex expectation component.

Return type:

Operation

This operation performs no measurement. Actual use requires sampling probe and computing the probability difference on the classical side.

oracq.algorithms.common.estimation.swap_test(first, second)[source]

Generate an overlap measurement circuit for two pure states.

Parameters:
  • first – Preparation of the first state; requires zero input and a clean workspace.

  • second – Preparation of the second state of the same width; requires zero input and a clean workspace.

Returns:

Keeps left, right, both work registers and probe. The probability that probe is zero equals the squared overlap modulus of the two states plus one, divided by two.

Return type:

Operation

The two preparations are only invoked forward; the conditional swap is generated by the algorithm.

oracq.algorithms.common.estimation.amplitude_estimation(preparation, marked, *, precision=3)[source]

Generate a QPE circuit estimating the good-state probability.

Parameters:
  • preparation – A zero-input state preparation supporting adjoint and controlled invocation.

  • marked – Set of integer indices of the good states in the target space.

  • precision – Number of phase register bits, in the range 1..63.

Returns:

Registers target, work and phase. After reading phase, call amplitude_from_phase to decode.

Return type:

Operation

A finite-precision readout may correspond to several approximate probabilities. Sampling and statistics are the host’s responsibility.

oracq.algorithms.common.estimation.amplitude_from_phase(value, precision)[source]

Convert one phase sample into an estimate of the good-state probability.

Parameters:
  • value – Unsigned integer readout of phase.

  • precision – Bit width of phase.

Returns:

sin(pi*value/2**precision)**2, between zero and one.

Return type:

float