Hi @Satanik_Mitra!
A program becomes locked after it is run, as you can see in the note here. The issue in your code is the second run of the for
loop. There, the prog.context
context manager is trying to add to the program, which is locked due to the first eng.run()
.
My intention was to execute the Engine for 2 times in a loop with same X1 and X2 values.
I’m curious about your use case. Is the idea of running twice with the same values to extract samples from the homodyne measurement? If so, sampling can be done in the following way:
import strawberryfields as sf
from strawberryfields.ops import *
shots = 100
prog = sf.Program(2)
x1 = 0.4
x2 = 0.5
with prog.context as q:
Squeezed(x1) | q[0]
Squeezed(x2) | q[1]
BSgate(0.4, 0.10) | (q[0], q[1])
Rgate(0.4) | q[0]
Rgate(0.4) | q[1]
MeasureHomodyne(0.0) | q[0]
eng = sf.Engine("fock", backend_options={"cutoff_dim": 4})
samples = []
for i in range(shots):
result = eng.run(prog)
s = result.samples
samples.append(s.flatten()[0])
Alternatively, if you are looking for batching with the TF backend, check out our tutorial here.