Repository: Qiskit/qiskit

Issue:
TestUnitaryCircuit.test_qasm_2q_unitary failing on windows
<!-- ⚠️ 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**: master @ 9fb0f2e
- **Python version**: 3.6
- **Operating system**: Windows

### What is the current behavior?

From https://dev.azure.com/qiskit-ci/qiskit-terra/_build/results?buildId=17021&view=logs&j=c36f2e0f-c9b4-5d6c-0a9a-bb54323ef157&t=c9849e48-bd8f-5b19-f5f8-0b7675dae500&l=5319 :

```
test.python.circuit.test_unitary.TestUnitaryCircuit.test_qasm_2q_unitary
------------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "D:\a\1\s\test\python\circuit\test_unitary.py", line 271, in test_qasm_2q_unitary
    self.assertEqual(expected_qasm, qc.qasm())

      File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 829, in assertEqual
    assertion_func(first, second, msg=msg)

      File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 1203, in assertMultiLineEqual
    self.fail(self._formatMessage(msg, standardMsg))

      File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 670, in fail
    raise self.failureException(msg)

    AssertionError: 'OPEN[98 chars]u3(0,0,0) p0;\n\tu3(0,0,0) p1;\n}\ncustom_gate[37 chars]];\n' != 'OPEN[98 chars]u3(0,-pi/4,pi/4) p0;\n\tu3(0,0,0) p1;\n}\ncust[44 chars]];\n'
  OPENQASM 2.0;
  include "qelib1.inc";
  qreg q0[2];
  creg c0[1];
  x q0[0];
  gate custom_gate p0,p1 {
- 	u3(0,0,0) p0;
+ 	u3(0,-pi/4,pi/4) p0;
  	u3(0,0,0) p1;
  }
  custom_gate q0[0],q0[1];
  custom_gate q0[1],q0[0];
```

### Steps to reproduce the problem



### What is the expected behavior?



### Suggested solutions





Discussion:
This looks like a repeat of https://github.com/Qiskit/qiskit-terra/issues/4606 I don't know what would have changed to cause this now though. We did fix it in https://github.com/Qiskit/qiskit-terra/pull/4656 and that isolated windows only fix was replaced by a more general fix in https://github.com/Qiskit/qiskit-terra/commit/8e4a366c02438200dd3b24201011235353b59089 but it wasn't failing on that PR or other open patches. We can add back the fix (or a similar one) from #4606 if needed, but it'd be good to understand what is going on
we should do circuit equivalence checking rather than checking qasm. (pointed out by @levbishop)
Well except that test isn't really about checking equivalence, the test that's failing is specifically testing to make sure that we can run `circuit.qasm()` on a circuit with a 2q unitary gate in it: https://github.com/Qiskit/qiskit-terra/blob/master/test/python/circuit/test_unitary.py#L248-L271 and that the decomposed unitary gets defined as a custom gate correctly in the qasm output. There are other tests that do an equivalence check to verify the decomposition and I agree that is the proper way to to test that.

Resolving patch:
diff --git a/qiskit/quantum_info/synthesis/two_qubit_decompose.py b/qiskit/quantum_info/synthesis/two_qubit_decompose.py
--- a/qiskit/quantum_info/synthesis/two_qubit_decompose.py
+++ b/qiskit/quantum_info/synthesis/two_qubit_decompose.py
@@ -382,7 +382,7 @@ def traces(self, target):
                 4]
 
     @staticmethod
-    def decomp0(target):
+    def decomp0(target, eps=1e-15):
         """Decompose target ~Ud(x, y, z) with 0 uses of the basis gate.
         Result Ur has trace:
         :math:`|Tr(Ur.Utarget^dag)| = 4|(cos(x)cos(y)cos(z)+ j sin(x)sin(y)sin(z)|`,
@@ -390,7 +390,10 @@ def decomp0(target):
 
         U0l = target.K1l.dot(target.K2l)
         U0r = target.K1r.dot(target.K2r)
-
+        U0l.real[abs(U0l.real) < eps] = 0.0
+        U0l.imag[abs(U0l.imag) < eps] = 0.0
+        U0r.real[abs(U0r.real) < eps] = 0.0
+        U0r.imag[abs(U0r.imag) < eps] = 0.0
         return U0r, U0l
 
     def decomp1(self, target):


Test patch: