Skip to content

Amplitude-Encoding Assignment

Amplitude-encoding assignment represents the evaluation of an expression over a quantum variable in the amplitudes of the resulting state. The target qubit serves as an indicator for the success of the computation. Supported expressions include a number of useful math functions, including trigonometric functions and multiplicative invert (\(x^{-1}\)).


target-var *= expression

target-var *= expression


  • target-var must be initialized prior to the assignment.
  • Only a single quantum variable is allowed in expression, representing a real number in the domain [0, 1), that is, a qnum with no sign bit and with all fraction digits.
  • expression must evaluate to a real number in the domain [-1, 1]. Values that exceed this range are trimmed. Poles of the expression are ignored (set to 0). For example, given the expression 1/x, the zero state of x is ignored, as it is undefined.

  • For expression over quantum variable \(x\) that computes the function \(f(x)\), the operation performed by the statement is -

\(|x\rangle |0\rangle \rightarrow \sqrt{1-f^2(x)}|d\rangle |0\rangle + f(x)|x\rangle |1\rangle\)


In the following example, the function \(f(x) = x^2\) is computed over a quantum variable x:

qfunc main(output x: qnum<5, False, 5>, output ind: qnum) {
  ind *= x**2;
from classiq import QNum, qfunc, prepare_int, QBit
from classiq import (

def main(x: Output[QNum[5, False, 5]], ind: Output[QNum]) -> None:
    allocate(5, x)
    allocate(1, ind)
    ind *= x**2

Synthesizing and executing this model results in the histogram shown below. States with the variable ind sampled as 1 (on the right side of the histogram) have probabilities corresponding to \((x^2)^2\). The probability of states with ind sampled as 0 (on the left side of the histogram) correspond to \(\sqrt{1-(x^2)^2}\).