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

Fix scalar mutliplication of SymbolicTerm #474

Merged
merged 8 commits into from
Sep 27, 2021
Merged

Fix scalar mutliplication of SymbolicTerm #474

merged 8 commits into from
Sep 27, 2021

Conversation

stavros11
Copy link
Member

Fixes #470, the fix was very simple and is in the first commit only. In the rest I am adding some unit tests that focus on the core/terms.py file and improving the related docstrings and comments to help in the future, because as it is now it was quite hard to debug this issue.

@stavros11 stavros11 added the bug Something isn't working label Sep 22, 2021
@codecov
Copy link

codecov bot commented Sep 22, 2021

Codecov Report

Merging #474 (2151075) into master (fc1eb31) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            master      #474    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           84        85     +1     
  Lines        11770     11905   +135     
==========================================
+ Hits         11770     11905   +135     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/qibo/core/hamiltonians.py 100.00% <100.00%> (ø)
src/qibo/core/terms.py 100.00% <100.00%> (ø)
src/qibo/tests/test_core_terms.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 fc1eb31...2151075. Read the comment docs.

@stavros11
Copy link
Member Author

I simplified a little bit the qibo.core.terms.SymbolicTerm consturctor and added a new test file for the code in terms.py. I believe this should be good for review. The notebook that discovered this bug works for me now, but it would be good if someone else could confirm this too before merging.

@stavros11 stavros11 marked this pull request as ready for review September 26, 2021 11:30
matrix_map (dict): Dictionary that maps target qubit ids to a list of
matrices that act on each qubit.
"""
"""Helper constructor using the ``sympy`` expression directly.
Copy link
Member

Choose a reason for hiding this comment

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

I think there is something wrong with this comment, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, thanks. I was going to update the docstring after removing the .from_factors constructor for simplification but I forgot to complete the update. It should be ok now.

src/qibo/core/terms.py Outdated Show resolved Hide resolved

if isinstance(factor, sympy.Symbol):
if isinstance(factor.matrix, K.qnp.tensor_types):
self.factors.extend(pow * [factor])
Copy link
Member

Choose a reason for hiding this comment

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

Given that the comments are quite good, please some sentence explaining how and why the pow term is applied to the matrix_map.

Copy link
Member

@scarrazza scarrazza left a comment

Choose a reason for hiding this comment

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

Thanks for this implementation. Works for me, seems to fix the non convergence observed in the notebooks. Please a look at my minor comments.

@stavros11
Copy link
Member Author

Thanks for this implementation. Works for me, seems to fix the non convergence observed in the notebooks. Please a look at my minor comments.

Thank you for the review. I update the comments for the above points, let me know if it is ok.

Copy link
Member

@scarrazza scarrazza left a comment

Choose a reason for hiding this comment

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

Looks good, thank you.

@scarrazza scarrazza merged commit 7338ce7 into master Sep 27, 2021
@scarrazza scarrazza deleted the fixtrotter branch October 5, 2021 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trotter evolution and dense evolution does not match
2 participants