-
Notifications
You must be signed in to change notification settings - Fork 195
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
Update decomposition function #751
base: master
Are you sure you want to change the base?
Conversation
…ocalV), t_list. and added the If BS1 not None: to the interferometer_decompose method to match the decomposition with the interferometer function. I also changed the return in tests/frontend/test_decompositions.py for the triaungular decomposition to the new convention. Furthermore, I added a rudimental test for the triangular interferometer in test_interferometer_triangular.
Hi @jama7168, Thanks again for opening this PR. A member of our team is currently reviewing it. We should get back to you soon with next steps. Have a good weekend! |
# extract the joint Fock probabilities | ||
probs_rect = results.state.all_fock_probs() | ||
#all probabilities should be the same here! Sp the output should be True | ||
print(f"{np.allclose(probs_triangular, probs_rect)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be an assert statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right there. I copied the code from my local test where i just printed out the results to check if it works. I replaced it with an assert statement and made the test itself a bit more stable and added that one can change the size of the test matrix. I hope this fixes the problem with the test. As I am very new to this, I tried to run make docs and make test on my local machine but I ran into some troubles setting it up correctly. I still hope that this resolves the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jacob for opening the PR! Could you follow up on the errors that are raised in the tests? I also left a comment. Thanks again!
Before submitting
Please complete the following checklist when submitting a PR:
All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to the
test directory!
All new functions and code must be clearly commented and documented.
If you do make documentation changes, make sure that the docs build and
render correctly by running
make docs
.Ensure that the test suite passes, by running
make test
.Ensure that code and tests are properly formatted, by running
make format
orblack -l 100 <filename>
on any relevant files. You will need to have the Black code format installed:pip install black
.Add a new entry to the
.github/CHANGELOG.md
file, summarizing thechange, and including a link back to the PR.
The Strawberry Fields source code conforms to
PEP8 standards.
We check all of our code against Pylint.
To lint modified files, simply
pip install pylint
, and thenrun
pylint strawberryfields/path/to/file.py
.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Context:
During testing the interferometer Class I came across the problem that Interferometer(unitary_matrix, mesh = 'triangular', tol = 1e-10) and Interferometer(unitary_matrix, mesh = 'rectangular_phase_end', tol = 1e-10) give different results when applied within the boson sampling. As the matrix we are starting with is the same that should not be (see also here: https://discuss.pennylane.ai/t/problems-in-understanding-sf-decompositions-triangular/7875/6 for more details and the discussion).
Description of the Change:
I changed the following things:
the order of the return in the triangular decomposition from reversed(tlist), np,diag(localV), None to None, np,diag(localV), t_list so that in the Interferometer_decomposition function the order of application is first the diagonal (phase shifters) and then the T_i[0] to T_i[N].
Then I changed the interferometer_decompose method such that it checks if the BS1 from the Decomposition is None.
I also provided the minimal example as a test with which i tested the interferometer class. Now the results for both are the same as it should be.
Benefits:
Fixed a problem with the triangular decomposition in the Interferometer.
Possible Drawbacks:
Since I changed the return of the triangular decomposition it might affect other functions. Maybe we should check that first!!
Related GitHub Issues:
Not a gitub Issue but here the form discussion I had:
https://discuss.pennylane.ai/t/problems-in-understanding-sf-decompositions-triangular/7875/6