Repository: Qiskit/qiskit

Issue:
Transpiler fails with optimization level 2 if gates have 100% error
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

- **Qiskit Terra version**: 0.8.2 and master branch
- **Python version**: 3.6.3
- **Operating system**: Ubuntu shell in Windows 10

### What is the current behavior?
If any CX gate is reported as 100% error, attempting to run transpiler with optimization level 2 on any circuit will fail with a math error.  Likely trying to take log of 0. 

```  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/compiler/transpile.py", line 159, in transpile
    circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_configs)))
  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/tools/parallel.py", line 100, in parallel_map
    return [task(values[0], *task_args, **task_kwargs)]
  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/compiler/transpile.py", line 180, in _transpile_circuit
    return transpile_circuit(circuit, transpile_config)
  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/transpiler/transpile_circuit.py", line 62, in transpile_circuit
    return pass_manager.run(circuit)
  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/transpiler/passmanager.py", line 138, in run
    dag = self._do_pass(pass_, dag, passset.options)
  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/transpiler/passmanager.py", line 168, in _do_pass
    dag = self._run_this_pass(pass_, dag)
  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/transpiler/passmanager.py", line 188, in _run_this_pass
    pass_.run(FencedDAGCircuit(dag))
  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/transpiler/passes/mapping/noise_adaptive_layout.py", line 215, in run
    self._initialize_backend_prop()
  File "/home/awack/anaconda3/lib/python3.6/site-packages/qiskit/transpiler/passes/mapping/noise_adaptive_layout.py", line 99, in _initialize_backend_prop
    swap_reliab = -math.log(pow(g_reliab, 3))
ValueError: math domain error```


### Steps to reproduce the problem

See attached file for test case that can reproduce the issue


### What is the expected behavior?

Should not crash if gates have 100% error, should just avoid that gate.

### Suggested solutions


[transpiler_err.py.txt](https://github.com/Qiskit/qiskit-terra/files/3297360/transpiler_err.py.txt)





Discussion:

Resolving patch:
diff --git a/qiskit/transpiler/passes/mapping/noise_adaptive_layout.py b/qiskit/transpiler/passes/mapping/noise_adaptive_layout.py
--- a/qiskit/transpiler/passes/mapping/noise_adaptive_layout.py
+++ b/qiskit/transpiler/passes/mapping/noise_adaptive_layout.py
@@ -96,7 +96,8 @@ def _initialize_backend_prop(self):
                         break
                     else:
                         g_reliab = 1.0
-                swap_reliab = -math.log(pow(g_reliab, 3))
+                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


Test patch: