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

Loop sampling #25

Merged
merged 9 commits into from
Jul 17, 2019
Merged

Loop sampling #25

merged 9 commits into from
Jul 17, 2019

Conversation

nquesada
Copy link
Collaborator

Description of the Change:
Adds the ability to sample from Gaussian states with finite means, and at the same time simplifies the hafnian sampling functions. Also adds tests to the new functionality
Benefits:
Can sample from Gaussian states with non zero means.
Possible Drawbacks:
The syntax is slightly awkward in that the mean vector is (an optional argument) passed after the covariance matrix and the number of samples. Maybe it might be a good idea to use this syntax also in the quantum functions, i.e. make the vector of means of optional.
Related GitHub Issues:

@nquesada nquesada requested a review from bgupt July 11, 2019 19:15
@codecov
Copy link

codecov bot commented Jul 11, 2019

Codecov Report

Merging #25 into master will increase coverage by 0.21%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master      #25      +/-   ##
==========================================
+ Coverage      95%   95.21%   +0.21%     
==========================================
  Files           8        8              
  Lines         560      564       +4     
==========================================
+ Hits          532      537       +5     
+ Misses         28       27       -1
Impacted Files Coverage Δ
hafnian/samples.py 85.16% <100%> (+1.05%) ⬆️

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 fb814a6...b9edfb0. Read the comment docs.

Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

Awesome @nquesada. I'm in favour of bringing all the function signatures in-line, and making means optional everywhere.


np.random.seed(20)
np.random.seed(137)
Copy link
Member

Choose a reason for hiding this comment

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

How come you needed to change the seed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just like 137, it is a more quantum electrodynamical number ;)

Copy link
Member

Choose a reason for hiding this comment

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

🤣

Copy link
Contributor

Choose a reason for hiding this comment

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

@nquesada You have just given me my new favoite random number seed. 👍

probs1[i] = hafnian(mat).real / factpref
probs1[i] = density_matrix_element(
mu_red, V_red, indices, indices, include_prefactor=True, hbar=hbar
).real
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

assert np.allclose(
rel_freq, probs, rtol=rel_tol / np.sqrt(n_samples), atol=rel_tol / np.sqrt(n_samples)
)

Copy link
Member

Choose a reason for hiding this comment

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

great tests

hafnian/samples.py Outdated Show resolved Hide resolved
hafnian/samples.py Outdated Show resolved Hide resolved
probs1[i] = hafnian(mat).real / factpref
probs1[i] = density_matrix_element(
mu_red, V_red, indices, indices, include_prefactor=True, hbar=hbar
).real
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


np.random.seed(20)
np.random.seed(137)
Copy link
Contributor

Choose a reason for hiding this comment

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

@nquesada You have just given me my new favoite random number seed. 👍

@nquesada nquesada merged commit 0bed206 into master Jul 17, 2019
@nquesada nquesada deleted the loop_sampling branch July 17, 2019 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants