amazon-braket / amazon-braket-default-simulator-python

Quantum program simulators that can run locally
https://amazon-braket-default-simulator-python.readthedocs.io/
Apache License 2.0
67 stars 22 forks source link

feat: Track classical register indices for measurements #266

Closed Altanali closed 4 months ago

Altanali commented 4 months ago

Issue #, if available: https://github.com/amazon-braket/amazon-braket-sdk-python/issues/1004

Description of changes: Primarily, instead of discarding the index of a classical register used in an explicit measure assignment (e.g. b[1] = measure q[2];) when building a circuit from OpenQASM using the BDK Interpreter with a ProgramContext instance, the indices are passed into the ProgramContext add_measure method. This change requires all implementations of the ProgramContext class to support a classical_targets parameter in their add_measure method declaration, even if the variable goes unused.

The result of this change addresses the issue attached to this PR, where going to and from Braket circuits and OpenQASM programs will discard classical register indices.

Testing done: Updated test_interpreter.py to verify that classical register indices used in measurements are tracked and stored in order by the default_simulator/circuit/Circuit object when built by the Braket Interpreter,

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

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

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (7e717a2) to head (c559001). Report is 8 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #266 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 48 48 Lines 3763 3793 +30 Branches 919 928 +9 ========================================= + Hits 3763 3793 +30 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.