diff --git a/src/qc_compiler/utils.py b/src/qc_compiler/utils.py index 2c1776d..98f525c 100644 --- a/src/qc_compiler/utils.py +++ b/src/qc_compiler/utils.py @@ -4,9 +4,13 @@ extraction used across all optimization modules. """ +import logging + from qiskit import QuantumCircuit from qiskit.providers import BackendV2 +logger = logging.getLogger(__name__) + TWO_QUBIT_GATES = {"cx", "cz", "ecr", "swap", "rxx", "rzz", "ryy", "crx", "cry", "crz"} @@ -43,20 +47,20 @@ def get_backend_properties(backend: BackendV2) -> dict: try: t1_val = props.qubit_property(qubit, "T1")[0] t1_times[qubit] = float(t1_val) - except Exception: # noqa: S110, BLE001 - pass + except Exception: # noqa: BLE001 + logger.warning("Could not extract T1 for qubit %d", qubit) try: t2_val = props.qubit_property(qubit, "T2")[0] t2_times[qubit] = float(t2_val) - except Exception: # noqa: S110, BLE001 - pass + except Exception: # noqa: BLE001 + logger.warning("Could not extract T2 for qubit %d", qubit) try: ro_val = props.qubit_property(qubit, "readout_error")[0] readout_errors[qubit] = float(ro_val) - except Exception: # noqa: S110, BLE001 - pass + except Exception: # noqa: BLE001 + logger.warning("Could not extract readout error for qubit %d", qubit) single_qubit_gate_errors = {} two_qubit_gate_errors = {} diff --git a/tests/test_utils.py b/tests/test_utils.py index 1f2fee7..166bf63 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,8 @@ """Tests for qc_compiler.utils module.""" +import logging +from unittest.mock import MagicMock + from qiskit import QuantumCircuit from qiskit_ibm_runtime.fake_provider import FakeBrisbane @@ -366,4 +369,35 @@ def test_gate_length_unit_conversion(self): props = get_backend_properties(backend) assert len(props["gate_lengths"]) > 0 for length in props["gate_lengths"].values(): - assert length > 0 \ No newline at end of file + assert length > 0 + + +class TestBackendPropertyExtractionWarnings: + """Regression tests for backend property extraction logging (issue #49).""" + + def test_missing_t1_logs_warning(self, caplog): + backend = MagicMock() + backend.name = "test_backend" + backend.num_qubits = 2 + mock_props = MagicMock() + mock_props.qubit_property.side_effect = Exception("no T1 data") + mock_props.gates = [] + backend.properties.return_value = mock_props + + with caplog.at_level(logging.WARNING, logger="qc_compiler.utils"): + result = get_backend_properties(backend) + assert "Could not extract T1" in caplog.text + assert result["t1_times"] == {} + + def test_missing_readout_error_logs_warning(self, caplog): + backend = MagicMock() + backend.name = "test_backend" + backend.num_qubits = 2 + mock_props = MagicMock() + mock_props.qubit_property.side_effect = Exception("no data") + mock_props.gates = [] + backend.properties.return_value = mock_props + + with caplog.at_level(logging.WARNING, logger="qc_compiler.utils"): + get_backend_properties(backend) + assert "Could not extract readout error" in caplog.text \ No newline at end of file