Amplitude Loading¶
The amplitude loading function performs the following operation:
$|d\rangle |0\rangle \rightarrow \sqrt{1-f^2(d)}|d\rangle |0\rangle + f(d)|d\rangle |1\rangle$
for any input, $|d\rangle$, and function $f(d)$.
The function $f(d)$ is expected to be real and include only a single variable. Its domain is [0, 1] and its range is contained in [-1, 1]. For multi-argument or complex functions, an exception is raised. If, for some input, the function value exceeds the [-1, 1] range, the value is trimmed accordingly.
The function is implemented using repeated multiple controlled RY rotations where $|d\rangle$ is the control register and $|0\rangle$ is the target qubit.
Poles of the expression are automatically ignored (set to 0). For example, for the 1/x
function,
the zero input state is ignored, as it is undefined.
The function is invoked using the *=
expression, where the left side is the indicator qubit, and the right side is an expression of the input quantum state.
Example¶
The following code loads the function $x^2$ into the amplitude of a quantum state, using $|x\rangle$ of size 4 and a single indicator qubit.
from classiq import (
Output,
QArray,
QBit,
QNum,
allocate,
allocate_num,
create_model,
qfunc,
)
VAR_SIZE = 4
@qfunc
def main(x: Output[QNum], ind: Output[QNum]) -> None:
allocate_num(VAR_SIZE, False, VAR_SIZE, x)
allocate(1, ind)
ind *= x**2
qmod = create_model(main)
from classiq import synthesize, write_qmod
write_qmod(qmod, "amplitude_loading_example")
qprog = synthesize(qmod)