Skip to content
Construct PsiQDK Algorithms

quantum_phase_estimation_utils

quantum_phase_estimation_utils

calculate_holevo_variance

calculate_holevo_variance(phases, probabilities)

Calculate the Holevo variance given a set of phases and their associated probabilities.

Parameters:

Name Type Description Default
phases List[float]

List of phases obtained from QPE, each between [0, \(2\pi\)].

required
probabilities List[float]

List of probabilities associated with each phase.

required
Note

The phases from running QPE calculation are in the range [0, 1] and should be multiplied by \(2\pi\) to be scaled to [0, \(2\pi\)] before being passed to this function.

clopper_pearson_lower

clopper_pearson_lower(num_successes, num_trials, fail_prob)

Evaulates the estimated lower bound to the Binomial confidence interval, via a Clopper-Pearson test.

Parameters:

Name Type Description Default
num_successes int

The number of successful trials.

required
num_trials int

The total number of trials.

required
fail_prob float

The tolerable probability of failure (i.e. that the true value lies outside the confidence interval).

required

Returns:

Type Description
float

The Clopper-Pearson lower bound to the confidence interval.

clopper_pearson_max_error

clopper_pearson_max_error(num_successes, num_trials, fail_prob)

Calculates the maximum error using Clopper-Pearson.

Returns the value furthest from the point estimate that still lies within the Clopper-Pearson confidence interval.

Parameters:

Name Type Description Default
num_successes int

The number of successful trials.

required
num_trials int

The total number of trials.

required
fail_prob float

The tolerable probability of failure (i.e. that the true value lies outside the confidence interval).

required

Returns:

Type Description
float

The value furthest from the point estimate that still lies in the confidence inteval.

clopper_pearson_upper

clopper_pearson_upper(num_successes, num_trials, fail_prob)

Evaluates the estimated upper bound to the Binomial confidence interval, via a Clopper-Pearson test.

Parameters:

Name Type Description Default
num_successes int

The number of successful trials.

required
num_trials int

The total number of trials.

required
fail_prob float

The tolerable probability of failure (i.e. that the true value lies outside the confidence interval).

required

Returns:

Type Description
float

The Clopper-Pearson upper bound to the confidence interval.

energy_to_phase_qubitization

energy_to_phase_qubitization(energy, norm)

Convert an eigenvalue to a phase.

Parameters:

Name Type Description Default
energy float

Energy eigenvalue of Hamiltonian.

required
norm float

Norm of Hamiltonian.

required

Returns:

Type Description
float

Exact phase corresponding to the energy eigenvalue

get_most_probable_phase

get_most_probable_phase(phase_qubits)

Get the most probable phase from a qubit register typically output after running phase estimation.

Note

This function is only designed for a qubit register of type QUFixed.

Parameters:

Name Type Description Default
phase_qubits QUFixed

A register of qubits, typically representing phase qubits after phase estimation.

required

Returns:

Type Description
float

The most probable phase to read.

hartree_to_ev

hartree_to_ev(energy)

Converts Hartree to electronVolts.

Parameters:

Name Type Description Default
energy float

The energy in Hartree.

required

Returns:

Type Description
float

The energy in eV.

num_trials_chernoff

num_trials_chernoff(precision, fail_prob)

Calculate the number of trials using the Chernoff bound.

Returns the number of trials needed for an estimate to be returned within a desired precision with a given fail probability, from the vanilla Chernoff bound.

Note
  • Deprecated in favour of the Clopper-Pearson tests, below.

optimal_holevo_variance

optimal_holevo_variance(n_precision_qubits)

Calculate the optimal Holevo variance for a given number of bits of precision m as per Eq. 10 in "Optimum phase estimation with two control qubits" (arXiv:2303.12503 ⧉).

Parameters:

Name Type Description Default
n_precision_qubits int

Number of bits of precision.

required

peek_ipea_phase

peek_ipea_phase(qc, ancilla, phase_sign_fixed=False)

Extracts the exact phase given to an eigenstate.

Parameters:

Name Type Description Default
qc QPU

The QPU instance.

required
ancilla Qubits

The output ancilla for IPEA.

required
phase_sign_fixed bool

Whether the sign of the kicked-back phase is known in advance, or whether it needs to be determined. The former is useful for qubitization, and the latter for Trotterization.

False

Returns:

Type Description
phase (float

The exact phase given to an eigenstate.

phase_from_cs

phase_from_cs(sine, cosine)

Calculates a phase from the sine and cosine.

Extracts an estimate of the phase, \(\phi\), given an estimate of \(\cos(2 \pi \phi)\) and \(\sin(2 \pi \phi)\).

Parameters:

Name Type Description Default
sine float

An estimate of \(\sin(2 \pi \phi)\).

required
cosine float

An estimate of \(\cos(2 \pi \phi)\).

required

Returns:

Type Description
float

An estimate of the phase, \(\phi\).

Note

The output phase is in \([0,1]\) (not \([0, 2\pi]\), or \([-\pi, \pi]\)).

phase_to_energy_qubitization

phase_to_energy_qubitization(phase, norm)

Convert a phase to an eigenvalue.

Parameters:

Name Type Description Default
phase float

Phase found using IPEA.

required
norm float

Norm of Hamiltonian.

required

Returns:

Type Description
float

Energy eigenvalue of Hamiltonian.

phase_to_energy_time_evolution

phase_to_energy_time_evolution(output, bits_precision, offset=0, rescaling_factor=1)

Converts a measured phase to an eigenenergy, when estimating the phase of \(\exp(iHt)\).

Parameters:

Name Type Description Default
output int

The bits of output from phase estimation.

required
bits_precision int

The number of bits of precision.

required
offset float

A constant factor to add to the eigenenergy (for example, if the Hamiltonian had an identity term that has been skimmed off).

0
rescaling_factor float

A factor to account for rescaling of the Hamiltonian before simulation.

1

Returns:

Type Description
float

The estimated eigenphase.