Skip to content

Conversation

@mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Feb 12, 2025

Context:
This PR is a follow up on #6838 and #6937 to add finite shot execution support to default.qubit.

Description of the Change:

  • Update DefaultQubitInterpreter to handle the ability to update shots based on the specified postselect_mode. The currently supported postselect_modes are "hw-like" and "fill-shots".
  • Update DeferMeasurementsInterpreter to not use aux_wires. This is needed so that we don't need to know ahead of time which wires to use to map MCMs. Instead, now we specify num_wires, which should be an integer for the total number of available wires. When executing, this should be known since the device requires wires to be specified.
    • Because of traceable wires, there might be some sharp bits. Take a look at the following example:
    qml.capture.enable()
    import jax
    
    @qml.capture.expand_plxpr_transforms
    @partial(qml.defer_measurements, num_wires=1)
    def f(n):
        qml.measure(n)
    >>> jax.make_jaxpr(f)(0)
    { lambda ; a:i64[]. let _:AbstractOperator() = CNOT[n_wires=2] a 0 in () }
    The jaxpr is correct, but if I try to execute with n=0, we will expectedly fail because we tried to create a CNOT([0, 0]). This is expected, but would be nice if it could be caught at capture time rather than runtime. I have updated the defer_measurements documentation accordingly. Let me know if there are any other suggestions about how to deal with this.
  • Update DefaultQubitInterpreter to accept ExecutionConfig.

Benefits:

Possible Drawbacks:
Using hw-like postselection currently will not be jit friendly when returning qml.sample, as the number of samples can be less than the original number of samples non-deterministically.

Future Work:

  • Integrate execution with the mcm_method and postselect_mode arguments of QNode.

Related GitHub Issues:

[sc-82064]

@mudit2812 mudit2812 marked this pull request as ready for review February 26, 2025 19:39
@mudit2812
Copy link
Contributor Author

@albi3ro @astralcai I've tentatively opened the PR for review. The testing questions I mentioned in stand-up remain unresolved, and I would love if you're able to provide feedback on that. Thanks!

@codecov
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.60%. Comparing base (cc21b97) to head (e4141ab).
Report is 345 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6961      +/-   ##
==========================================
- Coverage   99.60%   99.60%   -0.01%     
==========================================
  Files         488      488              
  Lines       46638    46659      +21     
==========================================
+ Hits        46455    46474      +19     
- Misses        183      185       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@mudit2812 mudit2812 requested a review from astralcai February 28, 2025 20:58
@mudit2812 mudit2812 enabled auto-merge (squash) March 4, 2025 22:19
@mudit2812 mudit2812 merged commit 3f7f048 into master Mar 4, 2025
46 checks passed
@mudit2812 mudit2812 deleted the dq-defer-measurements-shots branch March 4, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants