Skip to content

Commit

Permalink
fix: Fix Emulator raising a new Exception instance from the original …
Browse files Browse the repository at this point in the history
…exception raised by an EmulatorPass in order to modify the message with the Emulator name.
  • Loading branch information
ltnln committed Jul 30, 2024
1 parent 96e917a commit f30379c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/braket/emulation/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/unit_tests/braket/aws/test_aws_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions test/unit_tests/braket/emulation/test_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit f30379c

Please sign in to comment.