qiboteam / qibo

A full-stack framework for quantum computing.
https://qibo.science
Apache License 2.0
294 stars 60 forks source link

Remove `TrotterCircuit` cache #1371

Closed stavros11 closed 4 months ago

stavros11 commented 4 months ago

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:

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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](https://app.codecov.io/gh/qiboteam/qibo/pull/1371/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/qiboteam/qibo/pull/1371/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | `99.84% <100.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

marekgluza commented 4 months ago

If allocating a circuit is not considered very costly

stavros11 commented 4 months ago

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