From f7fb8a59968f465c1016f451e4a6462d2b920c8a Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 30 Mar 2022 14:52:34 -0400 Subject: [PATCH] Handle edge case where target doesn't have measurement defined This commit fixes an edge case in the heurstic scoring where if a target is present but doesn't have measurement defined we always return a score of 0. In the case measure ment doesn't have measurement defined this will fall back to looking at the degree of the qubit instead of trying to use the readout error rate. --- qiskit/transpiler/passes/layout/vf2_layout.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qiskit/transpiler/passes/layout/vf2_layout.py b/qiskit/transpiler/passes/layout/vf2_layout.py index ec23ac90eb2b..3cb0dbf8a6a0 100644 --- a/qiskit/transpiler/passes/layout/vf2_layout.py +++ b/qiskit/transpiler/passes/layout/vf2_layout.py @@ -211,9 +211,10 @@ def _score_layout(self, layout): on the chosen qubits. If BackendProperties are not available it uses the coupling map degree to weight against higher connectivity qubits.""" bits = layout.get_physical_bits() - score = 0 + score = None if self.target is not None: if "measure" in self.target: + score = 0 for bit in bits: props = self.target["measure"].get((bit,)) if props is None or props.error is None: @@ -223,7 +224,8 @@ def _score_layout(self, layout): ) / len(self.coupling_map.graph) else: score += props.error - else: + if score is None: + score = 0 if self.properties is None: # Sum qubit degree for each qubit in chosen layout as really rough estimate of error for bit in bits: