Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from Apr 14, 2020

Conversation

josh146
Copy link
Member

@josh146 josh146 commented Apr 14, 2020

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

@josh146 josh146 added the bug Something isn't working label Apr 14, 2020
@codecov
Copy link

codecov bot commented Apr 14, 2020

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%) ⬆️

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.

strawberryfields/backends/fockbackend/circuit.py Outdated Show resolved Hide resolved
Copy link
Contributor

@antalszava antalszava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Once the question about a correct threshold is revisited, it's ready to be merged from my side (e.g. the current indeed being deemed to fit this use case).

@josh146 josh146 merged commit 19b6b63 into master Apr 14, 2020
@josh146 josh146 deleted the bug-homodyne-fock branch April 14, 2020 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working review-ready
Projects
None yet
4 participants