workbench_algorithms.utils.quantum_phase_estimation_utils
Utility functions for quantum phase estimation.
phase_to_energy_time_evolution
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. |
phase_to_energy_qubitization
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. |
energy_to_phase_qubitization
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 |
hartree_to_ev
Converts Hartree to electronVolts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
energy
|
float
|
The energy in Hartree. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The energy in eV. |
peek_ipea_phase
Extracts the exact phase given to an eigenstate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qc
|
QPU
|
The Workbench 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. |
num_trials_chernoff
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.
clopper_pearson_lower
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_upper
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. |
clopper_pearson_max_error
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. |
phase_from_cs
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]\)).
get_most_probable_phase
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
|
representing the most probable phase to read |
calculate_holevo_variance
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.
optimal_holevo_variance
Calculate the optimal Holevo variance for a given number of bits of precision m as per Eq. 10 in https://arxiv.org/pdf/2303.12503 .
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_precision_qubits
|
int
|
Number of bits of precision |
required |