diff --git a/src/braket/tasks/gate_model_quantum_task_result.py b/src/braket/tasks/gate_model_quantum_task_result.py index 79f6dbc30..d1c06071d 100644 --- a/src/braket/tasks/gate_model_quantum_task_result.py +++ b/src/braket/tasks/gate_model_quantum_task_result.py @@ -134,12 +134,12 @@ def __eq__(self, other) -> bool: return self.task_metadata.id == other.task_metadata.id return NotImplemented - def get_compiled_circuit(self) -> str: + def get_compiled_circuit(self) -> Optional[str]: """ Get the compiled circuit, if one is available. Returns: - str: The compiled circuit or None. + Optional[str]: The compiled circuit or None. """ metadata = self.additional_metadata if not metadata: diff --git a/test/unit_tests/braket/tasks/test_gate_model_quantum_task_result.py b/test/unit_tests/braket/tasks/test_gate_model_quantum_task_result.py index e9a7e7c7c..5915ef7bc 100644 --- a/test/unit_tests/braket/tasks/test_gate_model_quantum_task_result.py +++ b/test/unit_tests/braket/tasks/test_gate_model_quantum_task_result.py @@ -157,7 +157,6 @@ def result_oqc(task_metadata_shots, additional_metadata_oqc): return GateModelQuantumTaskResult.from_object(result) - @pytest.fixture def result_str_1(result_obj_1): return result_obj_1.json() @@ -337,6 +336,13 @@ def test_get_compiled_circuit(result_obj_1): assert result.get_compiled_circuit() == None +def test_get_compiled_circuit_no_metadata(result_obj_1): + """Test that the method does not raise an error if metadata is missing.""" + result = GateModelQuantumTaskResult.from_object(result_obj_1) + result.additional_metadata = None + assert result.get_compiled_circuit() == None + + def test_measurement_counts_from_measurements(): measurements: np.ndarray = np.array( [[1, 0, 1, 0], [0, 0, 0, 0], [1, 0, 1, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 1, 0]]