joselado/dmrgpy

NameError: name 'jlsession' is not defined

Closed this issue · 1 comments

Hi!

I'm very happy to find a DMRG package that uses Python. I've cloned your repo to my Jupyter Notebook and when I run any of your example codes I get this error message:
NameError: name 'jlsession' is not defined

It seems like the only common error for all examples. I don't know what it is or how to fix it. Can you please help?

Here's the full error:

C++ backend not found, trying to run with Julia version

NameError Traceback (most recent call last)
in
3 n = 6 # number of different spinless fermionic orbitals
4 # fc is an object that contains the information of the many body system
----> 5 fc = fermionchain.Fermionic_Chain(n) # create the object
6 # h = 0
7 # create random hoppings

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/fermionchain.py in init(self, n)
19 # self.N = [self.Cdag[i]*self.C[i] for i in range(n)]
20 self.Id = self.get_operator("Id",1)
---> 21 Many_Body_Chain.init(self,[0 for i in range(n)])
22 self.fermionic = True
23 self.use_ampo_hamiltonian = True # use ampo

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/manybodychain.py in init(self, sites)
83 self.kpm_extrapolate_mode = "plain" # mode of the extrapolation
84 os.system("mkdir -p "+self.path) # create folder for the calculations
---> 85 self.initialize()
86 # and initialize the sites
87 def initialize(self):

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/manybodychain.py in initialize(self)
89 self.task = {"write_sites":"true"}
90 self.execute(lambda: write_sites(self)) # write the different sites
---> 91 self.run() # run the calculation
92 self.sites_from_file = True
93 def setup_julia(self):

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/manybodychain.py in run(self, automatic)
270 if not os.path.isfile(mpscpp): # mpscpp.x not found, rerun with julia
271 print("C++ backend not found, trying to run with Julia version")
--> 272 self.setup_julia() # turn to Julia
273 return self.run() # rerun with julia
274 from . import cpprun

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/manybodychain.py in setup_julia(self)
94 """Setup the Julia mode"""
95 self.itensor_version = "julia"
---> 96 self.initialize()
97 def setup_cpp(self):
98 """Setup the Julia mode"""

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/manybodychain.py in initialize(self)
89 self.task = {"write_sites":"true"}
90 self.execute(lambda: write_sites(self)) # write the different sites
---> 91 self.run() # run the calculation
92 self.sites_from_file = True
93 def setup_julia(self):

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/manybodychain.py in run(self, automatic)
265 elif self.itensor_version in ["julia","Julia","jl"]:
266 from . import juliarun
--> 267 juliarun.run(self)
268 return
269 else: raise

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/juliarun.py in run(self)
27 import contextlib
28 c = "@suppress_out include(""+dmrgpath+"/mpsjulia/mpsjulia.jl");"
---> 29 self.execute(lambda: jlsession.eval(c)) # evaluate Julia
30
31

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/fermionchain.py in execute(self, f)
129 from . import multioperator
130 multioperator.use_jordan_wigner = False
--> 131 return Many_Body_Chain.execute(self,f)
132
133

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/manybodychain.py in execute(self, f)
399 """Execute function in the folder"""
400 self.to_folder() # go to folder
--> 401 out = f()
402 self.to_origin() # go back
403 return out # return result

~/dmrgpy/examples/s12_chain/../../src/dmrgpy/juliarun.py in ()
27 import contextlib
28 c = "@suppress_out include(""+dmrgpath+"/mpsjulia/mpsjulia.jl");"
---> 29 self.execute(lambda: jlsession.eval(c)) # evaluate Julia
30
31

NameError: name 'jlsession' is not defined

Hi!

thanks for your nice feedback! Regarding the issue you mentioned, I think that the issue is that the code has not been compiled, so the code does find nor the C++ version nor the Julia interpreter. See below the instructions you have to follow

##################################
Execute the script

python install.py

and it will compile both ITensor and a C++ program that uses it. Alternatively, in case you just want to use the Julia version, execute the script

python install_julia.py
##################################

Best regards,
Jose