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
2 changes: 1 addition & 1 deletion src/qc_compiler/cost_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def _get_measured_qubits(self, circuit: QuantumCircuit) -> list[int]:
for qubit in instr.qubits:
measured.add(circuit.find_bit(qubit).index)
if not measured:
measured = set(range(circuit.num_qubits))
return []
return sorted(measured)

def estimate_fidelity(
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cost_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,24 @@ def test_measurement_error_no_measure(self):
qc.h(0)
qc.cx(0, 1)
error = model.estimate_measurement_error(qc)
assert error == 0.0

def test_measurement_error_only_measured_qubits(self):
model = CostModel()
device = DeviceCharacterization(
backend_name="test",
num_qubits=3,
readout_errors={0: 0.01, 1: 0.02, 2: 0.03},
)
model = CostModel()
model.device = device
qc = QuantumCircuit(3, 1)
qc.h(0)
qc.cx(0, 1)
qc.measure(0, 0)
error = model.estimate_measurement_error(qc)
assert error > 0
assert error < 0.02

def test_fidelity_bell_state(self):
model = CostModel()
Expand Down
Loading