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 greedy recursion #537

Merged
merged 30 commits into from
Apr 12, 2024
Merged

Remove greedy recursion #537

merged 30 commits into from
Apr 12, 2024

Conversation

ibrahim-shehzad
Copy link
Collaborator

This PR aims to resolve #536, by getting rid of recursion inside the greedy_best_first_search algorithm that is used to warm start the search performed by the cut-finder. I have replaced recursion with a simple while loop and have verified that the issues reported to us for large QAOA circuits (which led to #536) are now avoided. Since these circuits have large widths, the algorithm takes a while to finish running and any direct tests on these circuits would significantly slow down the overall testing process. This is why I have not added any new tests at this stage.

ibrahim-shehzad and others added 25 commits April 2, 2024 09:51
Co-authored-by: Jim Garrison <[email protected]>
Co-authored-by: Jim Garrison <[email protected]>
Otherwise, a deprecation warning will show any time the tests are run
Otherwise we see the following when we run tests
```
circuit_knitting/utils/metrics.py::circuit_knitting.utils.metrics.cross_entropy
  <doctest circuit_knitting.utils.metrics.cross_entropy[0]>:1: DeprecationWarning: The function ``circuit_knitting.utils.metrics.cross_entropy()`` is deprecated as of circuit-knitting-toolbox 0.7.0. It will be removed Circuit knitting toolbox 0.8.0 release.

circuit_knitting/utils/metrics.py::circuit_knitting.utils.metrics.MSE
  <doctest circuit_knitting.utils.metrics.MSE[0]>:1: DeprecationWarning: The function ``circuit_knitting.utils.metrics.MSE()`` is deprecated as of circuit-knitting-toolbox 0.7.0. It will be removed Circuit knitting toolbox 0.8.0 release.

circuit_knitting/utils/metrics.py::circuit_knitting.utils.metrics.MAPE
  <doctest circuit_knitting.utils.metrics.MAPE[0]>:1: DeprecationWarning: The function ``circuit_knitting.utils.metrics.MAPE()`` is deprecated as of circuit-knitting-toolbox 0.7.0. It will be removed Circuit knitting toolbox 0.8.0 release.

circuit_knitting/utils/metrics.py::circuit_knitting.utils.metrics.chi2_distance
  <doctest circuit_knitting.utils.metrics.chi2_distance[0]>:1: DeprecationWarning: The function ``circuit_knitting.utils.metrics.chi2_distance()`` is deprecated as of circuit-knitting-toolbox 0.7.0. It will be removed Circuit knitting toolbox 0.8.0 release.

circuit_knitting/utils/metrics.py::circuit_knitting.utils.metrics.chi2_distance
  <doctest circuit_knitting.utils.metrics.chi2_distance[1]>:1: DeprecationWarning: The function ``circuit_knitting.utils.metrics.chi2_distance()`` is deprecated as of circuit-knitting-toolbox 0.7.0. It will be removed Circuit knitting toolbox 0.8.0 release.

circuit_knitting/utils/metrics.py::circuit_knitting.utils.metrics.HOP
  <doctest circuit_knitting.utils.metrics.HOP[0]>:1: DeprecationWarning: The function ``circuit_knitting.utils.metrics.HOP()`` is deprecated as of circuit-knitting-toolbox 0.7.0. It will be removed Circuit knitting toolbox 0.8.0 release.
```
Otherwise, we will see a deprecation warning
@ibrahim-shehzad ibrahim-shehzad added the cut finder Related to the automatic cut finder label Apr 8, 2024
@ibrahim-shehzad ibrahim-shehzad self-assigned this Apr 8, 2024
@coveralls
Copy link

coveralls commented Apr 8, 2024

Pull Request Test Coverage Report for Build 8656075716

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.433%

Totals Coverage Status
Change from base Build 8560627750: 0.0%
Covered Lines: 3448
Relevant Lines: 3613

💛 - Coveralls

@ibrahim-shehzad
Copy link
Collaborator Author

ibrahim-shehzad commented Apr 8, 2024

With pieces of older git history showing up above, it looks like I may have (accidentally) created this branch locally from the deprecate-cutqc branch, instead of from main. Let me know if this is a problem and I should undo this and start over.

@caleb-johnson
Copy link
Collaborator

With pieces of older git history showing up above, it looks like I may have (accidentally) created this branch locally from the deprecate-cutqc branch, instead of from main. Let me know if this is a problem and I should undo this and start over.

@ibrahim-shehzad This can happen if you have commits from a feature branch and then those commits are squashed when that branch is merged. Git doesnt know what to do so it keeps things in the diff that are not actual changes. I think you can just checkout the main versions of these files and then commit and push those files and it'll update the diff

@ibrahim-shehzad ibrahim-shehzad added the bug Something isn't working label Apr 8, 2024
@caleb-johnson
Copy link
Collaborator

This looks nice, and it appears to implement the same logic. If you could just say something about what the conditions are when this loop should end, I'd like to consider if there are cases which could cause this to run forever.

@ibrahim-shehzad ibrahim-shehzad requested a review from garrison April 9, 2024 13:45
else:
# avoid using recursion to stay clear of any risk of stack overflow.
state = best[-1]
continue
Copy link
Collaborator

@caleb-johnson caleb-johnson Apr 9, 2024

Choose a reason for hiding this comment

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

If you don't take my suggestion above, I think we can remove this continue anyway. I don't think it does anything. The while loop will evaluate its condition next regardless of whether this is here.

@garrison garrison added this to the 0.7.0 milestone Apr 9, 2024
Copy link
Collaborator

@caleb-johnson caleb-johnson left a comment

Choose a reason for hiding this comment

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

This looks good to me. A couple of small style suggestions, but it's fine to merge as-is IMO. Thanks!

@ibrahim-shehzad ibrahim-shehzad merged commit 4ab172a into main Apr 12, 2024
11 checks passed
@ibrahim-shehzad ibrahim-shehzad deleted the remove-greedy-recursion branch April 12, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cut finder Related to the automatic cut finder
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Max recursion limit exceeded when running cut-finder on deep circuits
4 participants