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

Now the non-recursive function do not produce warning #386

Merged
merged 15 commits into from
Apr 24, 2024

Conversation

nquesada
Copy link
Collaborator

Minor changes to remove some numba warnings.

Comment on lines 232 to 236
if method == "diagonals":
patt_long = (i,) + tuple(N_nums)
dm[i, i] = pref * np.real(
haf_blocked(A, blocks=blocks, repeats=patt_long)
/ np.prod(factorial(patt_long))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rachelchadwick compare with

def probabilities_single_mode(cov, pattern, normalize=False, LO_overlap=None, cutoff=13, hbar=2):

Comment on lines -1313 to -1378
@pytest.mark.parametrize("method", ["recursive", "non-recursive"])
def test_vac_schmidt_modes_gkp(method):
"""
add vacuum schmidt modes and check it doesn't change the state
"""
m1, m2 = 5, 7
params = np.array(
[
-1.38155106,
-1.21699567,
0.7798817,
1.04182349,
0.87702211,
0.90243916,
1.48353639,
1.6962906,
-0.24251599,
0.1958,
]
)
sq_r = params[:3]
bs_theta1, bs_theta2, bs_theta3 = params[3:6]
bs_phi1, bs_phi2, bs_phi3 = params[6:9]
sq_virt = params[9]

S1 = squeezing(np.abs(sq_r), phi=np.angle(sq_r))
BS1, BS2, BS3 = (
beam_splitter(bs_theta1, bs_phi1),
beam_splitter(bs_theta2, bs_phi2),
beam_splitter(bs_theta3, bs_phi3),
)
Usymp1, Usymp2, Usymp3 = (
expand(BS1, [0, 1], 3),
expand(BS2, [1, 2], 3),
expand(BS3, [0, 1], 3),
)
Usymp = Usymp3 @ Usymp2 @ Usymp1
r2 = np.array([0, 0, sq_virt])
S2 = squeezing(np.abs(r2), phi=np.angle(r2))
Z = S2 @ Usymp @ S1
cov = Z @ Z.T
mu = np.zeros([len(cov)])

cutoff = 26
psi = state_vector(mu, cov, post_select={1: m1, 2: m2}, cutoff=cutoff)

rho1 = np.outer(psi, psi.conj())
rho1 /= np.trace(rho1)

M = 3
K = 5
big_cov = np.eye(2 * M * K, dtype=np.complex128)
big_cov[::K, ::K] = cov

rho_big = density_matrix_single_mode(big_cov, {1: m1, 2: m2}, cutoff=cutoff, method=method)
rho_big /= np.trace(rho_big)

assert np.allclose(rho1, rho_big, atol=4e-4)
probs = np.diag(
density_matrix_single_mode(
big_cov, {1: m1, 2: m2}, cutoff=cutoff, normalize=True, method="diagonals"
)
)
assert np.allclose(np.diag(rho1), probs)


Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test was just moved to the end of the file.

Comment on lines -1418 to -1467
@pytest.mark.parametrize("cutoff", [8, 9])
@pytest.mark.parametrize("method", ["non-recursive"])
def test_density_matrix(cutoff, method):
"""
test generation of heralded density matrix against combinatorial calculation
"""
# Note that the recursive method fails this
U = unitary_group.rvs(2)

N = {0: 3}

efficiency = 1 * np.ones(2)

noise = None

n0 = 2.9267754749886055
n1 = 2.592138225047742
zs0 = np.array([np.arcsinh(np.sqrt(n0))])
zs1 = np.array([np.arcsinh(np.sqrt(n1))])
rjs = [zs0, zs1]

O = np.identity(2, dtype=np.complex128)
S = 0.8 * np.exp(0 * 1j)
O[0, 1] = S.conj()
O[1, 0] = S

dm = heralded_density_matrix(
rjs, O, U, N, efficiency=efficiency, noise=noise, Ncutoff=cutoff, thresh=5e-3
)

rho = np.zeros((cutoff, cutoff), dtype=np.complex128)
for i in range(cutoff):
for j in range(cutoff):
rho[i, j] = sum(dm[i, j, m, m] for m in range(cutoff))

rho_norm = rho / np.trace(rho)

cov = prepare_cov(rjs, U, O=O, thresh=5e-3)

rho2 = density_matrix_single_mode(cov, N, cutoff=cutoff, method=method)
rho2_norm = rho2 / np.trace(rho2).real

probs = np.diag(
density_matrix_single_mode(cov, N, cutoff=cutoff, normalize=True, method="diagonals")
)

assert np.allclose(rho_norm, rho2_norm, atol=1e-6, rtol=1e-6)
assert np.allclose(np.diag(rho_norm), probs)


Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test was just moved to the end of the file.

Comment on lines +224 to +228
else:
for i in range(cutoff):
patt_long = (i,) + tuple(N_nums)
dm[i, i] = pref * np.real(
haf_blocked(A, blocks=blocks, repeats=patt_long) / np.prod(factorial(patt_long))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rachelchadwick this is the same as

def probabilities_single_mode(cov, pattern, normalize=False, LO_overlap=None, cutoff=13, hbar=2):

@nquesada nquesada merged commit 5666166 into off_diagonal Apr 24, 2024
2 of 3 checks passed
@nquesada nquesada deleted the warning_off_diagonals branch April 24, 2024 16:09
rachelchadwick added a commit that referenced this pull request May 1, 2024
* First commit

* Fixes bug

* removes unused import

* Working version

* Passes black

* removes unused function

* removes unused function

* Rachels code review (#385)

* Minor fixes

* passes black

* Fix test

* removes unused function

* test error is raised

* test error is raised

* Passes black

* Passes black

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>

* Now the non-recursive function do not produce warning (#386)

* Now the non-recursive function do not produce warning

* Now the non-recursive function do not produce warning

* Passes black

* Simplifies the diagonal method

* More tests, always

* More tests, always

* minor pylint improvements

* Adds extra test

* black

* minor simplification

* some tests pass

* some tests pass

* Moves the tests that take forever to the end of the test file

* Passes black

* Adds else

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

* Adds the warning (#388)

* Adds the warning

* passes black

* Apply suggestions from code review

Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>

* Update thewalrus/internal_modes/fock_density_matrices.py

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>

* Windows fix for numba types (#389)

* Fix numba types

* Passes black

* Apply suggestions from code review

* Apply suggestions from code review

* passes black

* Make lists tuples

* Check non-recursive

* Tests with high tolerances

* Run black

* Update test_density_matrix

* Minor changes

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
Co-authored-by: Nicolas Quesada <991946+nquesada@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>

* removes unnecesary import

* Squashed commit of the following:

commit 7c63905
Merge: 127a1a7 f935053
Author: Eli Bourassa <53090166+elib20@users.noreply.github.com>
Date:   Mon Apr 29 14:16:22 2024 -0400

    Merge branch 'master' into internal_modes

commit f935053
Author: Alberto Fumagalli <alberto@xanadu.ai>
Date:   Mon Apr 29 14:14:51 2024 -0400

    Add codecov token to test workflow (#390)

commit fe9e112
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Wed Apr 10 15:31:34 2024 -0400

    Updates references (#384)

    * updates references

    * Updates biblio

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit 25b5f08
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Wed Feb 28 20:35:28 2024 -0500

    Implements the pre-Iwasawa and Iwasawa decompositions. (#382)

    * First working version

    * First working version

    * First working version

    * better tests

    * better tests

    * Finally correct

    * Finally correct

    * putting the traingles in the right places

    * Removes unnecesary T

    * More tests

    * More tests and spell correction

    * More tests and spell correction

    * Removes unnecesary complex number usage

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

commit 127a1a7
Merge: e6de063 8759363
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Tue Feb 13 16:43:20 2024 -0500

    Merge branch 'master' into internal_modes

commit 8759363
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Thu Feb 1 16:57:23 2024 -0500

    Better blochmessiah (#381)

    * Nicer BM

    * Updates changelog

    * Unnecesary import

    * More simplifications

    * More simplifications

    * one more

    * Updates docstring

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit 6247fc8
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Wed Jan 24 10:43:57 2024 -0500

    Updates docstring and simplifies Williamson (#380)

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit 0b1af63
Author: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>
Date:   Thu Jan 11 17:09:32 2024 -0500

    Increment version number to `0.22.0-dev` (#379)

commit 544c457
Author: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>
Date:   Wed Jan 10 16:52:38 2024 -0500

    bump version to `0.21.0` (#378)

commit 2268bf0
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Thu Jan 4 11:12:27 2024 -0500

    Adds extra degenerate tests with nonvac nullspace (#377)

    * Adds extra degenerate tests with nonvac nullspace

    * updates changelog

    * updates changelog

    * updates changelog

    * Removes unnecesary comment

    * Still breaking something

    * Simplifications still work

    * Simplifications still work

    * Fixes bug

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit 8ec2172
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Wed Nov 29 15:53:11 2023 -0500

    Implements the Montrealer (#374)

    * Saving changes

    * Passes black

    * Passes black

    * Black

    * updates acknowledgements and changelog

    * updates acknowledgements and changelog

    * Adds montrealer

    * Adds Montrealer tests (#375)

    * Yanic the pirate

    * mtl test

    * mtl first tests

    * mtl test

    * test mtl

    * test montrealer

    * test montrealer

    * test Montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * tests montrealer

    * montrealer test

    * montrealer test

    * montrealer test

    * montrealer test

    * montrealer test

    * test montrealer

    * test montrealer

    * montrealer test

    * montrealer test

    * montrealer test

    * montrealer tests

    * montrealer tests

    * montrealer tests

    * montrealer tests

    * functions header update

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer ready for review

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer - failed tests

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * the rspms are now ordered

    * Passes black

    * garbage test file to be deleted later

    * minor changes

    * Done

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

    * making bots happy

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Apply suggestions from code review

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Adds extra tests

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
    Co-authored-by: Yanic Cardin <yanic.cardin.1@gmail.com>
    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

commit 0e163bf
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Tue Aug 22 10:19:08 2023 -0400

    Update symplectic.py (#372)

    * Update decompositions.py

    * New takagi

    * New takagi

    * Passes black

    * Simplifies blochmessiah

    * Simplifies blochmessiah

    * Found a case that breaks Takagi

    * Fixes all the tests

    * Fixes issues found by the linter

    * Adds extra test

    * Adds extra test

    * dummy

    * dummy

    * Update symplectic.py

    Removes `autonne`

    * relocates test

    * trying to make pylint happy

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit e999e49
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Thu Aug 17 12:55:45 2023 -0400

    Better way to determine if a matrix is a phase times a real matrix (#373)

    * Add a better way to determine if a matrix is a phase times a real matrix and tests

    * CHANGELOG updates

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

* Revert "Squashed commit of the following:"

This reverts commit 0f99b20.

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>
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.

2 participants