Hamiltonian doesn't import from sympy properly
I tried importing Hamiltonian from a Mathematica code. I used following instructions to achieve that:
from qsymm.model import Model
from sympy.parsing import mathematica as M
import sympy
ham_txt = open("sympify-export-simple.txt","r")
ham_list = ham_txt.readlines()
ham=" ".join(ham_list).replace("*^","*10^(").replace("-10*I","-10)*I").replace("-10*k","-10)*k")
H_mat=M.parse_mathematica(ham)
H_sym=list(map(list,sympy.sympify(str(H_mat).replace("kx","k_x").replace("ky","k_y").replace("kz","k_z"))))
TBM=Model(hamiltonian=H_sym, momenta=('k_x', 'k_y', 'k_z'))
The replace
functions are only there to take care of some inaccuracies in parse_mathematica
function. sympify-export-simple.txt
was exported directly from a working Mathematica
code which gives accurate results.
The Hamiltonian was imported properly for a 8x8 matrix but this doesn't work well for a 256x256 matrix.
I got the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[3], line 1
----> 1 TBM=Model(hamiltonian=H_sym, momenta=('k_x', 'k_y', 'k_z'))
File ~/.conda/envs/kwant/lib/python3.11/site-packages/qsymm/model.py:215, in Model.__init__(self, hamiltonian, locals, momenta, keep, symbol_normalizer, normalize, shape, format)
213 hamiltonian = kwant_continuum.make_commutative(hamiltonian, *gens)
214 monomials = kwant_continuum.monomials(hamiltonian)
--> 215 monomials = {k: kwant_continuum.lambdify(v)()
216 for k, v in monomials.items()}
217 # remove matrices == zeros
218 monomials = {k: v for k, v in monomials.items()
219 if not np.allclose(v, 0)}
File ~/.conda/envs/kwant/lib/python3.11/site-packages/qsymm/model.py:215, in <dictcomp>(.0)
213 hamiltonian = kwant_continuum.make_commutative(hamiltonian, *gens)
214 monomials = kwant_continuum.monomials(hamiltonian)
--> 215 monomials = {k: kwant_continuum.lambdify(v)()
216 for k, v in monomials.items()}
217 # remove matrices == zeros
218 monomials = {k: v for k, v in monomials.items()
219 if not np.allclose(v, 0)}
TypeError: _lambdifygenerated() missing 2 required positional arguments: 'e' and 'k_x'
I'm not sure why this is happening. I tried to make those Hamiltonians mostly similar (except dimensionality). Please let me know what the problem might be.