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

Native mid-circuit measurements support composite measurements, etc. (phase 2) #5120

Merged
merged 145 commits into from
Feb 16, 2024

Conversation

vincentmr
Copy link
Contributor

@vincentmr vincentmr commented Jan 29, 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:
This PR is a follow-up on #5088 .

Epic 50811 states:

  • The deferred measurement principle is not used
  • Each shot is a new exploration of the tree of possible mid-circuit measurement results
  • The mid-circuit measurement results are correctly exposed to PennyLane's frontend
  • Compatible with qubit reuse
  • Compatible with qubit reset
  • Compatible with qubit postselection
  • Compatible with existing support for conditioning in PennyLane
    • Addition, subtraction and multiplication of one or more mid-circuit measurement results

The current PR tackles the requirements above as indicated by the task list.

Description of the Change:

  • apply_mid_measure handles post-selection returning a zero state and sample when the state isn't properly normalized (which happens when the state cannot be normalized).
  • The concretize method is added to MeasurementValue object to obtain a concrete value from a dictionary of measurement values. This allows handling composite measurements. Other modules like simulate are simplified accordingly.
  • Post-selected-zero-state samples are thrown away at the simulate level, handling this exception. This means the final number of samples is lower or equal to the total number of shots.
  • Tests for all introduced features.

Benefits:
Mid-circuit measurements are natively supported.

Possible Drawbacks:
Slower in several cases (e.g. when few MCMs).

Missing features:
To do in follow-up PRs:

  • parameter-shift support
  • optimisation

Related GitHub Issues:
[sc-54987]
[sc-55666]
[sc-55667]
[sc-55668]
[sc-55922]

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>
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.

Thanks @vincentmr ! This looks good to me. Very excited to get this in. I'm still a bit worried about the core test runners, but everyone seems okay with it so let's do it

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

one last concern, then I'd say this is good to go!

pennylane/devices/qubit/simulate.py Show resolved Hide resolved
@vincentmr vincentmr enabled auto-merge (squash) February 16, 2024 19:13
@vincentmr vincentmr merged commit 5442f59 into master Feb 16, 2024
37 of 38 checks passed
@vincentmr vincentmr deleted the feature/mcm_composite branch February 16, 2024 19:35
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.

7 participants