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

Remove TrotterCircuit cache #1371

Merged
merged 4 commits into from
Jun 25, 2024
Merged

Conversation

stavros11
Copy link
Member

Fixes #1357.

I believe the TrotterCircuit class is implementing a cache of the circuit implementing the Trotter decomposition returned by hamiltonian.circuit(dt) , to avoid recreating it if the users decides to use a different dt. However, this creates a ("secret") link between the circuits returned by hamiltonian.circuit that can confuse users, such as in #1357, and also complicates the code.

If allocating a circuit is not considered very costly, this cache probably does not provide much in terms of performance, therefore I decided to remove it to have cleaner code (and behavior).

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.

Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.84%. Comparing base (ad50a20) to head (784db2c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1371      +/-   ##
==========================================
- Coverage   99.84%   99.84%   -0.01%     
==========================================
  Files          74       74              
  Lines       10806    10788      -18     
==========================================
- Hits        10789    10771      -18     
  Misses         17       17              
Flag Coverage Δ
unittests 99.84% <100.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@alecandido alecandido left a comment

Choose a reason for hiding this comment

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

Thanks, I agree with your analysis, which is confirmed by the test you added.

tests/test_hamiltonians_trotter.py Outdated Show resolved Hide resolved
@marekgluza
Copy link
Contributor

If allocating a circuit is not considered very costly

  • In my applications it was not costly and I was doing deepcopy all the time.

Copy link
Contributor

@marekgluza marekgluza left a comment

Choose a reason for hiding this comment

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

Thank you @stavros11 for this implementation of a solution.

When I was reading the code before I was wondering what was the use of TrotterCircuit and removing it resolves that question too.

@stavros11
Copy link
Member Author

Thank you for reviewing. I updated the test in 784db2c. I will merge after the CI passes.

@MatteoRobbiati MatteoRobbiati added this pull request to the merge queue Jun 25, 2024
Merged via the queue into master with commit e965d89 Jun 25, 2024
27 checks passed
@stavros11 stavros11 deleted the symbolic-hamiltonian-circuit branch June 25, 2024 09:33
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.

Question about SymbolicHamiltonian.circuit
4 participants