joselado / dmrgpy

DMRGPy is a Python library to compute quasi-one-dimensional spin chains and fermionic systems using matrix product states with DMRG as implemented in ITensor. Most of the computations can be performed both with DMRG and exact diagonalization for small systems, which allows one to benchmark the results.
GNU General Public License v3.0
87 stars 20 forks source link

NameError: name 'jlsession' is not defined #6

Closed phyjswang closed 3 years ago

phyjswang commented 3 years ago

Dear Jose

After installing your dmrgpy, and try to run the first example given in README, I encounter the following error:

$ python test.py
C++ backend not found, trying to run with Julia version
Julia cannot be executed
Traceback (most recent call last):
  File "/home/jw-ubu/Github/dmrgpy/test.py", line 3, in <module>
    sc = spinchain.Spin_Chain(spins) # create spin chain object
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/spinchain.py", line 45, in __init__
    Many_Body_Chain.__init__(self,sites)
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/manybodychain.py", line 86, in __init__
    self.initialize()
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/manybodychain.py", line 92, in initialize
    self.run() # run the calculation
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/manybodychain.py", line 273, in run
    self.setup_julia() # turn to Julia
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/manybodychain.py", line 97, in setup_julia
    self.initialize()
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/manybodychain.py", line 92, in initialize
    self.run() # run the calculation
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/manybodychain.py", line 268, in run
    juliarun.run(self)
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/juliarun.py", line 29, in run
    self.execute(lambda: jlsession.eval(c)) # evaluate Julia
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/manybodychain.py", line 403, in execute
    out = f()
  File "/home/jw-ubu/miniconda3/envs/quantum/lib/python3.9/site-packages/dmrgpy/juliarun.py", line 29, in <lambda>
    self.execute(lambda: jlsession.eval(c)) # evaluate Julia
NameError: name 'jlsession' is not defined

Intest.py, I simply copied your example:

from dmrgpy import spinchain
spins = ["S=1/2" for i in range(30)] # spins in each site
sc = spinchain.Spin_Chain(spins) # create spin chain object
h = 0 # initialize Hamiltonian
for i in range(len(spins)-1): 
  h = h + sc.Sx[i]*sc.Sx[i+1]
  h = h + sc.Sy[i]*sc.Sy[i+1]
  h = h + sc.Sz[i]*sc.Sz[i+1]
sc.set_hamiltonian(h) # create the Hamiltonian
print("Ground state energy",sc.gs_energy())

So why the error? Also, why "C++ backend not found", since I should have installed it using python install.py successfully. BTW, ITensor works fine inside julia.

Best, Junsen

joselado commented 3 years ago

Dear Junsen,

thank you for your message and for the info on the error.

This error probably comes from the code not being able to compile when you executed "python install.py". One of the reasons could be that a suitable C++ compiler was not found, yet there could be some other reason. If you paste here the output that you get when compiling the code, I can check what is the reason for the code not compiling properly.

Best regards, Jose

phyjswang commented 3 years ago

Hi Jose,

Thank you for your reply.

As you mentioned, I didn't install LAPACK on my Ubuntu, since I thought it is irrelevant if I only use the Julia version of dmrgpy. However it turns out that this package is necessary.

For others who may encounter the same problem, I install it via

sudo apt-get install libblas-dev liblapack-dev

Now I can successfully run python test.py using both the C++ and Julia backend and obtain the expected result.

Best, Junsen