From d39b33e606c800f2f94815a7882679de57020bd7 Mon Sep 17 00:00:00 2001 From: Marco Lazzarin <48728634+mlazzarin@users.noreply.github.com> Date: Mon, 1 Nov 2021 10:17:12 +0100 Subject: [PATCH 1/2] Replace hardcoded np with backend K in some linalg calls --- src/qibo/tests/test_core_callbacks.py | 2 +- src/qibo/tests/test_core_hamiltonians.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qibo/tests/test_core_callbacks.py b/src/qibo/tests/test_core_callbacks.py index 79264323e8..df21870bb8 100644 --- a/src/qibo/tests/test_core_callbacks.py +++ b/src/qibo/tests/test_core_callbacks.py @@ -323,7 +323,7 @@ def test_gap(backend, dense, check_degenerate): ham = lambda t: (1 - t) * h0.matrix + t * h1.matrix targets = {"ground": [], "excited": [], "gap": []} for t in np.linspace(0, 1, 11): - eigvals = np.linalg.eigvalsh(ham(t)).real + eigvals = K.eigvalsh(ham(t)).real targets["ground"].append(eigvals[0]) targets["excited"].append(eigvals[1]) targets["gap"].append(eigvals[1] - eigvals[0]) diff --git a/src/qibo/tests/test_core_hamiltonians.py b/src/qibo/tests/test_core_hamiltonians.py index 9a33e01ca1..89825d4d73 100644 --- a/src/qibo/tests/test_core_hamiltonians.py +++ b/src/qibo/tests/test_core_hamiltonians.py @@ -173,17 +173,17 @@ def test_hamiltonian_eigenvalues(dtype, dense): H1 = hamiltonians.XXZ(nqubits=2, delta=0.5, dense=dense) H1_eigen = H1.eigenvalues() - hH1_eigen = np.linalg.eigvalsh(H1.matrix) + hH1_eigen = K.eigvalsh(H1.matrix) K.assert_allclose(H1_eigen, hH1_eigen) c1 = dtype(2.5) H2 = c1 * H1 - hH2_eigen = np.linalg.eigvalsh(c1 * H1.matrix) + hH2_eigen = K.eigvalsh(c1 * H1.matrix) K.assert_allclose(H2._eigenvalues, hH2_eigen) c2 = dtype(-11.1) H3 = H1 * c2 - hH3_eigen = np.linalg.eigvalsh(H1.matrix * c2) + hH3_eigen = K.eigvalsh(H1.matrix * c2) K.assert_allclose(H3._eigenvalues, hH3_eigen) From 047d84429b94aec5dad6416730d906b404e31193 Mon Sep 17 00:00:00 2001 From: Marco Lazzarin <48728634+mlazzarin@users.noreply.github.com> Date: Mon, 1 Nov 2021 14:10:38 +0400 Subject: [PATCH 2/2] Fix bug with tensorflow EagerTensor --- src/qibo/tests/test_core_callbacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibo/tests/test_core_callbacks.py b/src/qibo/tests/test_core_callbacks.py index df21870bb8..17e52d1022 100644 --- a/src/qibo/tests/test_core_callbacks.py +++ b/src/qibo/tests/test_core_callbacks.py @@ -323,7 +323,7 @@ def test_gap(backend, dense, check_degenerate): ham = lambda t: (1 - t) * h0.matrix + t * h1.matrix targets = {"ground": [], "excited": [], "gap": []} for t in np.linspace(0, 1, 11): - eigvals = K.eigvalsh(ham(t)).real + eigvals = K.real(K.eigvalsh(ham(t))) targets["ground"].append(eigvals[0]) targets["excited"].append(eigvals[1]) targets["gap"].append(eigvals[1] - eigvals[0])