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 A, let |Ψ=A|0.

  • Write |Ψ=|Ψ1+|Ψ0 as a superposition of the orthogonal good and bad components of |Ψ.

  • Enhance the probability a=Ψ1|Ψ1 that a measurement of |Ψ yields a good state.

Let θa[0,π/2] such that sin2(θa)=a. Then the amplitude amplification operator Q acts as

Qj|Ψ=1asin((2j+1)θa)|Ψ1+11acos((2j+1)θa)|Ψ0.

Therefore, after m iterations the probability of measuring a good state is sin2((2m+1)θ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 |Ψ. 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 |Ψ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 |Ψ=cos(π16)|0+sin(π16)|1 and an oracle that tags the good state |1. In this case, we have a=sin2(π16)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>