# Buggy code
def _initialize_backend_prop(self):
    """
    Extract readout and CNOT errors and compute swap costs.
    """
    backend_prop = self.backend_prop
    for ginfo in backend_prop.gates:
        if ginfo.gate == "cx":
            for item in ginfo.parameters:
                if item.name == "gate_error":
                    g_reliab = 1.0 - item.value
                    break
                else:
                    g_reliab = 1.0
            swap_reliab = pow(g_reliab, 3)
            swap_reliab = -math.log(swap_reliab) if swap_reliab != 0 else -math.inf
            self.swap_graph.add_edge(
                ginfo.qubits[0], ginfo.qubits[1], weight=swap_reliab
            )
            self.swap_graph.add_edge(
                ginfo.qubits[1], ginfo.qubits[0], weight=swap_reliab
            )
            self.cx_errors[(ginfo.qubits[0], ginfo.qubits[1])] = g_reliab
            self.gate_list.append((ginfo.qubits[0], ginfo.qubits[1]))
    idx = 0
    for q in backend_prop.qubits:
        for nduv in q:
            if nduv.name == "readout_error":
                self.readout_errors[idx] = 1.0 - nduv.value
                self.available_hw_qubits.append(idx)
        idx += 1
    for edge in self.cx_errors:
        self.gate_cost[edge] = (
            self.cx_errors[edge]
            * self.readout_errors[edge[0]]
            * self.readout_errors[edge[1]]
        )
    self.swap_paths, swap_costs_temp = (
        nx.algorithms.shortest_paths.dense.floyd_warshall_predecessor_and_distance(
            self.swap_graph, weight="weight"
        )
    )
    for i in swap_costs_temp:
        self.swap_costs[i] = {}
        for j in swap_costs_temp[i]:
            if (i, j) in self.cx_errors:
                self.swap_costs[i][j] = self.cx_errors[(i, j)]
            elif (j, i) in self.cx_errors:
                self.swap_costs[i][j] = self.cx_errors[(j, i)]
            else:
                best_reliab = 0.0
                for n in self.swap_graph.neighbors(j):
                    if (n, j) in self.cx_errors:
                        reliab = (
                            math.exp(-swap_costs_temp[i][n]) * self.cx_errors[(n, j)]
                        )
                    else:
                        reliab = (
                            math.exp(-swap_costs_temp[i][n]) * self.cx_errors[(j, n)]
                        )
                    if reliab > best_reliab:
                        best_reliab = reliab
                self.swap_costs[i][j] = best_reliab


# Traceback (TypeError)
import qiskit as qk
from qiskit.test.mock import FakePoughkeepsie
qc = qk.QuantumCircuit.from_qasm_str('''
OPENQASM 2.0;
include "qelib1.inc";
qreg q7159[6];
qreg q7160[2];
creg c1212[1];
cx q7159[5],q7159[4];
cx q7159[3],q7159[2];
cx q7159[1],q7159[0];
cx q7160[1],q7160[0];
measure q7160[1] -> c1212[0];''')
qk.transpile(qc, backend=FakePoughkeepsie(), optimization_level=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/compiler/transpile.py", line 200, in transpile
circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_configs)))
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/tools/parallel.py", line 100, in parallel_map
return [task(values[0], *task_args, **task_kwargs)]
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/compiler/transpile.py", line 221, in _transpile_circuit
return transpile_circuit(circuit, transpile_config)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/transpile_circuit.py", line 62, in transpile_circuit
out_circuit = pass_manager.run(circuit)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/passmanager.py", line 172, in run
dag = self._do_pass(pass_, dag, passset.options)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/passmanager.py", line 223, in _do_pass
dag = self._run_this_pass(pass_, dag)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/passmanager.py", line 255, in _run_this_pass
pass_.run(FencedDAGCircuit(dag))
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/passes/mapping/noise_adaptive_layout.py", line 229, in run
self.prog2hw[edge[0]] = best_hw_edge[0]
TypeError: 'NoneType' object is not subscriptable

# Fixed code
def _initialize_backend_prop(self):
    """
    Extract readout and CNOT errors and compute swap costs.
    """
    backend_prop = self.backend_prop
    for ginfo in backend_prop.gates:
        if ginfo.gate == "cx":
            for item in ginfo.parameters:
                if item.name == "gate_error":
                    g_reliab = 1.0 - item.value
                    break
                else:
                    g_reliab = 1.0
            swap_reliab = pow(g_reliab, 3)
            swap_reliab = -math.log(swap_reliab) if swap_reliab != 0 else -math.inf
            self.swap_graph.add_edge(
                ginfo.qubits[0], ginfo.qubits[1], weight=swap_reliab
            )
            self.swap_graph.add_edge(
                ginfo.qubits[1], ginfo.qubits[0], weight=swap_reliab
            )
            self.cx_reliability[(ginfo.qubits[0], ginfo.qubits[1])] = g_reliab
            self.gate_list.append((ginfo.qubits[0], ginfo.qubits[1]))
    idx = 0
    for q in backend_prop.qubits:
        for nduv in q:
            if nduv.name == "readout_error":
                self.readout_reliability[idx] = 1.0 - nduv.value
                self.available_hw_qubits.append(idx)
        idx += 1
    for edge in self.cx_reliability:
        self.gate_reliability[edge] = (
            self.cx_reliability[edge]
            * self.readout_reliability[edge[0]]
            * self.readout_reliability[edge[1]]
        )
    self.swap_paths, swap_costs_temp = (
        nx.algorithms.shortest_paths.dense.floyd_warshall_predecessor_and_distance(
            self.swap_graph, weight="weight"
        )
    )
    for i in swap_costs_temp:
        self.swap_costs[i] = {}
        for j in swap_costs_temp[i]:
            if (i, j) in self.cx_reliability:
                self.swap_costs[i][j] = self.cx_reliability[(i, j)]
            elif (j, i) in self.cx_reliability:
                self.swap_costs[i][j] = self.cx_reliability[(j, i)]
            else:
                best_reliab = 0.0
                for n in self.swap_graph.neighbors(j):
                    if (n, j) in self.cx_reliability:
                        reliab = (
                            math.exp(-swap_costs_temp[i][n])
                            * self.cx_reliability[(n, j)]
                        )
                    else:
                        reliab = (
                            math.exp(-swap_costs_temp[i][n])
                            * self.cx_reliability[(j, n)]
                        )
                    if reliab > best_reliab:
                        best_reliab = reliab
                self.swap_costs[i][j] = best_reliab