Skip to content

Amplitude Estimation

The amplitude estimation function creates a segment that estimates the probability of the "good" states of a quantum state [1]. A quantum state can be decomposed into "good" and "bad" states. The amplitude estimation algorithm takes a state preparation circuit and uses it within Grover's operator to assess the probability of the good states. The algorithm ends with an inverse QFT applied to the evaluation qubits which can measured to obtain the required probability.

Syntax

Function: AmplitudeEstimation

Parameters:

  • state_preparation: str
  • num_eval_qubits: int
  • objective_qubits: List[int]

Example

{
  "constraints": {
    "max_width": 7,
    "max_depth": 1800
  },
  "logic_flow": [
    {
      "function": "AmplitudeEstimation",
      "function_params": {
        "state_preparation": "OPENQASM 2.0;\ninclude 'qelib1.inc';\nqreg q[4];\nh q[0];\nh q[1];\nh q[2];\nh q[3];\n",
        "num_eval_qubits": 3,
        "objective_qubits": [0, 2]
      }
    }
  ],
  "preferences": {
    "draw_at_level": 2
  }
}
from classiq import ModelDesigner
from classiq.builtin_functions import AmplitudeEstimation

from qiskit import QuantumCircuit

QUBIT_COUNT = 7
MAX_DEPTH = 1800

sp_circ = QuantumCircuit(4)
sp_circ.h([0, 1, 2, 3])

num_eval_qubits = 3
objective_qubits = [0, 2]

params = AmplitudeEstimation(
    state_preparation=sp_circ.qasm(),
    objective_qubits=objective_qubits,
    num_eval_qubits=num_eval_qubits,
)

model_designer = ModelDesigner()
model_designer.AmplitudeEstimation(params)
model_designer.preferences.draw_at_level = 2
circuit = model_designer.synthesize()

The example above presents a circuit that implements amplitude estimation. The good basis states are defined (in the SDK code) through objective_qubits - the list of qubit indices that have to be "1" for the state to be considered a good state. The quantum circuit for preparing the state to be estimated is defined by state_preparation, a quantum circuit in an OpenQASM format. Note that quotes inside the OpenQASM code should be ' instead of " (not as in the usual OpenQASM format). num_eval_qubits (\(m\)) is the number of evaluation qubits used in the inverse QFT, in addition to the qubits from the state preparation. The higher is \(m\) the more accurate the result is.

Note that the total number of qubits (max_width) has to be at least the sum of the qubits from the state preparation and the number of evaluation qubits.

amplitude estimation image

To execute the circuit, you may run the following code in the SDK:

Create the following file: execution_preferences.exct

{
    "preferences": {
        "backend_preferences": {
            "backend_service_provider": "IBMQ",
            "backend_name": "aer_simulator"
        },
        "amplitude_estimation":{
            "alpha":0.05,
            "epsilon":0.01,
            "objective_qubits": [0,2]
        }
    }
}
Run Classiq execute command (Classiq: Execute Quantum Program), choose a file containing the program and pick it's instruction set (e.g. QASM or ionq) and the outptut path.

from classiq import Executor
from classiq.interface.backend import backend_preferences
from classiq.interface.executor import execution_preferences

res = Executor(
    amplitude_estimation=execution_preferences.AmplitudeEstimation(
        alpha=0.05, epsilon=0.01, objective_qubits=objective_qubits
    ),
    num_shots=4000,
    backend_preferences=backend_preferences.IBMBackendPreferences(
        backend_name="aer_simulator"
    ),
).execute(circuit)

The printed result is:

print(f"The estimation of the good states is: {res.vendor_format_result['estimation']}")
The estimation of the good states is: 0.37364666315118733

References

[1]G. Brassard, P. Hoyer, M. Mosca, and A. Tapp, “Quantum Amplitude Amplification and Estimation,” arXiv:quant-ph/0005055, vol. 305, pp. 53–74, 2002, doi: 10.1090/conm/305/05215. https://arxiv.org/abs/quant-ph/0005055