Repository: quantumlib/Cirq

Issue:
upgrade to numpy 1.19
Discover all the issues / test failures related to numpy 0.19 and upgrade our requirements.txt.
More context: https://github.com/quantumlib/Cirq/pull/3106


Discussion:
Hi @balopat, I just updated NumPy to 1.19 and ran check/all | grep numpy, it seems like every test passed and no warning regarding NumPy has been raised. But there is a mention that "Importing from numpy.matlib is deprecated since 1.19.0" which is related to quimb package that was used. Hope this helps.
Can I help on this if needed?
@exAClior - that sounds great - can you confirm that #3105 and #3103 - the currently known broken tests - are passing by raising a PR? @abhik-99  - I would leave this with @exAClior if he is interested. 
@balopat Just a quick update, I ran the following commands `pytest ./cirq/ion/convert_to_ion_gates_test.py` for #3105 and `pytest ./cirq/optimizers/decompositions_test.py` for #3103 and they did pass with no problem at all. 
My python version is 3.8.5 and the numpy version is 1.19.1. 
However, as I am trying to create a PR to report this, I pulled from the latest upstream/master I ran `./cirq/check/all`, it was not happy at all. I think pylint does not treat a overloaded function very nicely. This morning everything runs fine. I don't know if it is the last commit on master that creates this problem. I could go ahead revert the last commit on my fork and investigate
I would be wary of using python 3.8 - I think that has its own bag of issues (#3194). I would suggest solving this using a python 3.7 env first.
> I would be wary of using python 3.8 - I think that has its own bag of issues (#3194). I would suggest solving this using a python 3.7 env first.

Thank you so much for your advice. It turned out that I am not installing the requirement for checkers and etc correctly. But numpy 1.19.1 should work. I am double testing everything before I create the PR.

Resolving patch:
diff --git a/cirq/optimizers/decompositions.py b/cirq/optimizers/decompositions.py
--- a/cirq/optimizers/decompositions.py
+++ b/cirq/optimizers/decompositions.py
@@ -139,7 +139,7 @@ def single_qubit_op_to_framed_phase_form(
         When M is controlled, the control must be rotated around the Z axis to
         apply g.
     """
-    vals, vecs = np.linalg.eig(mat)
+    vals, vecs = linalg.unitary_eig(mat)
     u = np.conj(vecs).T
     r = vals[1] / vals[0]
     g = vals[0]


Test patch:
diff --git a/cirq/ion/convert_to_ion_gates_test.py b/cirq/ion/convert_to_ion_gates_test.py
--- a/cirq/ion/convert_to_ion_gates_test.py
+++ b/cirq/ion/convert_to_ion_gates_test.py
@@ -54,16 +54,15 @@ def test_convert_to_ion_gates():
 
     rx = cirq.ion.ConvertToIonGates().convert_one(OtherX().on(q0))
     rop = cirq.ion.ConvertToIonGates().convert_one(op)
-    assert rx == [
-        cirq.PhasedXPowGate(phase_exponent=1).on(cirq.GridQubit(0, 0))
-    ]
-    assert rop == [
+    assert cirq.approx_eq(
+        rx, [cirq.PhasedXPowGate(phase_exponent=1.0).on(cirq.GridQubit(0, 0))])
+    assert cirq.approx_eq(rop, [
         cirq.ry(np.pi / 2).on(op.qubits[0]),
         cirq.ms(np.pi / 4).on(op.qubits[0], op.qubits[1]),
         cirq.rx(-1 * np.pi / 2).on(op.qubits[0]),
         cirq.rx(-1 * np.pi / 2).on(op.qubits[1]),
         cirq.ry(-1 * np.pi / 2).on(op.qubits[0])
-    ]
+    ])
 
     rcnot = cirq.ion.ConvertToIonGates().convert_one(OtherCNOT().on(q0, q1))
     assert cirq.approx_eq([op for op in rcnot if len(op.qubits) > 1],
diff --git a/cirq/optimizers/decompositions_test.py b/cirq/optimizers/decompositions_test.py
--- a/cirq/optimizers/decompositions_test.py
+++ b/cirq/optimizers/decompositions_test.py
@@ -12,9 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import math
 import random
-import sys
 from typing import Sequence
 
 import numpy as np
@@ -175,16 +173,10 @@ def test_single_qubit_matrix_to_gates_tolerance_half_turn_phasing():
     assert len(kept) == 3
 
 
-@pytest.mark.xfail(sys.platform == 'win32',
-                   reason='https://github.com/quantumlib/Cirq/issues/2468')
-def test_single_qubit_op_to_framed_phase_form_output_on_example_case():
-    u, t, g = cirq.single_qubit_op_to_framed_phase_form(
-        cirq.unitary(cirq.Y**0.25))
-    cirq.testing.assert_allclose_up_to_global_phase(u,
-                                                    cirq.unitary(cirq.X**0.5),
-                                                    atol=1e-7)
-    assert abs(t - (1 + 1j) * math.sqrt(0.5)) < 0.00001
-    assert abs(g - 1) < 0.00001
+def _random_unitary_with_close_eigenvalues():
+    U = cirq.testing.random_unitary(2)
+    d = np.diag(np.exp([-0.2312j, -0.2312j]))
+    return U @ d @ U.conj().T
 
 
 @pytest.mark.parametrize('mat', [
@@ -195,15 +187,14 @@ def test_single_qubit_op_to_framed_phase_form_output_on_example_case():
     cirq.unitary(cirq.Y),
     cirq.unitary(cirq.Z),
     cirq.unitary(cirq.Z**0.5),
-] + [cirq.testing.random_unitary(2)
-     for _ in range(10)])
+    _random_unitary_with_close_eigenvalues(),
+] + [cirq.testing.random_unitary(2) for _ in range(10)])
 def test_single_qubit_op_to_framed_phase_form_equivalent_on_known_and_random(
         mat):
     u, t, g = cirq.single_qubit_op_to_framed_phase_form(mat)
     z = np.diag([g, g * t])
     assert np.allclose(mat, np.conj(u.T).dot(z).dot(u))
 
-
 def test_single_qubit_matrix_to_phased_x_z_known():
     actual = cirq.single_qubit_matrix_to_phased_x_z(
         np.array([[0, 1], [1, 0]]), atol=0.01)