Repository: Qiskit/qiskit

Issue:
Optimize1qGatesDecompositions does not optimize single (non-parameterized) epsilon rotations
<!-- ⚠️ 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**: main @ aceac9ea
- **Python version**: 3.6
- **Operating system**: osx 10.15.7

### What is the current behavior?

While looking into #6468 , `Optimize1qGatesDecompositions` will remove runs of (non-parameterized) single qubit gates if their net operation is sufficiently close to the identity, but will not do so for runs of only a single gate.

### Steps to reproduce the problem

```
>>> import qiskit as qk
>>> qc = qk.QuantumCircuit(1)
>>> qc.u1(0.0, 0)
>>> qc.draw()
     ┌───────┐
q_0: ┤ U1(0) ├
     └───────┘
>>> from qiskit.transpiler.passes import Optimize1qGates, Optimize1qGatesDecomposition
>>> Optimize1qGates(basis=['u1', 'u2', 'u3'])(qc).draw()

q_0:

>>> Optimize1qGatesDecomposition(basis=['u1', 'u2', 'u3'])(qc).draw()

q_0:

>>> qc = qk.QuantumCircuit(1)
>>> qc.u1(1e-17, 0)
>>> qc.draw()
     ┌───────┐
q_0: ┤ U1(0) ├
     └───────┘
>>> Optimize1qGates(basis=['u1', 'u2', 'u3'])(qc).draw()

q_0:

>>> Optimize1qGatesDecomposition(basis=['u1', 'u2', 'u3'])(qc).draw()
     ┌───────┐
q_0: ┤ U1(0) ├
     └───────┘
>>> qc = qk.QuantumCircuit(1)
>>> qc.u1(1e-17, 0)
>>> qc.u1(1e-17, 0)
>>> qc.draw()
     ┌───────┐┌───────┐
q_0: ┤ U1(0) ├┤ U1(0) ├
     └───────┘└───────┘
>>> Optimize1qGates(basis=['u1', 'u2', 'u3'])(qc).draw()

q_0:

>>> Optimize1qGatesDecomposition(basis=['u1', 'u2', 'u3'])(qc).draw()

q_0:

```

This may prevent the transpiler from making subsequent optimizations (without KAK) like
```
>>> qc = qk.QuantumCircuit(2)
>>> qc.cx(0, 1)
>>> qc.u1(1e-17, 0)
>>> qc.cx(0, 1)
>>> qc.draw()
          ┌───────┐
q_0: ──■──┤ U1(0) ├──■──
     ┌─┴─┐└───────┘┌─┴─┐
q_1: ┤ X ├─────────┤ X ├
     └───┘         └───┘
>>> Optimize1qGates(basis=['u1', 'u2', 'u3'])(qc).draw()

q_0: ──■────■──
     ┌─┴─┐┌─┴─┐
q_1: ┤ X ├┤ X ├
     └───┘└───┘
>>> Optimize1qGatesDecomposition(basis=['u1', 'u2', 'u3'])(qc).draw()
          ┌───────┐
q_0: ──■──┤ U1(0) ├──■──
     ┌─┴─┐└───────┘┌─┴─┐
q_1: ┤ X ├─────────┤ X ├
     └───┘         └───┘
```

### What is the expected behavior?



### Suggested solutions





Discussion:
We probably just need to add some tolerance to this line: https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py#L83 basically just swap that with numpy `allclose` instead of `equals` (using approximation degree for the tolerance might make sense too)
Hi, i am new and would like to work on this if thats ok.
@mwessling90 sure, I've assigned the issue to you. Feel free to reach out if you need any help
I want to work on this issue if thats ok.
Thanks @fs1132429 but this issue has already been assigned to someone else, I saw you volunteered for a few other issues so I've assigned a couple others to you 😄 
@javabster @mwessling90 would it be ok if I took over this issue? 


Resolving patch:
diff --git a/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py b/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py
--- a/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py
+++ b/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py
@@ -79,7 +79,7 @@ def run(self, dag):
             #     The U3 decomposer is only going to emit a sequence of length 1 anyhow.
             if "u3" in self._target_basis and len(run) == 1 and isinstance(run[0].op, U3Gate):
                 # Toss U3 gates equivalent to the identity; there we get off easy.
-                if np.array_equal(run[0].op.to_matrix(), np.eye(2)):
+                if np.allclose(run[0].op.to_matrix(), np.eye(2), 1e-15, 0):
                     dag.remove_op_node(run[0])
                     continue
                 # We might rewrite into lower `u`s if they're available.


Test patch: