Skip to content

Commit

Permalink
Merge pull request #66 from Cornell-QCA/model
Browse files Browse the repository at this point in the history
added functions for F inverse and FinvRF
  • Loading branch information
Haadi-Khan authored Jun 27, 2024
2 parents 7774d21 + 204bb28 commit 39d141d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
60 changes: 60 additions & 0 deletions python/anyon_braiding_simulator/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,63 @@ def getFMatrix(self, a: str, b: str, c: str, d: str) -> np.ndarray:
raise ValueError('invalid anyon name')

return self._f_mtx[anyondict[a]][anyondict[b]][anyondict[c]][anyondict[d]]

def getFInv(self, a: str, b: str, c: str, d: str) -> np.ndarray:
"""
Parameters
----------
a : str
name of anyon corresponding to first lower index
b : str
name of anyon corresponding to second lower index
c : str
name of anyon corresponding to third lower index
d : str
name of anyon corresponding to upper index
Only the following strings are accepted as parameters:
vacuum, sigma, psi
Requires that all anyons used as parameters are contained with the
given model
For details on notation, c.f.r. On classification of modular tensor
categories by Rowell, Stong, and Wang
https://www.arxiv.org/abs/0712.1377
Returns
-------
the Inverse F-matrix corresponding to the set of indices in the model
"""

return np.linalg.inv(self.getFMatrix(a,b,c,d))

def getFInvRF(self, a: str, b: str, c: str, d: str) -> np.ndarray:
"""
Parameters
----------
a : str
name of anyon corresponding to first lower index
b : str
name of anyon corresponding to second lower index
c : str
name of anyon corresponding to third lower index
d : str
name of anyon corresponding to upper index
Only the following strings are accepted as parameters:
vacuum, sigma, psi
Requires that all anyons used as parameters are contained with the
given model
For details on notation, c.f.r. On classification of modular tensor
categories by Rowell, Stong, and Wang
https://www.arxiv.org/abs/0712.1377
Returns
-------
the matrix product of (F^-1)RF corresponding to the set of indices in the model
"""

return self.getFInv(a,b,c,d) @ self._r_mtx @ self.getFMatrix(a,b,c,d)
32 changes: 32 additions & 0 deletions python/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,35 @@ def test_f_matrix(initialize_ising):
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()

@pytest.mark.model
def test_f_inverse(initialize_ising):
ising = initialize_ising

# check F with all sigma subscripts cancels with inverse
assert np.isclose(ising.getFMatrix('sigma', 'sigma', 'sigma', 'sigma') @ ising.getFInv('sigma', 'sigma', 'sigma', 'sigma'), np.identity(2)).all()
assert np.isclose(ising.getFInv('sigma', 'sigma', 'sigma', 'sigma') @ ising.getFMatrix('sigma', 'sigma', 'sigma', 'sigma'), np.identity(2)).all()

# check other non identity matrices
assert np.isclose(ising.getFMatrix('psi', 'sigma', 'sigma', 'vacuum') @ ising.getFInv('psi', 'sigma', 'sigma', 'vacuum'), np.identity(2)).all()
assert np.isclose(ising.getFInv('psi', 'sigma', 'sigma', 'vacuum') @ ising.getFMatrix('psi', 'sigma', 'sigma', 'vacuum'), np.identity(2)).all()

assert np.isclose(ising.getFMatrix('sigma', 'sigma', 'psi', 'psi') @ ising.getFInv('sigma', 'sigma', 'psi', 'psi'), np.identity(2)).all()
assert np.isclose(ising.getFInv('sigma', 'sigma', 'psi', 'psi') @ ising.getFMatrix('sigma', 'sigma', 'psi', 'psi'), np.identity(2)).all()

# check identity matrices
assert np.isclose(ising.getFMatrix('psi', 'psi', 'psi', 'vacuum') @ ising.getFInv('psi', 'psi', 'psi', 'vacuum'), np.identity(2)).all()
assert np.isclose(ising.getFInv('psi', 'psi', 'psi', 'vacuum') @ ising.getFMatrix('psi', 'psi', 'psi', 'vacuum'), np.identity(2)).all()

@pytest.mark.model
def test_FinvRF(initialize_ising):
ising = initialize_ising

# check F with all sigma subscripts
assert np.isclose(ising.getFInvRF('sigma', 'sigma', 'sigma', 'sigma'), np.linalg.inv(ising.getFMatrix('sigma', 'sigma', 'sigma', 'sigma')) @ ising._r_mtx @ ising.getFMatrix('sigma', 'sigma', 'sigma', 'sigma')).all()

# check other non identity matrices
assert np.isclose(ising.getFInvRF('psi', 'sigma', 'sigma', 'vacuum'), np.linalg.inv(ising.getFMatrix('psi', 'sigma', 'sigma', 'vacuum')) @ ising._r_mtx @ ising.getFMatrix('psi', 'sigma', 'sigma', 'vacuum')).all()

# check identity matrices
assert np.isclose(ising.getFInvRF('psi', 'psi', 'psi', 'vacuum'), np.linalg.inv(ising.getFMatrix('psi', 'psi', 'psi', 'vacuum')) @ ising._r_mtx @ ising.getFMatrix('psi', 'psi', 'psi', 'vacuum')).all()

0 comments on commit 39d141d

Please sign in to comment.