Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself
The prepare_exponential_state function creates a state with exponentially decreasing amplitudes. Namely, the probability for a state representing an integer nn is P(n)=1ZeλnP\left(n\right) = \frac{1}{Z} e^{-\lambda n} where λ\lambda is the rate, and ZZ is a normalization factor. If qq in the number of qubits, then Z=n=0n=2q1eλn=1eλ2q1eλZ = \sum_{n=0} ^{n = 2^q - 1} e^{-\lambda n} = \frac{1 - e^{-\lambda 2^q}}{1 - e^{-\lambda}} Function: prepare_exponential_state Arguments:
  • rate: CReal
  • q: QArray[QBit]
Notice that the function acts inplace on the qubits.

Example

Prepare a state with probabilities: P(n)=1Ze0.1nP\left(n\right) = \frac{1}{Z} e^{-0.1 n} where nn is in the range [0,31][0, 31].
from classiq import *


@qfunc
def main(x: Output[QArray[QBit]]):
    allocate(5, x)
    prepare_exponential_state(0.1, x)


qmod = create_model(main)

qprog = synthesize(qmod)