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

Fixes bug where negative probabilities can be calculated during Homodyne measurement in the Fock backend #364

Closed josh146 closed 4 years ago

josh146 commented 4 years ago

Context:

To calculate homodyne measurements in the Fock backend, a Hermite polynomial probability distribution is computed. However, due to floating point precision error, values in the probability distribution may have a small negative value (e.g., -2e-20), causing issues when np.random.multinomial is subsequently called.

Description of the Change:

Small negative values are set to zero in the probability distribution using NumPy fancy indexing.

Benefits: Fixes #354

Possible Drawbacks: n/a

Related GitHub Issues: #354

codecov[bot] commented 4 years ago

Codecov Report

Merging #364 into master will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #364   +/-   ##
=======================================
  Coverage   97.68%   97.68%           
=======================================
  Files          52       52           
  Lines        6443     6444    +1     
=======================================
+ Hits         6294     6295    +1     
  Misses        149      149           
Impacted Files Coverage Δ
strawberryfields/backends/fockbackend/circuit.py 98.42% <100.00%> (+<0.01%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a0d9ad0...4de1d46. Read the comment docs.