amazon-braket / amazon-braket-sdk-python

A Python SDK for interacting with quantum devices on Amazon Braket
https://aws.amazon.com/braket/
Apache License 2.0
294 stars 118 forks source link

fix: Support single-register measurements in `from_ir` #934

Closed ashlhans closed 3 months ago

ashlhans commented 3 months ago

Issue #, if available: Currently, the statement b = measure q in an OpenQASM program results in the following error:

ValueError: Operator qubit count 1 must be equal to size of target qubit set QubitSet([Qubit(0), Qubit(1)])

This is because a measure instruction is always a 1 qubit instruction but right now, all the targets get added to the measure instruction even if there are more than 1 qubit measured.

To reproduce this issue:

bell_qasm = """
OPENQASM 3;

qubit[2] q;
bit[2] c;

h q[0];
cnot q[0], q[1];

c = measure q;
"""

from braket.circuits import Circuit
print(Circuit.from_ir(bell_qasm))

Description of changes:

Testing done: tox and tox -e integ-tests

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 3 months ago

Codecov Report

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

Project coverage is 100.00%. Comparing base (c57a9ba) to head (48bd56a).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #934 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 133 133 Lines 8905 8906 +1 Branches 2006 2007 +1 ========================================= + Hits 8905 8906 +1 ```

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