orthogonalize! crashing due to possible version issue -- a solution

I’m not asking a question, instead, I’ve run into a problem that I’ve found the answer to; however, I suspect my specific problem is one that future others may run into. So I’m posting it here so that it might show up in a google search, and save others a bunch of time:

In brief, I found that using Julia v1.4 and ITensor v0.2.16 and running the following code

#import Pkg; Pkg.add("ITensors");
using ITensors 

function main()

N = 4::Int
sites = siteinds("S=1/2",N);

psi = randomMPS(sites;linkdims=N)

b = 3
orthogonalize!(psi, b)
U,S,V = svd(psi[b], (linkind(psi, b-1), siteind(psi,b)))
SvN = 0.0
for n=1:dim(S, 1)
  p = S[n,n]^2
  SvN -= p * log(p)
end

println("SvN = ",SvN)

end#main
main()

crashes Julia. For me the crash occurred at orthogonalize!, which is a pretty crucial function when dealing with MPS. However, I found that I was otherwise able to run ITensor, including complete DMRG calculations as well as calculate inner products and construct MPO’s – so the fact this was a version error was not immediately obvious to me. The crash output looks as follows:

Illegal inttoptr
          %96 = ptrtoint double addrspace(13)* %94 to i64
Illegal inttoptr
          %109 = inttoptr i64 %108 to i8 addrspace(13)*

signal (6): Aborted
in expression starting at /home/pj/JuliaBloqade_pbc_Gap_SvN_BUGCHECK2.txt:23
gsignal at /usr/bin/../lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /usr/bin/../lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7fca9cbd7d04)
_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE at /usr/bin/../lib/x86_64-linux-gnu/libLLVM-8.so.1 (unknown line)
_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE at /usr/bin/../lib/x86_64-linux-gnu/libLLVM-8.so.1 (unknown line)
_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE at /usr/bin/../lib/x86_64-linux-gnu/libLLVM-8.so.1 (unknown line)
unknown function (ip: 0x7fca9ccc1ac1)
unknown function (ip: 0x7fca9ccc42d8)
unknown function (ip: 0x7fca9ccc48cd)
unknown function (ip: 0x7fca9cbffb4a)
unknown function (ip: 0x7fca9cc30ed3)
unknown function (ip: 0x7fca9cc5684b)
jl_apply_generic at /usr/bin/../lib/x86_64-linux-gnu/libjulia.so.1 (unknown line)
contract at /home/pj/.julia/packages/NDTensors/VAFvo/src/dense.jl:562
unknown function (ip: 0x7fca4350f00a)
contract at /home/pj/.julia/packages/NDTensors/VAFvo/src/dense.jl:550
_contract at /home/pj/.julia/packages/ITensors/5sSxp/src/itensor.jl:1740
_contract at /home/pj/.julia/packages/ITensors/5sSxp/src/itensor.jl:1746
contract at /home/pj/.julia/packages/ITensors/5sSxp/src/itensor.jl:1848
* at /home/pj/.julia/packages/ITensors/5sSxp/src/itensor.jl:1836
#svd#288 at /home/pj/.julia/packages/ITensors/5sSxp/src/decomp.jl:141
svd at /home/pj/.julia/packages/ITensors/5sSxp/src/decomp.jl:81
unknown function (ip: 0x7fca72b47bf5)
main at /home/pj/JuliaBloqade_pbc_Gap_SvN_BUGCHECK2.txt:13
unknown function (ip: 0x7fca72b46e6c)
unknown function (ip: 0x7fca9cc6975b)
unknown function (ip: 0x7fca9cc69389)
unknown function (ip: 0x7fca9cc698f0)
unknown function (ip: 0x7fca9cc6a9c8)
unknown function (ip: 0x7fca9cc6b616)
unknown function (ip: 0x7fca9cc83e08)
unknown function (ip: 0x7fca9cc5f105)
jl_load at /usr/bin/../lib/x86_64-linux-gnu/libjulia.so.1 (unknown line)
include at ./client.jl:439
unknown function (ip: 0x7fca9cc6975b)
unknown function (ip: 0x7fca9cc69389)
unknown function (ip: 0x7fca9cc698f0)
unknown function (ip: 0x7fca9cc6a9c8)
unknown function (ip: 0x7fca9cc6b616)
unknown function (ip: 0x7fca9cc83e08)
unknown function (ip: 0x7fca9cc843c8)
jl_toplevel_eval_in at /usr/bin/../lib/x86_64-linux-gnu/libjulia.so.1 (unknown line)
eval at ./boot.jl:331
eval_user_input at /build/julia-98cBbp/julia-1.4.1+dfsg/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
macro expansion at /build/julia-98cBbp/julia-1.4.1+dfsg/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:118 [inlined]
#26 at ./task.jl:358
unknown function (ip: 0x7fca9cc6ecbb)
unknown function (ip: (nil))
Allocations: 128555926 (Pool: 128528157; Big: 27769); GC: 127
Aborted (core dumped)

which I’ve included in case someone tries to google search.

The answer is to update Julia to the latest version (1.8.5 as of today). I’m running Ubuntu 20.04 LTS via the Windows Subsystem for Linux (WSL), and installed Julia via $ apt install julia in the terminal; however, this installed Julia v1.4 by default, and I couldn’t find a way to install a newer version using apt. Conveniently Julia can update itself using the UpdateJulia package, which one can do by typing:
import Pkg; Pkg.add("UpdateJulia"); using UpdateJulia; update_julia(systemwide=false)

Since I installed Julia v1.4 via apt, its binary executable is found in /bin or /usr/bin, so I only need to type $ julia in the terminal to enter REPL. However, I found that after updating Julia, the command $ julia still calls v1.4, and I was unable to locate the directory containing v1.8 binaries. (They were not in ~/.julia; in fact, there was no directory ~/.julia/bin where the internet tells me they belong. Nor were they in /bin.) Conveniently for me, I found that tab-complete (i.e typing $ julia in terminal without pressing ENTER but instead TAB) recognized the existence of a julia-1.8 as an option. So even though I can’t find the corresponding binaries anywhere, I can run the newest version via calling $ julia-1.8. For whatever magical reason, calling this once made it so that $ julia opens v1.8 by default now.

Once the update is complete, orthogonalize! runs without crashing, and life is again normal.

I hope this post is appropriate, and that someone who walks the same unfortunate path I did to installing Julia for ITensors finds this helpful.

Thanks for sharing this. Do I understand correctly that upgrading your Julia version solved the problem? We recommend using at least version 1.6 of Julia with ITensor currently. Glad to hear it’s working for you now –

To second Miles’ answer, everyone should be using at least Julia v1.6 and ITensors v0.3. We won’t be supporting versions below that. We don’t have the time or resources to support older versions, and if you use older versions and come across bugs you may just be out of luck :person_shrugging: (this is a general announcement, I realize you were trying to use a newer version and having trouble finding it).

Also, it seems like the community is going forward with juliaup as the standard way of installing Julia from the command line (I’ve been using UpdateJulia since I’m behind the times but have been meaning to move over to juliaup).

Yes it did. So the short answer is as you say – just be updated to a supported version of Julia. But it wasn’t clear that was the case initially, and my package manager tricked me into thinking I had the latest version of Julia. I just included this in case anyone who naively runs the older version and sees the same crash can find a quick solution without having to spend too long troubleshooting.