Hi,
I am a bit confused about how to solve the following error CircuitError: The Program is locked, no more Commands can be appended to it. I think I understand why the error happens but I can’t come up with a way to run the circuit iteratively for a variational algorithm and avoid this error. The answer here for sampling makes sense. But what about the case when you want to run the circuit iteratively with a new parameter? I tried to eng.reset() at the end of for loop but it didn’t help.
I’d appreciate it if you could point out what I am missing here.
import strawberryfields as sf
from strawberryfields.ops import *
shots=2
prog = sf.Program(2)
x1 = 0.4
x2 = 0.5
param=[0.1, 0.4, 0.9]
steps=3
eng = sf.Engine("fock", backend_options={"cutoff_dim": 4})
def run_circuit(param):
with prog.context as q:
Squeezed(x1) | q[0]
Squeezed(x2) | q[1]
Zgate(-2*param) | q[0]
CZgate(-2*param) | (q[0],q[1])
MeasureHomodyne(0.0) | q[0]
return
for j in range(steps):
run_circuit(param[j])
result = eng.run(prog)
s = result.samples
# check if a condition is fulfilled
# update parameter, go to next iteration, re-run the circuit with new parameter and collect measurment results