Use this file to discover all available pages before exploring further.
View on GitHub
Open this notebook in GitHub to run it yourself
Most quantum applications start with preparing a state in a quantum register.For example, in finance the state may represent the price distribution of some assets.
In chemistry, it may be an initial guess for the ground state of a molecule, and in
a quantum machine learning, a feature vector to analyze.The state preparation functions creates a quantum program that
outputs either a probability distribution pi or a real amplitudes
vector ai in the computational basis, with i denoting the corresponding
basis state.The amplitudes take the form of list of float numbers.The probabilities are a list of positive numbers.This is the resulting wave function for probability:∣ψ⟩=i∑pi∣i⟩,and this is for amplitude:∣ψ⟩=i∑ai∣i⟩.In general, state preparation is hard.Only a very small portion
of the Hilbert space can be prepared efficiently (in O(poly(n))
steps) on a quantum program. Therefore, in practice, an approximation
is often used to lower the complexity.The approximation is specified
by an error bound, using the L2 norm.The higher the specified error tolerance, the smaller the output
quantum program.For exact state preparation, specify an error bound of 0.The state preparation algorithm can be tuned depending on whether the
probability distribution is sparse or dense.The synthesis engine will
automatically select the parameterization based on the given constraints and
optimization level.Function: prepare_stateParameters:
probabilities: CArray[CReal]
Probabilities to load.
Should be non-negative and sum to
bound: CReal
Approximation Error Bound, in the L2 metric (with respect to the given probabilies vector).
out: Output[QArray[QBit]]
Function: inplace_prepare_stateParameters:
probabilities: CArray[CReal]
bound: CReal
out: QArray[QBit]
Should of size exactly log2(“probabilities.len`)
The inplace_prepare_state works the same, but for a given allocated QArray.Function: prepare_amplitudesParameters:
amplitudes: CArray[CReal]
Amplitudes of the loaded state.
Each should be real and the vector norm should be equal to
bound: CReal
Approximation Error Bound, in the L2 metric (with respect to the given amplitudes vector).
out: Output[QArray[QBit]]
Function: inplace_prepare_amplitudesParameters:
amplitudes: CArray[CReal]
Amplitudes of the loaded state.
Each should be real and the vector norm should be equal to
bound: CReal
Approximation Error Bound, in the L2 metric (with respect to the given amplitudes vector).
out: QArray[QBit]
Should of size exactly log2(amplitudes.len)
The inplace_prepare_amplitudes works the same, but for a given allocated QArray.
This example generates a quantum program whose output state probabilities are an approximation to the PMF given.That is, the probability of measuring the state ∣000⟩ is 0.05, ∣001⟩ is 0.11,…
, and the probability to measure ∣111⟩ is 0.06.