Running own model yields ModuleNotFoundError
Posted: 18 Dec 2019, 20:26
Hello all. Sorry if this is not the correct place to ask this.
So I've written my own model (the details of the model are not important for this question), and the relevant code is
The script of this code is called 'fqh_chain.py', and I've saved it in the directory
where all the other models are as well. I try calling it in another script (which is on my desktop) by running
and I get the error
Yet, when I call one of the pre-existing models, e.g.
I get no errors!
Does anybody know why this happens?
I am new to python 3, this is the first time I'm using it.
So I've written my own model (the details of the model are not important for this question), and the relevant code is
Code: Select all
import numpy as np
from .lattice import Lattice, Site, Chain
from ..networks.site import FermionSite
from .model import MultiCouplingModel, CouplingMPOModel
from ..tools.params import get_parameter
from ..tools.misc import any_nonzero
__all__ = ['FQHChain']
class FQHChain(CouplingMPOModel, MultiCouplingModel):
r""" Add details about the model here
"""
def __init__(self, model_params):
CouplingMPOModel.__init__(self, model_params)
def init_sites(self, model_params):
site = FermionSite(conserve='N')
return site
def init_lattice(self, model_params):
site = self.init_sites(model_params)
L = get_parameter(model_params, 'L', 2, self.name) # default values of parameters are currently arbitrary.
bc_MPS = get_parameter(model_params, 'bc_MPS', 'infinite', self.name)
bc = 'periodic' if bc_MPS == 'infinite' else 'open'
lat = Chain(L, site, bc=bc, bc_MPS=bc_MPS)
return lat
def init_terms(self, model_params):
V10 = get_parameter(model_params, 'V10', 1., name, asarray=True) # default values of parameters are currently arbitrary.
V20 = get_parameter(model_params, 'V20', 0.2, name, True)
V21 = get_parameter(model_params, 'V21', 0.5, name, True)
self.add_coupling(V10, 0, 'N', 0, 'N', 1)
self.add_coupling(V20, 0, 'N', 0, 'N', 2)
self.add_multi_coupling(-V21, 0, 'Cd', [(0, 'C', 1), (0, 'C', 2), (0, 'Cd', 3)] )
self.add_multi_coupling(-V21, 0, 'C', [(0, 'Cd', -1), (0, 'Cd', -2), (0, 'C', -3)] ) # h.c. of previous term
# done
Code: Select all
/Users/username/TeNPy/tenpy/models
Code: Select all
from tenpy.models.fqh_chain import FQHChain
Code: Select all
Traceback (most recent call last):
File "fqh_test.py", line 1, in <module>
from tenpy.models.fqh_chain import FQHChain
ModuleNotFoundError: No module named 'tenpy.models.fqh_chain'
Code: Select all
from tenpy.models.toric_code import ToricCode
Does anybody know why this happens?
I am new to python 3, this is the first time I'm using it.