From f30379c4104cea6010d97d04e00dfb24c33e1504 Mon Sep 17 00:00:00 2001 From: Nagji Date: Tue, 30 Jul 2024 14:56:04 -0700 Subject: [PATCH] fix: Fix Emulator raising a new Exception instance from the original exception raised by an EmulatorPass in order to modify the message with the Emulator name. --- src/braket/emulation/emulator.py | 2 +- test/unit_tests/braket/aws/test_aws_emulation.py | 2 +- test/unit_tests/braket/emulation/test_emulator.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/braket/emulation/emulator.py b/src/braket/emulation/emulator.py index 18dfe723f..51cc8e93b 100644 --- a/src/braket/emulation/emulator.py +++ b/src/braket/emulation/emulator.py @@ -186,4 +186,4 @@ def _raise_exception(self, exception: Exception) -> None: Args: exception (Exception): The exception to modify and raise. """ - raise type(exception)(str(exception) + f" ({self._name})") + raise Exception(str(exception) + f" ({self._name})") from exception diff --git a/test/unit_tests/braket/aws/test_aws_emulation.py b/test/unit_tests/braket/aws/test_aws_emulation.py index 6d0728326..53d5ae53a 100644 --- a/test/unit_tests/braket/aws/test_aws_emulation.py +++ b/test/unit_tests/braket/aws/test_aws_emulation.py @@ -693,7 +693,7 @@ def test_emulator_passes(circuit, is_valid, rigetti_device): rigetti_device.validate(circuit) assert rigetti_device.run_passes(circuit, apply_noise_model=False) == circuit else: - with pytest.raises(ValueError): + with pytest.raises(Exception): rigetti_device.validate(circuit) diff --git a/test/unit_tests/braket/emulation/test_emulator.py b/test/unit_tests/braket/emulation/test_emulator.py index 84ac902bb..8fe68b2c2 100644 --- a/test/unit_tests/braket/emulation/test_emulator.py +++ b/test/unit_tests/braket/emulation/test_emulator.py @@ -64,7 +64,7 @@ def test_basic_invalidate(basic_emulator): f"Circuit must use at most 4 qubits, \ but uses {circuit.qubit_count} qubits. (DeviceEmulator)" ) - with pytest.raises(ValueError, match=match_string): + with pytest.raises(Exception, match=match_string): basic_emulator.run_passes(circuit) @@ -124,7 +124,7 @@ def test_validation_only_pass(setup_local_simulator_devices): f"Circuit must use at most 4 qubits, \ but uses {circuit.qubit_count} qubits. (DeviceEmulator)" ) - with pytest.raises(ValueError, match=match_string): + with pytest.raises(Exception, match=match_string): emulator.validate(circuit)