Closed rdprins closed 3 years ago
Thanks @RobbeDePrins for reporting this bug!
Here is the problematic code from your previous post:
import strawberryfields as sf
from strawberryfields import ops
import numpy as np
num_iterations = 10
num_repeat = 10
prog = sf.TDMProgram(N=4)
with prog.context([0]*num_iterations) as (p, q):
ops.Fock(1) | q[0]
ops.Fock(0) | q[1]
ops.BSgate(0.1,0.2) | (q[0], q[1])
ops.BSgate(0.3,0.4) | (q[2], q[3])
ops.BSgate(0.5,0.6) | (q[1], q[2])
ops.MeasureFock() | (q[0], q[1])
eng = sf.Engine("fock", backend_options={"cutoff_dim": 5})
results = eng.run(prog, shots=num_repeat)
print(results.all_samples)
Note that I receive the exact same error regarding Number of measurement operators must match number of spatial modes
. In fact, this error message occurs after the end of the with
block, even before the engine is created --- so this is a TDM specific bug.
I had a look in the source code, and it appears that the issue is due to this line here:
@nquesada, is this intentional or a bug?
Regarding running the circuit on the Fock backend, from a SF point of view, it should be as simple as changing the line
to
if compiler in ("fock", "gaussian"):
return super().compile(device=device, compiler=compiler)
For a simple TDM program, I can verify this allows the TDMProgram to be executed on the Fock backend.
Hi @josh146 , @RobbeDePrins --- Thanks for submitting this report. After conferring with one of my colleagues I realized that the error message is indeed correct. You TDMProgram
actually has two spatial modes, each with two concurrent modes, thus you would need to set N=[2,2]
. You also need to be careful about how you order your gates/preparations. We are drafting a second TDM
tutorial and hoping to release it soon. We realize that writing time-domain program is not as easy as writing regular programs.
The other point I wanted to make is that while you can follow @josh146 and make changes locally, we currently do not support TDMprogram
in the Fock backends, it is something that we might consider in the future.
Issue description
Trying to use TDMprogram on sf.fock, I get an uninformative error. Apparently TDMprogram is not implemented on the fock backend. Tt is trying to find MeasureHomodyne statements inside the program and failing to do so.
Expected behavior: 'Error: TDMprogram is currently only available for Gaussian backend'
Actual behavior: 'ValueError: Number of measurement operators must match number of spatial modes.'
Reproduces how often: 100%