ImportError when run on cluster
Posted: 11 Jul 2023, 15:37
Hi,
I'd been using TenPy in my project for a while. Up to now, I only run my code on my MacBook and PC(Ubuntu), and it works very fine. Now, I move the same code to run on the university cluster (CentOS7). After installing TeNPy from source, my code raised an ImportError due to circular import when run.
The cyclic seems to be within TeNPy structure. How should I solve this?
**EDIT**: Okay, I think I did something during installing from source. I've tried reinstall from conda-forge channel and the error has gone.
I'd been using TenPy in my project for a while. Up to now, I only run my code on my MacBook and PC(Ubuntu), and it works very fine. Now, I move the same code to run on the university cluster (CentOS7). After installing TeNPy from source, my code raised an ImportError due to circular import when run.
Code: Select all
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[1], line 7
4 os.environ["OMP_NUM_THREADS"] = "4"
6 from tenpy.tools.misc import setup_logging
----> 7 from utility_func import init_state
File /home/my_project/PhD_project/utility_func.py:3
1 import numpy as np
2 from tenpy.linalg import np_conserved as npc
----> 3 from tenpy.networks.site import SpinSite
4 from tenpy.models.lattice import Chain
5 from My_classes import get_MPDO, MyMPS
File /home/my_project/TeNPy/tenpy/networks/__init__.py:19
1 """Definitions of tensor networks like MPS and MPO.
2
3 Here, 'tensor network' refers just to the (parital) contraction of tensors.
(...)
15 purification_mps
16 """
17 # Copyright 2018-2023 TeNPy Developers, GNU GPLv3
---> 19 from . import site, mps, mpo, purification_mps
21 __all__ = ['site', 'mps', 'mpo', 'terms', 'purification_mps']
File /home/my_project/TeNPy/tenpy/networks/mps.py:168
166 from ..tools.cache import DictCache
167 from ..tools import hdf5_io
--> 168 from ..algorithms.truncation import TruncationError, svd_theta, _machine_prec_trunc_par
170 __all__ = ['BaseMPSExpectationValue', 'MPS', 'BaseEnvironment', 'MPSEnvironment', 'TransferMatrix',
171 'InitialStateBuilder', 'build_initial_state']
174 class BaseMPSExpectationValue(metaclass=ABCMeta):
File /home/my_project/TeNPy/tenpy/algorithms/__init__.py:23
1 """A collection of algorithms such as TEBD and DMRG.
2
3 .. rubric:: Submodules
(...)
19 disentangler
20 """
21 # Copyright 2018-2023 TeNPy Developers, GNU GPLv3
---> 23 from . import algorithm, truncation, dmrg, dmrg_parallel, disentangler, mps_common, tebd, tdvp, \
24 exact_diag, purification, network_contractor, mpo_evolution
26 __all__ = [
27 "algorithm",
28 "truncation",
(...)
38 "disentangler",
39 ]
File /home/my_project/TeNPy/tenpy/algorithms/dmrg.py:42
39 logger = logging.getLogger(__name__)
41 from ..linalg import np_conserved as npc
---> 42 from ..networks.mps import MPSEnvironment
43 from ..linalg.lanczos import lanczos, lanczos_arpack
44 from .truncation import truncate, svd_theta
ImportError: cannot import name 'MPSEnvironment' from partially initialized module 'tenpy.networks.mps' (most likely due to a circular import) (/home/my_project/TeNPy/tenpy/networks/mps.py)
**EDIT**: Okay, I think I did something during installing from source. I've tried reinstall from conda-forge channel and the error has gone.