Quantum Amplitude Amplification#
- amplitude_amplification(args, state_function, oracle_function, kwargs_oracle={}, iter=1, reflection_indices=None)[source]#
This method performs quantum amplitude amplification.
The problem of quantum amplitude amplification is described as follows:
Given a unitary operator \(\mathcal{A}\), let \(\ket{\Psi}=\mathcal{A}\ket{0}\).
Write \(\ket{\Psi}=\ket{\Psi_1}+\ket{\Psi_0}\) as a superposition of the orthogonal good and bad components of \(\ket{\Psi}\).
Enhance the probability \(a=\langle\Psi_1|\Psi_1\rangle\) that a measurement of \(\ket{\Psi}\) yields a good state.
Let \(\theta_a\in [0,\pi/2]\) such that \(\sin^2(\theta_a)=a\). Then the amplitude amplification operator \(\mathcal Q\) acts as
\[\mathcal Q^j\ket{\Psi}=\frac{1}{\sqrt{a}}\sin((2j+1)\theta_a)\ket{\Psi_1}+\frac{1}{\sqrt{1-a}}\cos((2j+1)\theta_a)\ket{\Psi_0}.\]Therefore, after \(m\) iterations the probability of measuring a good state is \(\sin^2((2m+1)\theta_a)\).
- Parameters:
- argsQuantumVariable or list[QuantumVariable]
The (list of) QuantumVariables which represent the state, the amplitude amplification is performed on.
- state_functionfunction
A Python function preparing the state \(\ket{\Psi}\). This function will receive the variables in the list
args
as arguments in the course of this algorithm.- oracle_functionfunction
A Python function tagging the good state \(\ket{\Psi_1}\). This function will receive the variables in the list
args
as arguments in the course of this algorithm.- kwargs_oracledict, optional
A dictionary containing keyword arguments for the oracle. The default is {}.
- iterint, optional
The amount of amplitude amplification iterations to perform. The default is 1.
- refection_indiceslist[int], optional
A list indicating with respect to which variables the reflection within the diffuser is performed, i.e. oblivious amplitude amplification is performed. By default, the reflection is performed with respect to all variables in
args
, i.e. standard amplitude amplification is performed.
Examples
We define a function that prepares the state \(\ket{\Psi}=\cos(\frac{\pi}{16})\ket{0}+\sin(\frac{\pi}{16})\ket{1}\) and an oracle that tags the good state \(\ket{1}\). In this case, we have \(a=\sin^2(\frac{\pi}{16})\approx 0.19509\).
from qrisp import z, ry, QuantumBool, amplitude_amplification import numpy as np def state_function(qb): ry(np.pi/8,qb) def oracle_function(qb): z(qb) qb = QuantumBool() state_function(qb)
>>> qb.qs.statevector(decimals=5) 0.98079∣False⟩+0.19509∣True⟩
We can enhance the probability of measuring the good state with amplitude amplification:
>>> amplitude_amplification([qb], state_function, oracle_function) >>> qb.qs.statevector(decimals=5) 0.83147*|False> + 0.55557*|True>
>>> amplitude_amplification([qb], state_function, oracle_function) >>> qb.qs.statevector(decimals=5) 0.55557*|False> + 0.83147*|True>
>>> amplitude_amplification([qb], state_function, oracle_function) >>> qb.qs.statevector(decimals=5) 0.19509*|False> + 0.98079*|True>