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

Tree-traversal iterative design & analytic-mode #5868

Merged
merged 249 commits into from
Aug 21, 2024
Merged

Conversation

vincentmr
Copy link
Contributor

@vincentmr vincentmr commented Jun 17, 2024

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.

  • Add a new entry to the doc/releases/changelog-dev.md file, summarizing the
    change, and including a link back to the PR.

  • The PennyLane source code conforms to
    PEP8 standards.
    We check all of our code against Pylint.
    To lint modified files, simply pip install pylint, and then
    run pylint pennylane/path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context:
The tree-traversal algorithm was first implemented using a recursive approach for simplicity, but this potentially requires very deep stack calls for circuits with a lot of MCMs. Tree-traversal could also support analytic execution, optionally with a probability cutoff to ignore branches.

Description of the Change:
Implement tree-traversal using an iterative approach.
Support shots=None.
Some profiling and optimization.

Benefits:
Remove system call increasing the default recursion call limit.

Possible Drawbacks:

Related GitHub Issues:
[sc-65241]

vincentmr and others added 30 commits January 19, 2024 13:10
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
@trbromley trbromley removed their request for review August 15, 2024 13:43
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Looks pretty good! Just some final comments for the implementation.

The only other thing that comes to mind is testing. There's an ongoing effort right now to rework mid-circuit measurement tests, with @obliviateandsurrender and @astralcai leading the work. They might be able to provide more context, but it might be worth adding unit tests in favour of the integration tests in test_default_qubit_native_mcm.py.

pennylane/measurements/mid_measure.py Outdated Show resolved Hide resolved
pennylane/devices/qubit/simulate.py Outdated Show resolved Hide resolved
pennylane/devices/qubit/simulate.py Outdated Show resolved Hide resolved
pennylane/devices/qubit/simulate.py Outdated Show resolved Hide resolved
@vincentmr vincentmr requested review from mudit2812 and albi3ro August 19, 2024 13:48
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Nice! Looks good to me. Very excited to get this in 🎉 . I'm approving as the only missing piece of the puzzle is test coverage, which will block merging anyway.

pennylane/devices/qubit/simulate.py Outdated Show resolved Hide resolved
vincentmr and others added 2 commits August 20, 2024 10:37
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

👍 Sorry about the delays in reviews. In an ideal world, we'd find a way to reduce the overall complexity of the simulate_tree_mcm function, but not sure its the time and effort that would be involved.

Other than that, impressive work :)

@vincentmr vincentmr enabled auto-merge (squash) August 20, 2024 20:58
@mudit2812 mudit2812 added this to the v0.38 milestone Aug 21, 2024
@vincentmr vincentmr merged commit 6ca9ce9 into master Aug 21, 2024
39 of 40 checks passed
@vincentmr vincentmr deleted the feature/tt_stack branch August 21, 2024 16:16
mudit2812 added a commit that referenced this pull request Sep 10, 2024
### Before submitting

Please complete the following checklist when submitting a PR:

- [x] 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!

- [x] 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`.

- [x] Ensure that the test suite passes, by running `make test`.

- [x] Add a new entry to the `doc/releases/changelog-dev.md` file,
summarizing the
      change, and including a link back to the PR.

- [x] The PennyLane source code conforms to
      [PEP8 standards](https://www.python.org/dev/peps/pep-0008/).
We check all of our code against [Pylint](https://www.pylint.org/).
      To lint modified files, simply `pip install pylint`, and then
      run `pylint pennylane/path/to/file.py`.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**
The tree-traversal algorithm was first implemented using a recursive
approach for simplicity, but this potentially requires very deep stack
calls for circuits with a lot of MCMs. Tree-traversal could also support
analytic execution, optionally with a probability cutoff to ignore
branches.

**Description of the Change:**
Implement tree-traversal using an iterative approach.
Support `shots=None`.
Some profiling and optimization.

**Benefits:**
Remove system call increasing the default recursion call limit.

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-65241]

---------

Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
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.

3 participants