From e5dd18910921fcc280396799714de8e1dc377b39 Mon Sep 17 00:00:00 2001 From: William L <=> Date: Tue, 18 Jun 2024 03:08:42 -0400 Subject: [PATCH 1/2] tests added --- src/Model_Testing.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Model_Testing.py diff --git a/src/Model_Testing.py b/src/Model_Testing.py new file mode 100644 index 0000000..6178701 --- /dev/null +++ b/src/Model_Testing.py @@ -0,0 +1,37 @@ +import pytest +from Model import AnyonModel, Model +import numpy as np +import cmath + +@pytest.fixture +def initialize_ising(): + return Model(AnyonModel(1)) + +@pytest.mark.model +def test_r_matrix(initialize_ising): + ising = initialize_ising + isingMat1 = initialize_ising._r_mtx + isingMat2 = cmath.exp(-1j*np.pi/8)*np.array([[1,0],[0,1j]]) + assert np.equal(isingMat1, isingMat2).all() + +@pytest.mark.model +def test_f_matrix(initialize_ising): + ising = initialize_ising + + # check F with all sigma subscripts yields the desired matrix + sigma4F1 = ising.getFMatrix("sigma", "sigma", "sigma", "sigma") + sigma4F2 = 1/np.sqrt(2)*np.array([[1,1],[1,-1]]) + assert np.equal(sigma4F1, sigma4F2).all() + + # check other non identity matrices + assert np.equal(ising.getFMatrix("psi", "sigma", "sigma", "vacuum"), -1*np.identity(2)).all() + assert np.equal(ising.getFMatrix("psi", "psi", "sigma", "sigma"), -1*np.identity(2)).all() + assert np.equal(ising.getFMatrix("sigma", "sigma", "psi", "psi"), -1*np.identity(2)).all() + assert not np.equal(ising.getFMatrix("psi", "sigma", "psi", "vacuum"), np.identity(2)).all() + + #check identity matrices + assert np.equal(ising.getFMatrix("psi", "psi", "psi", "vacuum"), np.identity(2)).all() + assert np.equal(ising.getFMatrix("psi", "vacuum", "psi", "psi"), np.identity(2)).all() + assert np.equal(ising.getFMatrix("psi", "psi", "psi", "psi"), np.identity(2)).all() + + From 9b3441bb410f4e38b8ef231082664dc15f8fa0bd Mon Sep 17 00:00:00 2001 From: Haadi Khan Date: Tue, 18 Jun 2024 12:15:59 -0400 Subject: [PATCH 2/2] Merged with main --- python/tests/test_model.py | 41 ++++++++++++++++++++++++++++++++------ src/Model_Testing.py | 37 ---------------------------------- 2 files changed, 35 insertions(+), 43 deletions(-) delete mode 100644 src/Model_Testing.py diff --git a/python/tests/test_model.py b/python/tests/test_model.py index 98216d5..36c5c03 100644 --- a/python/tests/test_model.py +++ b/python/tests/test_model.py @@ -1,11 +1,40 @@ -import pytest -from anyon_braiding_simulator import AnyonModel, Model +# Standard Library +import cmath -""" -TODO: Write tests for the Model class -""" +import numpy as np +import pytest +from anyon_braiding_simulator import AnyonModel +from Model import Model @pytest.fixture -def setup(): +def initialize_ising(): return Model(AnyonModel.Ising) + + +@pytest.mark.model +def test_r_matrix(initialize_ising): + isingMat1 = initialize_ising._r_mtx + isingMat2 = cmath.exp(-1j * np.pi / 8) * np.array([[1, 0], [0, 1j]]) + assert np.equal(isingMat1, isingMat2).all() + + +@pytest.mark.model +def test_f_matrix(initialize_ising): + ising = initialize_ising + + # check F with all sigma subscripts yields the desired matrix + sigma4F1 = ising.getFMatrix('sigma', 'sigma', 'sigma', 'sigma') + sigma4F2 = 1 / np.sqrt(2) * np.array([[1, 1], [1, -1]]) + assert np.equal(sigma4F1, sigma4F2).all() + + # check other non identity matrices + assert np.equal(ising.getFMatrix('psi', 'sigma', 'sigma', 'vacuum'), -1 * np.identity(2)).all() + assert np.equal(ising.getFMatrix('psi', 'psi', 'sigma', 'sigma'), -1 * np.identity(2)).all() + assert np.equal(ising.getFMatrix('sigma', 'sigma', 'psi', 'psi'), -1 * np.identity(2)).all() + assert not np.equal(ising.getFMatrix('psi', 'sigma', 'psi', 'vacuum'), np.identity(2)).all() + + # check identity matrices + assert np.equal(ising.getFMatrix('psi', 'psi', 'psi', 'vacuum'), np.identity(2)).all() + assert np.equal(ising.getFMatrix('psi', 'vacuum', 'psi', 'psi'), np.identity(2)).all() + assert np.equal(ising.getFMatrix('psi', 'psi', 'psi', 'psi'), np.identity(2)).all() diff --git a/src/Model_Testing.py b/src/Model_Testing.py deleted file mode 100644 index 6178701..0000000 --- a/src/Model_Testing.py +++ /dev/null @@ -1,37 +0,0 @@ -import pytest -from Model import AnyonModel, Model -import numpy as np -import cmath - -@pytest.fixture -def initialize_ising(): - return Model(AnyonModel(1)) - -@pytest.mark.model -def test_r_matrix(initialize_ising): - ising = initialize_ising - isingMat1 = initialize_ising._r_mtx - isingMat2 = cmath.exp(-1j*np.pi/8)*np.array([[1,0],[0,1j]]) - assert np.equal(isingMat1, isingMat2).all() - -@pytest.mark.model -def test_f_matrix(initialize_ising): - ising = initialize_ising - - # check F with all sigma subscripts yields the desired matrix - sigma4F1 = ising.getFMatrix("sigma", "sigma", "sigma", "sigma") - sigma4F2 = 1/np.sqrt(2)*np.array([[1,1],[1,-1]]) - assert np.equal(sigma4F1, sigma4F2).all() - - # check other non identity matrices - assert np.equal(ising.getFMatrix("psi", "sigma", "sigma", "vacuum"), -1*np.identity(2)).all() - assert np.equal(ising.getFMatrix("psi", "psi", "sigma", "sigma"), -1*np.identity(2)).all() - assert np.equal(ising.getFMatrix("sigma", "sigma", "psi", "psi"), -1*np.identity(2)).all() - assert not np.equal(ising.getFMatrix("psi", "sigma", "psi", "vacuum"), np.identity(2)).all() - - #check identity matrices - assert np.equal(ising.getFMatrix("psi", "psi", "psi", "vacuum"), np.identity(2)).all() - assert np.equal(ising.getFMatrix("psi", "vacuum", "psi", "psi"), np.identity(2)).all() - assert np.equal(ising.getFMatrix("psi", "psi", "psi", "psi"), np.identity(2)).all() - -