From c8195ca91f512a07f5b99cc4b2b1f6238814d6df Mon Sep 17 00:00:00 2001 From: DanPuzzuoli Date: Mon, 19 Dec 2022 10:13:01 -0800 Subject: [PATCH 1/3] fixing tests --- test/dynamics/models/test_generator_model.py | 33 +++++++++++--------- test/dynamics/solvers/test_lanczos.py | 15 ++++----- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/test/dynamics/models/test_generator_model.py b/test/dynamics/models/test_generator_model.py index f10e8bbb4..bf2253184 100644 --- a/test/dynamics/models/test_generator_model.py +++ b/test/dynamics/models/test_generator_model.py @@ -2,13 +2,12 @@ # # (C) Copyright IBM 2020. # -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license +# in the LICENSE.txt file in the root directory of this source tree or at +# http://www.apache.org/licenses/LICENSE-2.0. # -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. +# Any modifications or derivative works of this code must retain this copyright notice, and modified +# files need to carry a notice indicating that they have been altered from the originals. # pylint: disable=invalid-name """Tests for generator_models.py. """ @@ -758,28 +757,32 @@ def test_array_inputs_pseudo_random(self): low=-b, high=b, size=(dim, dim) ) old_frame = old_frame - old_frame.conj().transpose() + old_frame = RotatingFrame(old_frame) + new_frame = rng.uniform(low=-b, high=b, size=(dim, dim)) + 1j * rng.uniform( low=-b, high=b, size=(dim, dim) ) new_frame = new_frame - new_frame.conj().transpose() + new_frame = RotatingFrame(new_frame) out_static = transfer_static_operator_between_frames( - Array(static_operator), new_frame=Array(new_frame), old_frame=Array(old_frame) + Array(static_operator), new_frame=new_frame, old_frame=old_frame ) out_operators = transfer_operators_between_frames( - Array(operators), new_frame=Array(new_frame), old_frame=Array(old_frame) + Array(operators), new_frame=new_frame, old_frame=old_frame ) self.assertTrue(isinstance(out_static, (np.ndarray, Array))) self.assertTrue(isinstance(out_operators, (np.ndarray, Array))) - _, U = wrap(np.linalg.eigh)(1j * old_frame) - _, V = wrap(np.linalg.eigh)(1j * new_frame) - Uadj = U.conj().transpose() - Vadj = V.conj().transpose() - - expected_static = Vadj @ ((U @ static_operator @ Uadj + old_frame) - new_frame) @ V - expected_operators = Vadj @ (U @ operators @ Uadj) @ V + expected_static = new_frame.operator_into_frame_basis( + (old_frame.operator_out_of_frame_basis(static_operator) + old_frame.frame_operator) + - new_frame.frame_operator + ) + expected_operators = [ + new_frame.operator_into_frame_basis(old_frame.operator_out_of_frame_basis(op)) + for op in operators + ] self.assertAllClose(out_static, expected_static) self.assertAllClose(out_operators, expected_operators) diff --git a/test/dynamics/solvers/test_lanczos.py b/test/dynamics/solvers/test_lanczos.py index 288f53152..3053d8d0f 100644 --- a/test/dynamics/solvers/test_lanczos.py +++ b/test/dynamics/solvers/test_lanczos.py @@ -2,13 +2,12 @@ # # (C) Copyright IBM 2022. # -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license +# in the LICENSE.txt file in the root directory of this source tree or at +# http://www.apache.org/licenses/LICENSE-2.0. # -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. +# Any modifications or derivative works of this code must retain this copyright notice, and modified +# files need to carry a notice indicating that they have been altered from the originals. # pylint: disable=invalid-name """ @@ -64,7 +63,9 @@ def test_ground_state(self): eigen_vectors_l = q_basis @ eigen_vectors_t eigen_values_np, eigen_vectors_np = np.linalg.eigh(self.rand_op) - self.assertAllClose(eigen_vectors_np[:, 0], eigen_vectors_l[:, 0]) + # test overlap is 1. + overlap = np.abs(np.sum(eigen_vectors_np[:, 0].conj() * eigen_vectors_l[:, 0])) + self.assertAllClose(overlap, 1.0) self.assertAllClose(eigen_values_np[0], eigen_values_l[0]) def test_expm(self): From d46a97cb0d9c4a22fecc6b07c2c5f69969e1c933 Mon Sep 17 00:00:00 2001 From: Daniel Puzzuoli Date: Mon, 19 Dec 2022 13:46:54 -0500 Subject: [PATCH 2/3] Update test/dynamics/models/test_generator_model.py Co-authored-by: Ian Hincks --- test/dynamics/models/test_generator_model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/dynamics/models/test_generator_model.py b/test/dynamics/models/test_generator_model.py index bf2253184..19fcd3308 100644 --- a/test/dynamics/models/test_generator_model.py +++ b/test/dynamics/models/test_generator_model.py @@ -762,8 +762,7 @@ def test_array_inputs_pseudo_random(self): new_frame = rng.uniform(low=-b, high=b, size=(dim, dim)) + 1j * rng.uniform( low=-b, high=b, size=(dim, dim) ) - new_frame = new_frame - new_frame.conj().transpose() - new_frame = RotatingFrame(new_frame) + new_frame = RotatingFrame(new_frame - new_frame.conj().transpose()) out_static = transfer_static_operator_between_frames( Array(static_operator), new_frame=new_frame, old_frame=old_frame From 06b48f652b3966ef2a06435ba03004c74d69db35 Mon Sep 17 00:00:00 2001 From: Daniel Puzzuoli Date: Mon, 19 Dec 2022 13:47:00 -0500 Subject: [PATCH 3/3] Update test/dynamics/models/test_generator_model.py Co-authored-by: Ian Hincks --- test/dynamics/models/test_generator_model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/dynamics/models/test_generator_model.py b/test/dynamics/models/test_generator_model.py index 19fcd3308..b387ca311 100644 --- a/test/dynamics/models/test_generator_model.py +++ b/test/dynamics/models/test_generator_model.py @@ -756,8 +756,7 @@ def test_array_inputs_pseudo_random(self): old_frame = rng.uniform(low=-b, high=b, size=(dim, dim)) + 1j * rng.uniform( low=-b, high=b, size=(dim, dim) ) - old_frame = old_frame - old_frame.conj().transpose() - old_frame = RotatingFrame(old_frame) + old_frame = RotatingFrame(old_frame - old_frame.conj().transpose()) new_frame = rng.uniform(low=-b, high=b, size=(dim, dim)) + 1j * rng.uniform( low=-b, high=b, size=(dim, dim)