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: