-
Notifications
You must be signed in to change notification settings - Fork 117
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
feat: Track classical target indices during measurement. #1008
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… the instruction level instead of only if add_measure is called.
…es implementation
speller26
approved these changes
Jun 26, 2024
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1008 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 135 135
Lines 8949 8948 -1
Branches 2011 2010 -1
=========================================
- Hits 8949 8948 -1 ☔ View full report in Codecov by Sentry. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
#1004
Description of changes:
Update the BraketProgramContext to extend the changes introduced in amazon-braket/amazon-braket-default-simulator-python#266, which provide a classical register index to the BraketProgramContext
add_measure
method when a measurement assignment is used in an OpenQASM program (e.g.b[1] = measure q[1];
). This allows translations to and from Braket BDK Circuits and OpenQASM to be consistent with regards to classical register indices used in measurement assignments as currently, these indices are discarded entirely.Additionally, updating the
_measure_targets
array in theCircuit
object was moved to theadd_instruction
method from the_add_measure
method. This is because users of the Circuit class are able to add measurement instructions via theadd_instruction
method, but_measure_targets
will not be updated to reflect qubits used in the measurement. This results in incorrect behavior when usingto_ir
to take a circuit with measurements added viaadd_instruction
method calls to OpenQASM asto_ir
will check the_measure_targets
variable to see if any qubits are measured, see that the list is empty, and apply a measurement to all the qubits in the circuit, including those already measured via the originaladd_instruction
method calls.Testing done:
A round trip test was added to verify that classical register assignments are persisted when going from BDK Circuit to OpenQASM and back to BDK Circuit via the
to_ir
andfrom_ir
methods; this is similarly checked when going from OpenQASM to BDK Circuit back to OpenQASM.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.