# Buggy code
def _select_best_remaining_qubit(self, prog_qubit):
    """
    Select the best remaining hardware qubit for the next program qubit.
    """
    reliab_store = {}
    for hw_qubit in self.available_hw_qubits:
        reliab = 1
        for n in self.prog_graph.neighbors(prog_qubit):
            if n in self.prog2hw:
                reliab *= self.swap_costs[self.prog2hw[n]][hw_qubit]
        reliab *= self.readout_errors[hw_qubit]
        reliab_store[hw_qubit] = reliab
    max_reliab = 0
    best_hw_qubit = None
    for hw_qubit in reliab_store:
        if reliab_store[hw_qubit] > max_reliab:
            max_reliab = reliab_store[hw_qubit]
            best_hw_qubit = hw_qubit
    return best_hw_qubit


# 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 _select_best_remaining_qubit(self, prog_qubit):
    """
    Select the best remaining hardware qubit for the next program qubit.
    """
    reliab_store = {}
    for hw_qubit in self.available_hw_qubits:
        reliab = 1
        for n in self.prog_graph.neighbors(prog_qubit):
            if n in self.prog2hw:
                reliab *= self.swap_costs[self.prog2hw[n]][hw_qubit]
        reliab *= self.readout_reliability[hw_qubit]
        reliab_store[hw_qubit] = reliab
    max_reliab = 0
    best_hw_qubit = None
    for hw_qubit in reliab_store:
        if reliab_store[hw_qubit] > max_reliab:
            max_reliab = reliab_store[hw_qubit]
            best_hw_qubit = hw_qubit
    return best_hw_qubit