Skip to content

fix: classical shadow with program set#316

Open
yitchen-tim wants to merge 6 commits intomainfrom
yitchen/shadow
Open

fix: classical shadow with program set#316
yitchen-tim wants to merge 6 commits intomainfrom
yitchen/shadow

Conversation

@yitchen-tim
Copy link
Contributor

@yitchen-tim yitchen-tim commented Nov 14, 2025

Issue #, if available:
closes #313

Description of changes:
This PR fixes support for classical shadow in the Braket PennyLane plugin.

  • When classical shadow is called, the quantum tape goes to batch_execute() instead of execute(). Add handling for ClassicalShadowMP measurements in batch_execute().
  • Add maximumExecutables as a threshold add check in _run_snapshots() to only use program sets when snapshot count is below the threshold.

Testing done:
tox

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7fdee25) to head (ff93291).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #316   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines         1245      1253    +8     
  Branches       180       182    +2     
=========================================
+ Hits          1245      1253    +8     

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

@yitchen-tim yitchen-tim marked this pull request as ready for review November 14, 2025 15:04
@yitchen-tim yitchen-tim requested a review from a team as a code owner November 14, 2025 15:04
@yitchen-tim yitchen-tim reopened this Nov 14, 2025
speller26
speller26 previously approved these changes Nov 14, 2025
@yitchen-tim
Copy link
Contributor Author

thanks @speller26 I've updated the PR


def _can_run_as_program_set(self, n_executables: int) -> bool:
"""Whether a list of executables can be run as a program set"""
return self._supports_program_sets and n_executables < self._max_program_set_executables

Choose a reason for hiding this comment

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

why is this additional condition necessary now?

Copy link
Member

Choose a reason for hiding this comment

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

This just allows us to reuse the logic that used to be on line 212

"A circuit with a ClassicalShadowMP observable must "
"have that as its only return type."
)
if len(circuits) > 1:

Choose a reason for hiding this comment

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

This should be first condition in the loop to ensure early return


@patch.object(AwsDevice, "run")
def test_batch_execute_program_set_exceeds_max_executables(mock_run):
@patch.object(AwsDevice, "run_batch")

Choose a reason for hiding this comment

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

was this previously a bug?

@speller26 speller26 self-requested a review December 2, 2025 21:21
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.

Error in classical_shadow as return type when using program sets on QPU

3 participants