XanaduAI / thewalrus

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

Adds a new function which allows for threshold detection probabilities with displaced Gaussian states #220

Closed jakeffbulmer closed 3 years ago

jakeffbulmer commented 3 years ago

Context: The Torontonian is a function which helps to calculate probabilities of threshold detection measurements on Gaussian states with zero displacement. In this PR we add a new function which allows for threshold detection probabilities with displaced Gaussian states.

Description of the Change: New function 'threshold_detection_prob' in _torontonian.py, test in tests/test_torontonian.py

Benefits: Threshold detection probabilities can now be calculated for any Gaussian state. Such a formula does not appear in any literature to our knowledge

Possible Drawbacks: Numba jit compiling is a bit slow, for light use it might be practical to have a none compiled version?

Related GitHub Issues: The readme testing procedure should be updated to say that pytest-randomly is required to run the 'make test'

josh146 commented 3 years ago

Thanks for the contribution @jakeffbulmer!

Regarding the continuous integration, the osx-wheels job is currently broken, so will not pass (we are trying to fix this in #219), so don't worry too much if this one fails.

jakeffbulmer commented 3 years ago

Hi Josh,

Thanks! This is the first time I've done a PR to an open-source project like this, so if there is anything I've missed please let me know.

Thanks, Jake


From: Josh Izaac notifications@github.com Sent: 18 December 2020 17:09 To: XanaduAI/thewalrus thewalrus@noreply.github.com Cc: Jake Franklin Bulmer jacob.bulmer@bristol.ac.uk; Mention mention@noreply.github.com Subject: Re: [XanaduAI/thewalrus] Thresh disp (#220)

Thanks for the contribution @jakeffbulmerhttps://github.com/jakeffbulmer!

Regarding the continuous integration, the osx-wheels job is currently broken, so will not pass (we are trying to fix this in #219https://github.com/XanaduAI/thewalrus/pull/219), so don't worry too much if this one fails.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/XanaduAI/thewalrus/pull/220#issuecomment-748209847, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANG45HNKVSZ7L4G5IPJ6A6DSVOEEDANCNFSM4VBN5K3Q.

josh146 commented 3 years ago

No worries! And to answer your previous question, this is definitely something that is worth adding to the changelog :) There is also a Contributors section where you can add your name

nquesada commented 3 years ago

@jakeffbulmer don't forget to also update the Acknowledgements page

codecov[bot] commented 3 years ago

Codecov Report

Merging #220 (309e580) into master (73df41a) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #220   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         1228      1248   +20     
=========================================
+ Hits          1228      1248   +20     
Impacted Files Coverage Δ
thewalrus/__init__.py 100.00% <100.00%> (ø)
thewalrus/_torontonian.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 73df41a...309e580. Read the comment docs.

nquesada commented 3 years ago

@jakebulmer : when I run the code I get the following warning: ` ======================================================================= warnings summary ======================================================================= thewalrus/tests/test_torontonian.py::test_tor_and_threshold_prob_agree[1] /home/nquesada/Code/thewalrus/thewalrus/_torontonian.py:194: NumbaPendingDeprecationWarning: Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'a' of function 'np_asarray..impl'.

For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types

File "../../../../.local/lib/python3.6/site-packages/numba/np/arraymath.py", line 4039: if is_nonelike(dtype): def impl(a, dtype=None): ^

det_pattern = np.asarray(det_pattern)

thewalrus/tests/test_torontonian.py::test_tor_and_threshold_prob_agree[1] /home/nquesada/.local/lib/python3.6/site-packages/numba/core/ir_utils.py:2031: NumbaPendingDeprecationWarning: Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'det_pattern' of function 'threshold_detection_prob_displacement'.

For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types

File "../_torontonian.py", line 178: @numba.jit(nopython=True) def threshold_detection_prob_displacement(mu, cov, det_pattern, hbar=2): # pragma: no cover ^

warnings.warn(NumbaPendingDeprecationWarning(msg, loc=loc))

-- Docs: https://docs.pytest.org/en/latest/warnings.html ======================================================= 9 passed, 2464 deselected, 2 warnings in 13.41s ======================================================== `

Can you look into this?

jakeffbulmer commented 3 years ago

thanks for the comments @thisac, let me know if there is anything else I can do