Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/qc_compiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


Expand Down Expand Up @@ -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 = {}
Expand Down
36 changes: 35 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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

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