Homodyne and heterodyne detectors not accepting modes in kwargs
Closed this issue · 0 comments
rachelchadwick commented
Before posting a bug report
- I have searched exisisting GitHub issues to make sure the issue does not already exist.
Expected behavior
Homodyne(modes=[m],...)
should apply a homodyne detector to mode m. Similarly for Heterodyne.
Actual behavior
It applies it to mode 0.
Reproduces how often
Homodyne(modes=[m],...)
always applies it to mode 0.
Note that Homodyne(...)[m]
works correctly, applying it to mode m.
Similarly for Heterodyne.
System information
Python version: 3.8.0
Platform info: Windows-10-10.0.19041-SP0
Installation path: C:\Users\Rache\AppData\Local\Programs\Python\Python38\lib\site-packages\mrmustard
Mr Mustard version: 0.1.1
Numpy version: 1.19.2
Numba version: 0.53.1
Scipy version: 1.4.1
The Walrus version: 0.17.0
TensorFlow version: 2.7.0
Torch version: None
Source code
from mrmustard.lab import *
import numpy as np
from mrmustard.utils.graphics import mikkel_plot
import matplotlib.pyplot as plt
# Initial state is two modes with "diagonal" (angle=pi/2) squeezed state in mode 0
# and "vertical" (angle=0) squeezed state in mode 1
S1 = Sgate(modes=[0], r=1, phi=np.pi/2)
S2 = Sgate(modes=[1], r=1, phi=0)
initial_state = Vacuum(2) >> S1 >> S2
# Because the modes are separable, measuring in one mode should leave
# the state as simply the state in the unmeasured mode unchanged
# A homodyne measurement on the second mode should leave
# the diagonal state in the first mode but doesn't
final_state = initial_state << Homodyne(modes=[1],quadrature_angle=0,result=[0.3])
mikkel_plot(np.array(final_state.dm()))
# But coded like this does work
final_state = initial_state << Homodyne(quadrature_angle=0,result=[0.3])[1]
mikkel_plot(np.array(final_state.dm()))
plt.show()
Tracebacks
No response
Additional information
Proposed fix from @ilan-tz:
`Homodyne` initializes `DisplacedSqueezed` which initializes `State`.
Line 370 in states.py currently is
`State.__init__(self, cov=cov, means=means, cutoffs=cutoffs)`
but should be
`State.__init__(self, cov=cov, means=means, cutoffs=cutoffs, modes=modes)`
Similarly for `Heterodyne`, line 112 in `Coherent` should have the modes kwarg added.
In fact, in general the modes of the states do not seem to depend on the kwarg `modes` but just the length of the list of parameters given.