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

reduced state fix #395

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

* Add the calculation method of `takagi` when the matrix is diagonal. [(#394)](https://github.com/XanaduAI/thewalrus/pull/394)

* Add the lines for avoiding the comparison of np.ndarray and list.

### Documentation

### Contributors
Expand Down
3 changes: 3 additions & 0 deletions thewalrus/symplectic.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ def reduced_state(mu, cov, modes):
"""
N = len(mu) // 2

if type(modes) == np.ndarray:
Copy link
Collaborator

Choose a reason for hiding this comment

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

You probably need to add a test to trigger this line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you. I added the test!

modes = modes.tolist()

if modes == list(range(N)):
# reduced state is full state
return mu, cov
Expand Down
9 changes: 9 additions & 0 deletions thewalrus/tests/test_symplectic.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ def test_tms(self, hbar, tol):
assert np.allclose(res[0], expected[0], atol=tol, rtol=0)
assert np.allclose(res[1], expected[1], atol=tol, rtol=0)

def test_ndarray(self, hbar, tol):
"""Test numpy.ndarray in the third argument of `reduced_state` is converted to list correctly"""
mu, cov = symplectic.vacuum_state(4, hbar=hbar)
res = symplectic.reduced_state(mu, cov, np.array([0, 1, 2, 3]))
expected = np.zeros([8]), np.identity(8) * hbar / 2

assert np.allclose(res[0], expected[0], atol=tol, rtol=0)
assert np.allclose(res[1], expected[1], atol=tol, rtol=0)


class TestLossChannel:
"""Tests for the loss channel"""
Expand Down
Loading