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

Adds functions for calculating the total photon distribution of k lossy squeezed states #230

Merged
merged 10 commits into from
Mar 16, 2021

Conversation

nquesada
Copy link
Collaborator

This PR implements the results in Appendix 5 and Eqs. 8 and 9 of https://arxiv.org/pdf/2102.12474.pdf

@nquesada nquesada requested a review from thisac March 15, 2021 21:05
Copy link
Contributor

@thisac thisac left a comment

Choose a reason for hiding this comment

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

Not sure where to find the characteristic function in the paper (if it's there), so I wasn't able to check whether it was written down correctly. Other than that, it looks great! 💯

@@ -608,7 +608,7 @@ def tvd_cutoff_bounds(mu, cov, cutoff, hbar=2, check_is_valid_cov=True, rtol=1e-
and the user provided cutoff.

For the derivation see Appendix B of `'Exact simulation of Gaussian boson sampling in polynomial space and exponential time',
Quesada and Arrazola et al. <10.1103/PhysRevResearch.2.023005>`_.
Quesada and Arrazola <10.1103/PhysRevResearch.2.023005>`_.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't the full URL be needed here for the link to work? Although this function doesn't seem to be rendered in the docs at all. 🤔

Suggested change
Quesada and Arrazola <10.1103/PhysRevResearch.2.023005>`_.
Quesada and Arrazola <https://journals.aps.org/prresearch/abstract/10.1103/PhysRevResearch.2.023005>`_.


def total_photon_number_distribution(n, k, s, eta, pref=1.0):
r"""Probability of observing a total of :math:`n` photons when :math:`k` identical
single-mode squeezed vacua with squeezing parameter s undergo loss by transmission :math:`\eta`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I've actually never seen the word "vacua" before. 😄

Suggested change
single-mode squeezed vacua with squeezing parameter s undergo loss by transmission :math:`\eta`.
single-mode squeezed vacua with squeezing parameter ``s`` undergo loss by transmission :math:`\eta`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or actually change this to use :math:s as below. Same below for my n to :math:n suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thewalrus/quantum/photon_number_distributions.py Outdated Show resolved Hide resolved
thewalrus/quantum/photon_number_distributions.py Outdated Show resolved Hide resolved
"""Test that the total photon number distribution has the correct mean and variance"""
expectation_n = characteristic_function(s = s, k = k, eta = eta, poly_corr=1, mu = 0)
expectation_n2 = characteristic_function(s = s, k = k, eta = eta, poly_corr=2, mu = 0)
var_n =expectation_n2 - expectation_n ** 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var_n =expectation_n2 - expectation_n ** 2
var_n = expectation_n2 - expectation_n ** 2

Comment on lines 1541 to 1542
expectation_n = characteristic_function(s = s, k = k, eta = eta, poly_corr=1, mu = 0)
expectation_n2 = characteristic_function(s = s, k = k, eta = eta, poly_corr=2, mu = 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expectation_n = characteristic_function(s = s, k = k, eta = eta, poly_corr=1, mu = 0)
expectation_n2 = characteristic_function(s = s, k = k, eta = eta, poly_corr=2, mu = 0)
expectation_n = characteristic_function(s=s, k=k, eta=eta, poly_corr=1, mu=0)
expectation_n2 = characteristic_function(s=s, k=k, eta=eta, poly_corr=2, mu=0)

@pytest.mark.parametrize("k", [4, 6, 10, 12])
@pytest.mark.parametrize("eta", [0, 0.1, 0.5, 1])
def test_characteristic_function_is_normalized(s, k, eta):
r"""Check that when evaluated at \mu=1 the characteristic function gives 1"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
r"""Check that when evaluated at \mu=1 the characteristic function gives 1"""
r"""Check that when evaluated at mu=1 the characteristic function gives 1"""

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me like this function evaluates at mu=0 rather than mu=1 as is stated here. Typo? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch!

# Note that s must be less than np.arctanh(np.sqrt(0.5)) ~= 0.88
p = np.tanh(s)**2
val = characteristic_function(k=k, s=s, eta=1.0, mu=mu)
expected = ((1-p)/(1-2*p))**(k/2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expected = ((1-p)/(1-2*p))**(k/2)
expected = ((1 - p) / (1 - 2 * p)) ** (k / 2)

@pytest.mark.parametrize("k", [4, 6, 10, 12])
def test_charactetistic_function_no_loss(s, k):
"""Check the values of the characteristic function when there is no loss"""
mu = mu = 0.5*np.log(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
mu = mu = 0.5*np.log(2)
mu = 0.5 * np.log(2)

@thisac
Copy link
Contributor

thisac commented Mar 15, 2021

🚨
complexcode

@nquesada
Copy link
Collaborator Author

yeah, not sure about the complex code in test_quantum it is probably code cov saying it is time to split this file....

nquesada and others added 3 commits March 15, 2021 18:01
Co-authored-by: Theodor <theodor@xanadu.ai>
Co-authored-by: Theodor <theodor@xanadu.ai>
@codecov
Copy link

codecov bot commented Mar 15, 2021

Codecov Report

Merging #230 (959d492) into master (655e089) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #230   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         1200      1228   +28     
=========================================
+ Hits          1200      1228   +28     
Impacted Files Coverage Δ
thewalrus/quantum/__init__.py 100.00% <ø> (ø)
thewalrus/quantum/fock_tensors.py 100.00% <ø> (ø)
thewalrus/quantum/photon_number_distributions.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 655e089...959d492. Read the comment docs.

@josh146 josh146 merged commit 919d6a9 into master Mar 16, 2021
@josh146 josh146 deleted the total_n branch March 16, 2021 04:19
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