iqae
eigenkit.algorithms.iqae
IQAE
Bases: BaseQuantumSolver
Iterative Quantum Amplitude Estimation (IQAE).
Estimates \(a = \lvert \langle \psi_1 | A | 0 \rangle \rvert^2\) to an additive
precision epsilon, with a failure probability of at most alpha. It uses the Grover
operator \(Q = A S_0 A^\dagger S_{\psi_1}\), built from the oracle \(A\) that you
provide.
The oracle can be given in two forms:
- A PennyLane callable
oracle(wires), which applies the circuit \(A\) in place. The last wire (wires[-1]) must be the ancilla qubit:
The matrix of the circuit is extracted internally with qml.matrix, so this
form requires provider="pennylane" and the pennylane extra.
- A
CircuitSpec, which works on any backend that supports theQubitUnitary,X,MCZandZgates. With a provider other than PennyLane, passshot_mode="synthetic"orshot_mode="auto", becauseshot_mode="provider"works only with PennyLane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsilon
|
float
|
The additive precision to reach, that is, the half-width of the final confidence interval for \(a\). It must be in \((0, \pi/8)\). |
required |
alpha
|
float
|
The total failure probability. The algorithm applies a Bonferroni correction, so the confidence interval of each round is valid at level \(\alpha / T\), where \(T = \lceil \log_2(\pi / (8\varepsilon)) \rceil\) is the maximum number of rounds. It must be in \((0, 1)\). |
required |
n_qubits
|
int
|
The total number of qubits, including the ancilla. |
required |
provider
|
ProviderSpec
|
The backend to use: a registered name ( |
'numpy'
|
n_shots
|
int
|
The number of measurement shots per round. With
|
100
|
shot_mode
|
ShotMode
|
How the ancilla measurements are obtained. With |
'auto'
|
min_ratio
|
float
|
The minimum ratio \(K_{i+1} / K_i\) between the Grover powers of consecutive rounds. It must be greater than 1. |
2.0
|
random_state
|
int | None
|
The seed of the random number generator used for the shot
noise. An integer gives reproducible results, and |
42
|
Example
import numpy as np
from eigenkit import CircuitBuilder
from eigenkit.algorithms import IQAE
# RY(pi/3) on the ancilla prepares an amplitude of sin^2(pi/6) = 0.25.
qc = CircuitBuilder(n_qubits=2)
qc.ry(np.pi / 3, qubit=1)
oracle = qc.build()
iqae = IQAE(epsilon=0.02, alpha=0.05, n_qubits=2, random_state=0)
result = iqae.solve(oracle)
print(result.estimation) # 0.246
print(result.confidence_interval) # (0.2407, 0.2513), which contains 0.25
print(result.n_oracle_calls) # 2600
solve(oracle)
Estimate the amplitude \(a = \lvert \langle \psi_1 | A | 0 \rangle \rvert^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oracle
|
Callable | CircuitSpec
|
Either a PennyLane callable |
required |
Returns:
| Type | Description |
|---|---|
IQAEResult
|
An |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the selected provider does not support the gates that IQAE
needs ( |
IQAEResult
dataclass
Bases: ValueEquality
Outcome of a completed Iterative Quantum Amplitude Estimation (IQAE) run.
The result is read-only. Assigning to a field raises FrozenInstanceError, so
a mistyped = (instead of ==) cannot change a result. This type holds no
arrays, so nothing else needs protecting.
Results compare by value. They are not hashable, so that all result types behave in the same way: the types that hold arrays cannot be hashed both correctly and efficiently.
Attributes:
| Name | Type | Description |
|---|---|---|
estimation |
float
|
The point estimate of the amplitude \(a\). |
confidence_interval |
tuple[float, float]
|
The |
n_rounds |
int
|
The number of rounds that the run executed. It can also be read
as |
n_oracle_calls |
int
|
The total number of oracle calls over all rounds. |
success |
bool
|
Whether the interval reached the requested precision. This is the
same test that ends the loop over rounds, and the one reported by the
warning that the run did not converge. |
n_iterations
property
The number of rounds, under the name that the other results use.
n_rounds is the name that IQAE uses, and it stays available. This property
lets one loop read the number of iterations from any result.
Returns:
| Type | Description |
|---|---|
int
|
The number of rounds that the run executed. |