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(main)
show(qprog)
Opening: https://platform.classiq.io/circuit/2uFz2rmhHsIOvTysk7hpYPooM7a?version=0.70.0
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_solution = synthesize(main)
show(qprog_solution)
Opening: https://platform.classiq.io/circuit/2uFz3Vg2tRvstyBsb69dN0PcJ17?version=0.70.0