From 2d57c5ff9a1e92e1e4198903f499381eb8b3c52d Mon Sep 17 00:00:00 2001 From: Cody Wang Date: Tue, 3 Sep 2024 16:45:34 -0700 Subject: [PATCH 1/4] change: Return observable target if absent for RT (#1026) --- src/braket/circuits/circuit.py | 4 ++-- src/braket/circuits/observable.py | 12 +++++------- src/braket/circuits/observables.py | 12 ++++++------ src/braket/circuits/result_type.py | 2 +- src/braket/circuits/result_types.py | 8 ++++---- test/unit_tests/braket/circuits/test_result_type.py | 10 ++++++++++ 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/braket/circuits/circuit.py b/src/braket/circuits/circuit.py index 9ce7df7f8..02d419cff 100644 --- a/src/braket/circuits/circuit.py +++ b/src/braket/circuits/circuit.py @@ -319,8 +319,8 @@ def add_result_type( observable = Circuit._extract_observable(result_type_to_add) # We can skip this for now for AdjointGradient (the only subtype of this # type) because AdjointGradient can only be used when `shots=0`, and the - # qubit_observable_mapping is used to generate basis rotation instrunctions - # and make sure the observables are simultaneously commuting for `shots>0` mode. + # qubit_observable_mapping is used to generate basis rotation instructions + # and make sure the observables mutually commute for `shots>0` mode. supports_basis_rotation_instructions = not isinstance( result_type_to_add, ObservableParameterResultType ) diff --git a/src/braket/circuits/observable.py b/src/braket/circuits/observable.py index 11ed02eb6..e0572e3d9 100644 --- a/src/braket/circuits/observable.py +++ b/src/braket/circuits/observable.py @@ -40,20 +40,18 @@ def __init__( self, qubit_count: int, ascii_symbols: Sequence[str], targets: QubitSetInput | None = None ): super().__init__(qubit_count=qubit_count, ascii_symbols=ascii_symbols) - if targets is not None: - targets = QubitSet(targets) + targets = QubitSet(targets) + if targets: if (num_targets := len(targets)) != qubit_count: raise ValueError( f"Length of target {num_targets} does not match qubit count {qubit_count}" ) - self._targets = targets - else: - self._targets = None + self._targets = targets self._coef = 1 def _unscaled(self) -> Observable: return Observable( - qubit_count=self.qubit_count, ascii_symbols=self.ascii_symbols, targets=self.targets + qubit_count=self.qubit_count, ascii_symbols=self.ascii_symbols, targets=self._targets ) def to_ir( @@ -207,7 +205,7 @@ def __sub__(self, other: Observable): def __repr__(self) -> str: return ( f"{self.name}('qubit_count': {self._qubit_count})" - if self._targets is None + if not self._targets else f"{self.name}('qubit_count': {self._qubit_count}, 'target': {self._targets})" ) diff --git a/src/braket/circuits/observables.py b/src/braket/circuits/observables.py index 9346435a2..8249d156f 100644 --- a/src/braket/circuits/observables.py +++ b/src/braket/circuits/observables.py @@ -322,9 +322,9 @@ def __init__(self, observables: list[Observable]): f"{'@'.join([obs.ascii_symbols[0] for obs in unscaled_factors])}" ) all_targets = [factor.targets for factor in unscaled_factors] - if all(targets is None for targets in all_targets): - merged_targets = None - elif all(targets is not None for targets in all_targets): + if not any(all_targets): + merged_targets = QubitSet() + elif all(all_targets): flat_targets = [qubit for target in all_targets for qubit in target] merged_targets = QubitSet(flat_targets) if len(merged_targets) != len(flat_targets): @@ -508,9 +508,9 @@ def __init__(self, observables: list[Observable], display_name: str = "Hamiltoni self._summands = tuple(flattened_observables) qubit_count = max(flattened_observables, key=lambda obs: obs.qubit_count).qubit_count all_targets = [observable.targets for observable in flattened_observables] - if all(targets is None for targets in all_targets): - targets = None - elif all(targets is not None for targets in all_targets): + if not any(all_targets): + targets = QubitSet() + elif all(all_targets): targets = all_targets else: raise ValueError("Cannot mix terms with and without targets") diff --git a/src/braket/circuits/result_type.py b/src/braket/circuits/result_type.py index a7ce2436c..8343429e0 100644 --- a/src/braket/circuits/result_type.py +++ b/src/braket/circuits/result_type.py @@ -243,7 +243,7 @@ def observable(self) -> Observable: @property def target(self) -> QubitSet: - return self._target + return self._target or self._observable.targets @target.setter def target(self, target: QubitSetInput) -> None: diff --git a/src/braket/circuits/result_types.py b/src/braket/circuits/result_types.py index 8af36ab4a..6c1232b06 100644 --- a/src/braket/circuits/result_types.py +++ b/src/braket/circuits/result_types.py @@ -218,7 +218,7 @@ def __init__( def _to_openqasm(self, serialization_properties: OpenQASMSerializationProperties) -> str: observable_ir = self.observable.to_ir( - target=self.target, + target=self._target, ir_type=IRType.OPENQASM, serialization_properties=serialization_properties, ) @@ -477,7 +477,7 @@ def _to_jaqcd(self) -> ir.Expectation: def _to_openqasm(self, serialization_properties: OpenQASMSerializationProperties) -> str: observable_ir = self.observable.to_ir( - target=self.target, + target=self._target, ir_type=IRType.OPENQASM, serialization_properties=serialization_properties, ) @@ -552,7 +552,7 @@ def _to_jaqcd(self) -> ir.Sample: def _to_openqasm(self, serialization_properties: OpenQASMSerializationProperties) -> str: observable_ir = self.observable.to_ir( - target=self.target, + target=self._target, ir_type=IRType.OPENQASM, serialization_properties=serialization_properties, ) @@ -632,7 +632,7 @@ def _to_jaqcd(self) -> ir.Variance: def _to_openqasm(self, serialization_properties: OpenQASMSerializationProperties) -> str: observable_ir = self.observable.to_ir( - target=self.target, + target=self._target, ir_type=IRType.OPENQASM, serialization_properties=serialization_properties, ) diff --git a/test/unit_tests/braket/circuits/test_result_type.py b/test/unit_tests/braket/circuits/test_result_type.py index bc7cc0909..bb543b7c0 100644 --- a/test/unit_tests/braket/circuits/test_result_type.py +++ b/test/unit_tests/braket/circuits/test_result_type.py @@ -18,6 +18,7 @@ from braket.circuits.free_parameter import FreeParameter from braket.circuits.result_type import ObservableParameterResultType from braket.circuits.serialization import IRType +from braket.registers import QubitSet @pytest.fixture @@ -168,6 +169,15 @@ def test_obs_rt_repr(): ) +def test_obs_rt_target(): + assert ObservableResultType( + ascii_symbols=["Obs"], observable=Observable.X(), target=1 + ).target == QubitSet(1) + assert ObservableResultType( + ascii_symbols=["Obs"], observable=Observable.X(1) + ).target == QubitSet(1) + + @pytest.mark.parametrize( "ir_type, serialization_properties, expected_exception, expected_message", [ From 1f6bf0fc83040da58dae1f242a29fc9acf92ab61 Mon Sep 17 00:00:00 2001 From: Cody Wang Date: Wed, 4 Sep 2024 14:45:52 -0700 Subject: [PATCH 2/4] deprecation: Retire IonQ Harmony (#1030) --- src/braket/devices/devices.py | 2 +- test/integ_tests/test_device_creation.py | 2 +- test/integ_tests/test_measure.py | 2 +- test/integ_tests/test_reservation_arn.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/braket/devices/devices.py b/src/braket/devices/devices.py index ff2529234..0af058d42 100644 --- a/src/braket/devices/devices.py +++ b/src/braket/devices/devices.py @@ -31,7 +31,7 @@ class _IQM(str, Enum): Garnet = "arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet" class _IonQ(str, Enum): - Harmony = "arn:aws:braket:us-east-1::device/qpu/ionq/Harmony" + _Harmony = "arn:aws:braket:us-east-1::device/qpu/ionq/Harmony" Aria1 = "arn:aws:braket:us-east-1::device/qpu/ionq/Aria-1" Aria2 = "arn:aws:braket:us-east-1::device/qpu/ionq/Aria-2" Forte1 = "arn:aws:braket:us-east-1::device/qpu/ionq/Forte-1" diff --git a/test/integ_tests/test_device_creation.py b/test/integ_tests/test_device_creation.py index c7183c3e6..2b718c211 100644 --- a/test/integ_tests/test_device_creation.py +++ b/test/integ_tests/test_device_creation.py @@ -18,7 +18,7 @@ from braket.devices import Devices RIGETTI_ARN = "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3" -IONQ_ARN = "arn:aws:braket:us-east-1::device/qpu/ionq/Harmony" +IONQ_ARN = "arn:aws:braket:us-east-1::device/qpu/ionq/Aria-1" IQM_ARN = "arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet" SIMULATOR_ARN = "arn:aws:braket:::device/quantum-simulator/amazon/sv1" PULSE_ARN = "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3" diff --git a/test/integ_tests/test_measure.py b/test/integ_tests/test_measure.py index 9c8fdc02c..8fd72e6bf 100644 --- a/test/integ_tests/test_measure.py +++ b/test/integ_tests/test_measure.py @@ -23,7 +23,7 @@ DEVICE = LocalSimulator() SHOTS = 8000 -IONQ_ARN = "arn:aws:braket:us-east-1::device/qpu/ionq/Harmony" +IONQ_ARN = "arn:aws:braket:us-east-1::device/qpu/ionq/Aria-1" SIMULATOR_ARN = "arn:aws:braket:::device/quantum-simulator/amazon/sv1" IQM_ARN = "arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet" diff --git a/test/integ_tests/test_reservation_arn.py b/test/integ_tests/test_reservation_arn.py index 64135f76e..57833a840 100644 --- a/test/integ_tests/test_reservation_arn.py +++ b/test/integ_tests/test_reservation_arn.py @@ -33,7 +33,7 @@ def reservation_arn(aws_session): def test_create_task_via_invalid_reservation_arn_on_qpu(reservation_arn): circuit = Circuit().h(0) - device = AwsDevice(Devices.IonQ.Harmony) + device = AwsDevice(Devices.IonQ.Aria1) with pytest.raises(ClientError, match="Reservation arn is invalid"): device.run(circuit, shots=10, reservation_arn=reservation_arn) From 6236d632560c87cd19f5bda511c5035f07601c05 Mon Sep 17 00:00:00 2001 From: ci Date: Thu, 5 Sep 2024 18:38:00 +0000 Subject: [PATCH 3/4] prepare release v1.87.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 3fc1c64ef..18bde840f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## v1.87.0 (2024-09-05) + +### Deprecations and Removals + + * Retire IonQ Harmony + +### Bug Fixes and Other Changes + + * Return observable target if absent for RT + ## v1.86.1 (2024-08-29) ### Bug Fixes and Other Changes diff --git a/src/braket/_sdk/_version.py b/src/braket/_sdk/_version.py index a660f1729..7f61b52dd 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.86.2.dev0" +__version__ = "1.87.0" From 42d0ef8fc275b0dfbb560ac573846192a20e1587 Mon Sep 17 00:00:00 2001 From: ci Date: Thu, 5 Sep 2024 18:38:00 +0000 Subject: [PATCH 4/4] update development version to v1.87.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 7f61b52dd..2deedb28a 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.87.0" +__version__ = "1.87.1.dev0"