Quantum Amplitude Estimation#
- QAE(args, state_function, oracle_function, kwargs_oracle={}, precision=None, target=None)[source]#
This method implements the canonical quantum amplitude estimation (QAE) algorithm by Brassard et al..
The problem of quantum amplitude estimation is described as follows:
Given a unitary operator
, let .Write
as a superposition of the orthogonal good and bad components of .Find an estimate for
, the probability that a measurement of yields a good state.
- Parameters:
- argsQuantumVariable or list[QuantumVariable]
The (list of) QuantumVariables which represent the state, the quantum amplitude estimation is performed on.
- state_functionfunction
A Python function preparing the state
. This function will receive the variables in the listargs
as arguments in the course of this algorithm.- oracle_functionfunction
A Python function tagging the good state
. This function will receive the variables in the listargs
as arguments in the course of this algorithm.- kwargs_oracledict, optional
A dictionary containing keyword arguments for the oracle. The default is {}.
- precisionint, optional
The precision of the estimation. The default is None.
- targetQuantumFloat, optional
A target QuantumFloat to perform the estimation into. The default is None. If given neither a precision nor a target, an Exception will be raised.
- Returns:
- resQuantumFloat
A QuantumFloat encoding the angle
as a fraction of , such that is an estimate for .More precisely, we have
for and . After measurement, the estimate satisfieswith probability of at least
.
Examples
We define a function that prepares the state
and an oracle that tags the good state . In this case, we have .from qrisp import z, ry, QuantumBool, QAE import numpy as np def state_function(qb): ry(np.pi/4,qb) def oracle_function(qb): z(qb) qb = QuantumBool() res = QAE([qb], state_function, oracle_function, precision=3)
>>> res.get_measurement() {0.125: 0.5, 0.875: 0.5}
That is, after measurement we find
or with probability , respectively. Therefore, we obtain the estimate or . In this case, both results coincide with the exact value .Numerical integration
Here, we demonstarate how to use QAE for numerical integration.
Consider a continuous function
. We wish to evaluateFor this, we set up the corresponding
state_function
acting on theinput_list
:from qrisp import QuantumFloat, QuantumBool, control, z, h, ry, QAE import numpy as np n = 6 inp = QuantumFloat(n,-n) tar = QuantumBool() input_list = [inp, tar]
Here,
is the number of sampling points the function is evaluated on. Thestate_function
acts asThen the probability of measuring
in the target statetar
iswhich acts as an approximation for the value of the integral
.The
oracle_function
, therefore, tags the state of the target state:def oracle_function(inp, tar): z(tar)
For example, if
thestate_function
can be implemented as follows:def state_function(inp, tar): h(inp) N = 2**inp.size for k in range(inp.size): with control(inp[k]): ry(2**(k+1)/N,tar)
Finally, we apply QAE and obtain an estimate
for the value of the integral .prec = 6 res = QAE(input_list, state_function, oracle_function, precision=prec) meas_res = res.get_measurement() theta = np.pi*max(meas_res, key=meas_res.get) a = np.sin(theta)**2
>>> a 0.26430