XanaduAI / strawberryfields

Strawberry Fields is a full-stack Python library for designing, simulating, and optimizing continuous variable (CV) quantum optical circuits.
https://strawberryfields.ai
Apache License 2.0
754 stars 191 forks source link

IndexError during program compliation #443

Closed heltluke closed 4 years ago

heltluke commented 4 years ago

Issue description

An IndexError during program compilation occurs for squeezing amplitudes of 0 and identity Interferometers.

Source code and tracebacks

Here is an example that will reproduce the error:

n_modes = 4
squeezing_amplitudes = [0] * n_modes
unitary = np.identity(n_modes)
prog = sf.Program(n_modes * 2)
with prog.context as q:
    for i in range(n_modes):
        sf.ops.S2gate(squeezing_amplitudes[i]) | (q[i], q[i + n_modes])
    for qumodes in (q[:n_modes], q[n_modes:]):
        sf.ops.Interferometer(unitary) | qumodes
    sf.ops.MeasureFock() | q
prog.compile(compiler="Xcov")

The error itself is

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-34-0ca84a06d898> in <module>
----> 1 prog.compile(compiler="Xcov")
~/anaconda3/envs/sf_latest/lib/python3.7/site-packages/strawberryfields/program.py in compile(self, device, compiler, **kwargs)
    554             seq = pu.optimize_circuit(seq)
    555 
--> 556         seq = compiler.compile(seq, self.register)
    557 
    558         # create the compiled Program
~/anaconda3/envs/sf_latest/lib/python3.7/site-packages/strawberryfields/compilers/xcov.py in compile(self, seq, registers)
    124 
    125             # extract the compiled symplectic matrix
--> 126             S = seq[0].op.p[0]
    127 
    128             if len(used_modes) != n_modes:
IndexError: list index out of range