XanaduAI / thewalrus

A library for the calculation of hafnians, Hermite polynomials and Gaussian boson sampling.
https://the-walrus.readthedocs.io
Apache License 2.0
100 stars 55 forks source link

modify generate_hafnian_sample to renormalize probabilities #250

Closed soranjh closed 3 years ago

soranjh commented 3 years ago

Context: This PR modifies the generate_hafnian_sample function by renormalizing probabilities. The sum of the computed probabilities in this function is sometimes slightly larger than 1.0 which leads to an error in generating random samples with numpy.random.choice. This error prevents simulating the vibronic properties of large molecules.

Description of the Change: The if statement in line 157 of samples.py is removed such that the probabilities are always renormalized if their sum is larger than 1.0.

Related GitHub Issues: https://github.com/XanaduAI/strawberryfields/issues/597

codecov[bot] commented 3 years ago

Codecov Report

Merging #250 (b4165e2) into master (e32c40a) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #250   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         1294      1293    -1     
=========================================
- Hits          1294      1293    -1     
Impacted Files Coverage Δ
thewalrus/samples.py 100.00% <100.00%> (ø)

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 e32c40a...b4165e2. Read the comment docs.

nquesada commented 3 years ago

Thanks @soranjh : can you confirm that when you do this change the user who made the issue in SF stops getting errors?

soranjh commented 3 years ago

Thanks @soranjh : can you confirm that when you do this change the user who made the issue in SF stops getting errors?

Yes. The error disappears for one example.