State preparation
State preparation is a very important part of many quantum algorithms. How a state is prepared can have a huge effect on the circuit characteristics. Here we will prepare the same state twice with different approximations to see how that can affect the generated circuit.
from classiq import *
amplitudes = [
0.2450344728207077,
-0.1700813505441722,
0.16769736623372838,
-0.0239052232765222,
0.34393605643711794,
-0.2966929669473228,
-0.2839167245810649,
0.3305828537849893,
-0.32376029368963405,
0.25704647614347453,
0.1531631416826692,
-0.07516264976664182,
-0.314744872342388,
-0.24992215398592088,
0.3526620654512262,
-0.015039183255468514,
]
Create a circuit to prepare the amplitudes
Use the prepare_amplitudes()
function to encode the amplitudes above into a quantum circuit. Use the defined bound
in your prepare_amplitudes()
function.
bound = 0.3
@qfunc
def main(
# target: Output[QArray]
):
# Your code here
pass
qprog = synthesize(create_model(main))
show(qprog)
Opening: https://platform.classiq.io/circuit/0cf6b636-9189-4280-9e13-e25517c8e1eb?version=0.41.0.dev39%2B79c8fd0855
Change the bound for 0.001
and look at the effect.
Why is there a big difference in circuit characteristics
The full solution for your reference
bound = 0.3
@qfunc
def main(target: Output[QArray]):
prepare_amplitudes(amplitudes=amplitudes, out=target, bound=bound)
qprog = synthesize(create_model(main))
show(qprog)
Opening: https://platform.classiq.io/circuit/b4e9649f-2578-4dbb-bc4c-de943266395a?version=0.41.0.dev39%2B79c8fd0855