From 234ab0a56962ffb1694715672436f68f5750f4ac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:44:16 -0700 Subject: [PATCH 1/5] infra: bump codecov/codecov-action from 4.2.0 to 4.5.0 (#1011) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index dbd4d1faf..9d398f23d 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -36,7 +36,7 @@ jobs: run: | tox -e unit-tests - name: Upload coverage report to Codecov - uses: codecov/codecov-action@7afa10ed9b269c561c2336fd862446844e0cbf71 # v4.2.0 + uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: token: ${{ secrets.CODECOV_TOKEN }} if: ${{ strategy.job-index }} == 0 From 785d2512535af9606fd66eedd4476984c7b41a8b Mon Sep 17 00:00:00 2001 From: Altanali Date: Wed, 26 Jun 2024 13:53:16 -0700 Subject: [PATCH 2/5] feat: Track classical target indices for measurements (#1008) --- src/braket/circuits/braket_program_context.py | 14 ++++++++------ src/braket/circuits/circuit.py | 9 +++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/braket/circuits/braket_program_context.py b/src/braket/circuits/braket_program_context.py index 4371637d3..558692510 100644 --- a/src/braket/circuits/braket_program_context.py +++ b/src/braket/circuits/braket_program_context.py @@ -11,6 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +from collections.abc import Iterable from typing import Optional, Union import numpy as np @@ -161,16 +162,17 @@ def handle_parameter_value( return FreeParameterExpression(evaluated_value) return value - def add_measure(self, target: tuple[int]) -> None: + def add_measure( + self, target: tuple[int], classical_targets: Optional[Iterable[int]] = None + ) -> None: """Add a measure instruction to the circuit Args: target (tuple[int]): the target qubits to be measured. + classical_targets (Optional[Iterable[int]]): the classical registers + to use in the qubit measurement. """ - for index, qubit in enumerate(target): + for iter, qubit in enumerate(target): + index = classical_targets[iter] if classical_targets else iter instruction = Instruction(Measure(index=index), qubit) self._circuit.add_instruction(instruction) - if self._circuit._measure_targets: - self._circuit._measure_targets.append(qubit) - else: - self._circuit._measure_targets = [qubit] diff --git a/src/braket/circuits/circuit.py b/src/braket/circuits/circuit.py index f15e03647..9ce7df7f8 100644 --- a/src/braket/circuits/circuit.py +++ b/src/braket/circuits/circuit.py @@ -504,6 +504,11 @@ def add_instruction( # Check if there is a measure instruction on the circuit self._check_if_qubit_measured(instruction, target, target_mapping) + # Update measure targets if instruction is a measurement + if isinstance(instruction.operator, Measure): + measure_target = target or instruction.target[0] + self._measure_targets = (self._measure_targets or []) + [measure_target] + if not target_mapping and not target: # Nothing has been supplied, add instruction instructions_to_add = [instruction] @@ -710,10 +715,6 @@ def _add_measure(self, target_qubits: QubitSetInput) -> None: target=target, ) ) - if self._measure_targets: - self._measure_targets.append(target) - else: - self._measure_targets = [target] def measure(self, target_qubits: QubitSetInput) -> Circuit: """ From eeb7630e5b876b9cb1c3c7a856b66dc0c2c2e4ec Mon Sep 17 00:00:00 2001 From: Altanali Date: Wed, 26 Jun 2024 16:47:54 -0700 Subject: [PATCH 3/5] change: Add test to check classical indices used in measurement are preserved between Circuit and OpenQASM Translations. (#1013) --- setup.py | 2 +- .../braket/circuits/test_circuit.py | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 43d2c52ad..54987c283 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ package_dir={"": "src"}, install_requires=[ "amazon-braket-schemas>=1.21.3", - "amazon-braket-default-simulator>=1.21.4", + "amazon-braket-default-simulator>=1.25.0", "oqpy~=0.3.5", "backoff", "boltons", diff --git a/test/unit_tests/braket/circuits/test_circuit.py b/test/unit_tests/braket/circuits/test_circuit.py index 71eecd1f1..897828b27 100644 --- a/test/unit_tests/braket/circuits/test_circuit.py +++ b/test/unit_tests/braket/circuits/test_circuit.py @@ -3610,3 +3610,32 @@ def test_circuit_with_global_phase(): "b[0] = measure $0;", ] ) + + +def test_from_ir_round_trip_transformation_with_targeted_measurements(): + circuit = ( + Circuit() + .h(0) + .cnot(0, 1) + .add_instruction(Instruction(Measure(index=2), 1)) + .add_instruction(Instruction(Measure(index=1), 2)) + .add_instruction(Instruction(Measure(index=0), 0)) + ) + ir = OpenQasmProgram( + source="\n".join( + [ + "OPENQASM 3.0;", + "bit[3] b;", + "qubit[3] q;", + "h q[0];", + "cnot q[0], q[1];", + "b[2] = measure q[1];", + "b[1] = measure q[2];", + "b[0] = measure q[0];", + ] + ), + inputs={}, + ) + + assert Circuit.from_ir(ir) == Circuit.from_ir(circuit.to_ir("OPENQASM")) + assert circuit.to_ir("OPENQASM") == Circuit.from_ir(ir).to_ir("OPENQASM") From 6cd842e081300369583974e54caa6509cf3eb90a Mon Sep 17 00:00:00 2001 From: ci Date: Thu, 27 Jun 2024 00:03:09 +0000 Subject: [PATCH 4/5] prepare release v1.82.0 --- CHANGELOG.md | 10 ++++++++++ src/braket/_sdk/_version.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82e97333d..f6716703f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## v1.82.0 (2024-06-27) + +### Features + + * Track classical target indices for measurements + +### Bug Fixes and Other Changes + + * Add test to check classical indices used in measurement are preserved between Circuit and OpenQASM Translations. + ## v1.81.1 (2024-06-17) ### Bug Fixes and Other Changes diff --git a/src/braket/_sdk/_version.py b/src/braket/_sdk/_version.py index 50ee98c7c..1ce2d2394 100644 --- a/src/braket/_sdk/_version.py +++ b/src/braket/_sdk/_version.py @@ -15,4 +15,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "1.81.2.dev0" +__version__ = "1.82.0" From 239fc81f1dcb7bc298fceca73babdef12281d969 Mon Sep 17 00:00:00 2001 From: ci Date: Thu, 27 Jun 2024 00:03:09 +0000 Subject: [PATCH 5/5] update development version to v1.82.1.dev0 --- src/braket/_sdk/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/braket/_sdk/_version.py b/src/braket/_sdk/_version.py index 1ce2d2394..4d28af096 100644 --- a/src/braket/_sdk/_version.py +++ b/src/braket/_sdk/_version.py @@ -15,4 +15,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "1.82.0" +__version__ = "1.82.1.dev0"