ITensor Support Q&A - Recent questions without answers
http://itensor.org/support/unanswered
Powered by Question2AnswerExponential of MPO
http://itensor.org/support/3928/exponential-of-mpo
<p>Hi,</p>
<p>So I've been trying to use this function: expHermitian(ITensor H, Cplx tau = 1)<br>
but the operator that I want to exponentiate is the total Sz. Here is the code that I have so far:</p>
<p><code>auto ampo2 = AutoMPO(sites);
for(auto k : range1(Nspins))
{
ampo2 += "Sz",k;
}
auto proj = toMPO(ampo2);
auto exp2H = expHermitian(proj,2);</code></p>
<p>but I get an error that the function expects an ITensor object as the first argument (as expected). Is it possible to somehow do what I am trying to do?</p>
<p>Thank you.</p>
http://itensor.org/support/3928/exponential-of-mpoFri, 23 Sep 2022 16:22:44 +0000about MixedSiteSet for electron and spin
http://itensor.org/support/3922/about-mixedsiteset-for-electron-and-spin
<p>Dear there,<br>
I want to use dmrg to solve a Hamiltonian which has couplied spin 1/2 operator and electron operator on same site. <br>
For example: H= a \sum{n} {Sx(n)C^dag<em>up(n)C</em>up(n)} + b\sum{n} {Sz(n)}.</p>
<p>After some searching, I found I need use MixedSiteSet. But so far, I only find a previous example for a Holstein-type new site set , which is: <br>
using Holstein = MixedSiteSet(ElectronSite,BosonSite);</p>
<p>And I saw in that answer, it mentions "the odd numbered sites will be electron sites and the even numbered sites will be boson sites". But in my case, I need electron and spin on same site. I'm not sure if this kind of MixedSiteSet already exits in Itensor or how could I construct this?</p>
<p>Thank you so much!!</p>
http://itensor.org/support/3922/about-mixedsiteset-for-electron-and-spinWed, 27 Jul 2022 23:59:53 +0000Julia related error in purification.jl code
http://itensor.org/support/3897/julia-related-error-in-purification-jl-code
<p>Hello,<br>
I am getting the following error while running <code>purification.jl</code>, strangely, it is working in REPL "<a rel="nofollow" href="https://replit.com/@scin/EnragedJadedNasm#main.jl">https://replit.com/@scin/EnragedJadedNasm#main.jl</a>". Could you please help me out in this ?</p>
<pre><code>β = 0.00 energy = 0.00000000
************
ERROR:
LoadError: MethodError: no method matching /(::MPO, ::Float64)
Closest candidates are:
/(::StridedArray{P, N} where N, ::Real) where P<:Dates.Period at /buildworker
/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Dates
/src/deprecated.jl:44
/(::Union{SparseArrays.SparseVector{Tv, Ti}, SubArray{Tv, 1, var"#s814",
Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, false} where var"#s814"
<:SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}, SubArray{Tv, 1, var"#s814",
Tuple{Base.Slice{Base.OneTo{Int64}}}, false} where var"#s814"
<:SparseArrays.AbstractSparseVector{Tv, Ti}} where {Tv, Ti}, ::Number) at
/buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/SparseArrays
/src/sparsevector.jl:1450
/(::Complex, ::Real) at complex.jl:333
...
Stacktrace:
[ 1] main(; N::Int64, cutoff::Float64, δτ::Float64, beta_max::Float64)
@ Main /media/test.jl:26
[2] main()
@ Main /media/test.jl:11
[3] top-level scope
@ /media/test.jl:30
in expression starting at /media/test.jl:30
</code></pre>
http://itensor.org/support/3897/julia-related-error-in-purification-jl-codeTue, 12 Apr 2022 06:56:14 +0000Unsuccesful TEBD for Time Independent Fermi-Hubbard Model
http://itensor.org/support/3883/unsuccesful-tebd-for-time-independent-fermi-hubbard-model
<p>I have been trying to recreate the dynamics of a driven Fermi-Hubbard Hamiltonian in Julia:</p>
<p>$$<br>
\hat{H}=-t_0 \sum_{j,\sigma}\left( e^{-i\Phi(t)}\hat{c}^{\dag}_{j,\sigma}\hat{c}<em>{j+1,\sigma} + h.c. \right)+\sum_{j} \hat{n}_{j,\uparrow}\hat{n}</em>{j,\downarrow}<br>
$$<br>
(don't know why this isn't formatting this is the Hamiltonian given by equation 12 in <a rel="nofollow" href="https://journals.aps.org/pra/abstract/10.1103/PhysRevA.101.053408">https://journals.aps.org/pra/abstract/10.1103/PhysRevA.101.053408</a> )</p>
<p>where @@ \sigma @@ is spin, but my first step is attempting this with @@\Phi(t)@@ set to 0, which results in an undriven, time independent model. I have successfully performed DMRG to obtain the ground state (which I know because I have compared energies to exact calculations in the QuSpin package), but I have been unsuccessful in using TEBD (and RK2 and RK4) to evolve the ground state using the time independent Hamiltonian. I know applying the time evolution operator as an exponential of the TI Hamiltonian to the ground state should preserve the ground state, but instead the energy of the state resulting from the application of the time evolution operator increases throughout the evolution. Though I have not tested dependence rigorously, the energy increase seems to be mostly independent of the time step even though it should be @@\mathcal{O}(\delta t)@@ according to <a rel="nofollow" href="https://www.sciencedirect.com/science/article/pii/S0003491619302532.">https://www.sciencedirect.com/science/article/pii/S0003491619302532.</a> I have implemented a dynamic time step as well, and tested a couple different maximum bond dimensions in DMRG, as well as decreasing the cutoff for both DMRG and the apply function. Any help is greatly appreciated, thanks in advance! My code is below:</p>
<pre><code>"""
Use second order TEBD to evolve psi(t) to psi (t + dt)
"""
function TEBD(psi, dt, time, params, independent, cutoff)
phi = phi_tl(time + dt / 2, params, independent)
# odd gates (1,2),(3,4),(5,6),...
ogates = ITensor[]
# even gates (2,3),(4,5),(6,7),...
egates = ITensor[]
for j=1:params.nsites
s1 = params.space[j]
#periodic BC
if j == params.nsites
s2 = params.space[1]
else
s2 = params.space[j+1]
end
# we have to define the two site operator so contributions
# of each site will be counted twice
ul = ur = params.U / 2
# exp(i phi(t)) and exp(-i phi(t))
eiphi = exp(1.0im * phi)
eiphiconj = conj(eiphi)
# create operator (only scaled parameters are passed in so t is always 1)
hj = -eiphiconj * op("Cdagup",s1) * op("Cup",s2) +
-eiphiconj * op("Cdagdn",s1) * op("Cdn",s2) +
-eiphi * op("Cdagup",s2) * op("Cup",s1) +
-eiphi * op("Cdagdn",s2) * op("Cdn",s1) +
ul * op("Nupdn", s1) * op("Id",s2) +
ur * op("Id",s1) * op("Nupdn", s2)
# odd gate
if j % 2 == 1
Gj = exp(-1.0im * dt * hj)
push!(ogates, Gj)
# even gate
else
Gj = exp(-1.0im * dt / 2 * hj)
push!(egates, Gj)
end
end
gates = ITensor[]
append!(gates, egates)
append!(gates, ogates)
append!(gates, egates)
return apply(gates, psi; cutoff=cutoff)
end
"""
Propogates ground from 0 to tf using method to propogate by an adaptive timestep
Parameters:
ground - ground state (MPS)
tf - final time
method - the function used to propogate a wavefunction over single dt
dti - initial guess for timestep
epsilon - total change allowed in a single time step
independent - boolean that is True if we are evolving with a time independent
Hamiltonian, and False otherwise
"""
function propogation(ground::MPS, params, tf, method, dti, epsilon, independent, cutoff)
# error measures (en is for current step, en1 is for previous step)
en = en1 = 0.0
time = 0.0
# copy states
psi = deepcopy(ground)
# set dt and previous dt
dt = pdt = dti
# initialize vectors for saving times and expectation values
times = [0]
energies = [inner(ground, get_ham(0, params, independent), ground)]
currents = [inner(ground, get_current(0, params, independent), ground)]
# run for the entire time interval
while time < tf
# get the MPS at time + dt
next_psi = method(psi, dt, time, params, independent, cutoff)
# calculate difference between current and next psi
en = difference(psi, next_psi)
# run propogation while the difference is greater than acceptable error
while en > epsilon
# adjust time step
dt *= epsilon / en
# get the next MPS and calculate difference
next_psi = method(psi, dt, time, params, independent, cutoff)
en = difference(psi, next_psi)
end
# incremement time and add it to the array
time += dt
times = vcat(times, [time])
# accept wavefunction
psi = deepcopy(next_psi)
# calculate expectations
energies = vcat(energies, [inner(psi, get_ham(time, params, independent), psi)])
currents = vcat(currents, [inner(psi, get_current(time, params, independent), psi)])
en1 = (en1 > 0) ? en1 : en
# adjust for next time step
# https://www.sciencedirect.com/science/article/pii/S0377042705001123
ndt = dt * ((epsilon^2 * dt)/ (en * en1 * pdt))^(1/12)
# update values for next iteration e_{n-1} -> e_n, dt_{n-1} = dt_n,
# dt_n -> dt_{n+1}
en1 = en
pdt = dt
dt = ndt
end
return times, energies, currents
end
</code></pre>
http://itensor.org/support/3883/unsuccesful-tebd-for-time-independent-fermi-hubbard-modelTue, 29 Mar 2022 23:17:57 +0000SPIN-SPIN CORREALTION FOR A TWO LEG LADDER MODEL
http://itensor.org/support/3821/spin-spin-correaltion-for-a-two-leg-ladder-model
<p>Hii,</p>
<p>I am doing DMRG of a two leg ladder model in ITensor julia.</p>
<p>I have calculated the ground sate energy and spin-spin correlation in 1D Heisenberg model and 1D Hubbard model and it gives correct ground state energy and spin-spin(Total spin on each site) .</p>
<p>However, when i calculated DMRG for a two leg ladder model (for 48*2 sites) , it appears the ground state energy is correct, but the spin-spin correlation is antiferromagnetic while the actual correlation should be ferromagnetic.</p>
<p>Here is the Hamiltonian of the code with parameters</p>
<pre><code>Nx=48
N= 2*Nx
sites=siteinds("Electron",N,conserve_qns=true,conserve_nf = true,conserve_sz=true,conserve_nfparity=false)
ampo =AutoMPO()
#intra-leg hopping
for j=1:2:(N-3)
ampo += -t,"Cdagup",j,"Cup",j+2
ampo += -t,"Cdagup",j+2,"Cup",j
ampo += -t,"Cdagdn",j,"Cdn",j+2
ampo += -t,"Cdagdn",j+2,"Cdn",j
ampo += -t,"Cdagup",j+1,"Cup",j+3
ampo += -t,"Cdagup",j+3,"Cup",j+1
ampo += -t,"Cdagdn",j+1,"Cdn",j+3
ampo += -t,"Cdagdn",j+3,"Cdn",j+1
end
#inter-leg hopping
p=1
for j =1:2:(N-1)
ampo += Q(p),"Cdagup",j,"Cup",j+1
ampo += conj(Q(p)),"Cdagup",j+1,"Cup",j
ampo += Q(p),"Cdagdn",j,"Cdn",j+1
ampo += conj(Q(p)),"Cdagdn",j+1,"Cdn",j
p=p+1
end
# On-site interaction
for j=1:N
ampo += U,"Nupdn",j
end
</code></pre>
<p>I kept the particle number fixed as i want to calculate ground sate energy at some particular electron density.</p>
<p>After performing the DMRG with the above Hamiltonian i calculate the spin-spin correlation in the following way</p>
<pre><code>xxcorr = correlation_matrix(psi,"S+","S-")
yycorr = correlation_matrix(psi,"S-","S+")
zzcorr = correlation_matrix(psi,"Sz","Sz")
zz = 0.5* xxcorr + 0.5 * yycorr + zzcorr
</code></pre>
<p>I calculate the spin-spin correlation for a reference site away from the boundary.</p>
<p>But as i mentioned i am not getting the correct spin-spin correlations(which is ferromagnetic for some given parameters).</p>
<p>So ,is there anything wrong in writing the Hamiltonian or in the correlation matrix ?</p>
<p>Thanks</p>
http://itensor.org/support/3821/spin-spin-correaltion-for-a-two-leg-ladder-modelMon, 14 Mar 2022 19:02:11 +00003-sites Hamiltonian time evolution of Julia
http://itensor.org/support/3687/3-sites-hamiltonian-time-evolution-of-julia
<p>Hello,I have read the question "Can I time-evolve the system with three-site interaction by using TEBD?" which was showed 6 days ago. Miles said the TDVP in Julia had not been done.I want to express my idea about it.<br>
Useing the <br>
<code>s = siteinds("electron",N;conserve_qns=true)</code><br>
to define the siteinds. We use its MPO because the one site in "electron" form suggests two electrons.We set a identity matrix to the first electron of first site and "three-site interaction" can be set on the rest of 3 electron.<br>
Maybe I don't express it clearly.If you can understand my mean,can you tell me the feasibility?</p>
<p>Best regards,<br>
cgh</p>
http://itensor.org/support/3687/3-sites-hamiltonian-time-evolution-of-juliaTue, 11 Jan 2022 03:07:26 +0000How to store pauli's matrices inside an index of a tensor
http://itensor.org/support/3660/how-to-store-paulis-matrices-inside-an-index-of-a-tensor
<p>Hey all! <br>
I am trying to write down an Hamiltonian of the form <code>Sum(J(i,j,a,b)*S(i,a)*S(j,b)</code><br>
where S is the spin operator <code>Sx+Sy+Sz</code> and J is just some normal rendom numbers, and i>j . <br>
So my problem is that I can't figure out how to store an array inside an index. For example I want that whan a.b= 1 I will get Sx a,b=2 I will get Sy and for a,b=3 I will get Sz. <br>
and to match a random number to each of them (J ). <br>
Can anyone please help me ? <br>
Thank you, Tomer </p>
http://itensor.org/support/3660/how-to-store-paulis-matrices-inside-an-index-of-a-tensorThu, 30 Dec 2021 18:03:29 +0000How do I set a minimum bond dimension when applying ITensors to an MPS?
http://itensor.org/support/3640/how-set-minimum-bond-dimension-when-applying-itensors-to-mps
<p>I'm looking for a way to tell ITensors to keep a certain minimum number of singular values when I apply a two-site operator to an MPS.<br>
I usually have an array <code>ops</code> of two-site ITensors, which I apply on an MPS <code>state</code> using <code>apply(ops, state; cutoff=err)</code>, but no matter how low I set <code>err</code>, I never see the bond dimension increasing.<br>
To be precise, I'm testing the evolution of a chain of 1/2-spins under a simple exchange Hamiltonian<br>
$$<br>
\sum_{i=1}^N(\sigma^+_j\sigma^-_{j+1}+\sigma^-_j\sigma^+_{j+1}),<br>
$$<br>
starting from a state with a single spin in the "up" state, the others in the "down" state; even with <code>err=1e-15</code> the bond dimensions never exceed 2.<br>
If I recall correctly, theoretically speaking it <em>could</em> be higher, at least in the more central sites, but it doesn't happen here. It may be that the entanglement along the chain is so low that the singular values other than the first two are genuinely very tiny, but I would like to include them anyway, for the sake of testing.</p>
<p>I see that the <code>svd</code> function in the library has the <code>mindim</code> keyword, so the option is there, but I can't find a way to use it when I call <code>product</code> or <code>apply</code>. </p>
http://itensor.org/support/3640/how-set-minimum-bond-dimension-when-applying-itensors-to-mpsFri, 10 Dec 2021 22:41:31 +0000finiteT calculation of 2d lattice
http://itensor.org/support/3622/finitet-calculation-of-2d-lattice
<p>Dear Itensor community</p>
<p>I have tried to extend the spin-1/2 chain finiteT example in the tutorial folder to a finiteT temperature calculation of 2D lattice (e.g: triangular lattice). Comparing with small 4*4 tiangular lattice with ED results, what I am getting is totally wrong. </p>
<p>Bellow you can find the code:</p>
<p>===========</p>
<h2>include "itensor/all.h"</h2>
<h2>include "TStateObserver.h"</h2>
<h2>include "S2.h"</h2>
<h2>include <math.h> /* sqrt */</h2>
<h2>include "itensor/util/print_macro.h"</h2>
<p>using namespace std;<br>
using namespace itensor;</p>
<p>int<br>
main(int argc, char* argv[])<br>
{</p>
<pre><code>//Get parameter file
if(argc != 2)
{
printfln("Usage: %s inputfile.",argv[0]);
return 0;
}
auto input = InputGroup(argv[1],"input");
//auto yperiodic = false;
auto Nx = input.getInt("Nx",4);
auto Ny = input.getInt("Ny",4);
auto N = Nx*Ny;
auto beta = input.getReal("beta",1);
auto tau = input.getReal("tau",0.01);
auto maxdim = input.getInt("maxdim",1000);
auto cutoff = input.getReal("cutoff",1E-11);
auto verbose = input.getYesNo("verbose",false);
Args args;
args.add("MaxDim",maxdim);
args.add("Cutoff",cutoff);
args.add("Verbose",verbose);
args.add("Method","DensityMatrix");
//args.add("Method","Fit");
//
// Initialize the site degrees of freedom.
//
auto sites = SpinHalf(2*N,{"ConserveQNs=",false});
//
// Use the AutoMPO feature to create the
// next-neighbor Heisenberg model.
//
auto ampo = AutoMPO(sites);
// 4*4 triangular lattice : bound between nearest neighbor sites
</code></pre>
<p>// sites with even number reserved for "ancilla", so lattice sites numbered in odd<br>
auto site1 = {1,1,1,3,3,3,5,5,5,7,9,9,9,11,11,11,13,13,13,15,17,17,17,19,19,19,21,21,21,23};<br>
auto site2 = {9,11,3,11,13,5,13,15,7,15,17,19,11,19,21,13,21,23,15,23,25,27,19,27,29,21,29,31,23,31};</p>
<pre><code> for(auto bnd : zip(site1,site2)){
auto [s1,s2] = bnd;
//printfln(" s1 : %i , s2 : %i ",bnd.s1,bnd.s2);
ampo += 0.5,"S+",s1,"S-",s2;
ampo += 0.5,"S-",s1,"S+",s2;
ampo += ,"Sz",s1,"Sz",s2;
}
auto H = toMPO(ampo);
auto expH = toExpH(ampo,tau);
auto S2 = makeS2(sites,{"SkipAncilla=",true});
//auto Sz2 = makeTotSz2(sites,{"SkipAncilla=",true});
//
// Make initial 'wavefunction' which is a product
// of perfect singlets between neighboring sites
//
auto psi = MPS(sites);
for(int n = 1; n <= 2*N; n += 2)
{
auto s1 = sites(n);
auto s2 = sites(n+1);
auto wf = ITensor(s1,s2);
wf.set(s1(1),s2(2), ISqrt2);
wf.set(s1(2),s2(1), -ISqrt2);
ITensor D;
psi.ref(n) = ITensor(s1);
psi.ref(n+1) = ITensor(s2);
svd(wf,psi.ref(n),D,psi.ref(n+1));
psi.ref(n) *= D;
}
auto obs = TStateObserver(psi);
auto ttotal = beta/2.;
const int nt = int(ttotal/tau+(1e-9*(ttotal/tau)));
if(fabs(nt*tau-ttotal) > 1E-9)
{
Error("Timestep not commensurate with total time");
}
printfln("Doing %d steps of tau=%f",nt,tau);
auto targs = args;
auto En = Vector(nt);
auto Sus = Vector(nt);
auto SzSz = Vector(nt);
auto Betas = Vector(nt);
Real tsofar = 0;
std::ofstream enf("en_cutoffE-10_dmrg.txt");
std::ofstream susf("sus_cutoffE-10_dmrg.txt");
for(int tt = 1; tt <= nt; ++tt)
{
psi = applyMPO(expH,psi,args);
//Normalize wavefunction
psi.ref(1) /= norm(psi(1));
//psi.noPrime().normalize();
tsofar += tau;
targs.add("TimeStepNum",tt);
targs.add("Time",tsofar);
targs.add("TotalTime",ttotal);
obs.measure(targs);
//Record beta value
auto bb = (2*tsofar);
Betas(tt-1) = bb;
//
// Measure Energy
//
auto en = inner(psi,H,psi);
En(tt-1) = real(en)/N;
SzSz(tt-1) = 0.0;//(SziSzj*bb/3.)/N;
printfln("\n Temp : %.4f, E/N :%.20f, Sus/N :%.20f",bb,en/N,Sus(tt-1));
enf << format("%.14f %.14f %.14f\n",Betas(tt-1), 1.0/Betas(tt-1), En(tt-1));
}
enf.close();
susf.close();
return 0;
}
</code></pre>
<p>=========== </p>
<p>Any comments or suggestion are welcome.</p>
<p>Regards<br>
Javad</p>
http://itensor.org/support/3622/finitet-calculation-of-2d-latticeWed, 08 Dec 2021 23:14:20 +0000How to initialize a random uniform MPS in thermodynamic limit?
http://itensor.org/support/3613/how-to-initialize-random-uniform-mps-in-thermodynamic-limit
<p>Hi,<br>
I want to initialize a random uniform MPS (i.e. all tensors of the MPS are identical) in thermodynamic limit so that I can neglect the contribution of two matrices at the left and right end. But I have failed do that. Please give me some hints. I am using C++ version.</p>
http://itensor.org/support/3613/how-to-initialize-random-uniform-mps-in-thermodynamic-limitTue, 23 Nov 2021 06:18:39 +0000overlap of two states in different QN sectors
http://itensor.org/support/3599/overlap-of-two-states-in-different-qn-sectors
<p>I'm studying tJ model and using julia. </p>
<p>I want to calculate an overlap between the ground state |FP> obtained at maximum Sz sector with the ground state |GS> at minimum |Sz| sector (either 0 or 1/2). For simplicity, let's assume that the number of electrons, N, is even, so that we are comparing the ground states of Sz = N/2 and Sz = 0. The overlap can be written as @@< GS | (S^-)^{N/2} |FP>@@, where @@S^- = \sum_{i=1}^{Lx*Ly}S_i^-@@.</p>
<p>I want to conserve the quantum numbers "N" and "Sz", so I constructed sites as follows.</p>
<pre><code>sites1 = siteinds("tJ", Lx; conserve_qns=true)
</code></pre>
<p>Then I computed ground state FP and GS at Sz = N/2 and Sz= 0 sector, respectively.</p>
<pre><code>psi_init_maxSz = InitState_Sz(Lx, N, N/2 , sites1);
energy_FP, FP = dmrg(H, psi_init_maxSz, sweeps)
</code></pre>
<p>and </p>
<pre><code>psi_init_minSz = InitState_Sz(Lx, N, (iseven(N) ? 0 : 1/2) , sites1);
energy_GS, GS = dmrg(H, psi_init_minSz, sweeps)
</code></pre>
<p>Now, since FP and GS are in different Sz sector, I removed QN conservation using dense() and constructed new sites 'sites2'.</p>
<pre><code>FPstate_maxSz = dense(FP)
sites2 = siteinds(FPstate_maxSz)
GS_minSz = dense(GS)
</code></pre>
<p>Also, I built the following @@S^-@@ MPO.</p>
<pre><code>function S_lowering(Lx,Ly, sites)
ampo = AutoMPO();
for i in 1:Lx*Ly
ampo += 1, "S-", i
end
return MPO(ampo, sites)
end
</code></pre>
<p>Finally, I performed the overlap calculation:</p>
<pre><code>Slowering = S_lowering(Lx, 1, sites2);
for i in 1:div(N,2)
FPstate_maxSz = contract(Slowering, FPstate_maxSz)
end
overlap= abs(inner(GS_minSz, FPstate_maxSz))
</code></pre>
<p>However, the expression </p>
<pre><code>FPstate_maxSz = contract(Slowering, FPstate_maxSz)
</code></pre>
<p>seems to cause infinite loop -- it doesn't stop so I have to force quit.<br>
What is wrong with this and is there a better way to achieve my goal?</p>
<p>Thanks a lot in advance. </p>
http://itensor.org/support/3599/overlap-of-two-states-in-different-qn-sectorsTue, 09 Nov 2021 00:15:09 +0000out of time order correlation function
http://itensor.org/support/3565/out-of-time-order-correlation-function
<p>Hey all, <br>
Is there someone in here knows is there is any code for out of time order correlation function ? or have been written one and can share </p>
http://itensor.org/support/3565/out-of-time-order-correlation-functionSat, 30 Oct 2021 11:19:47 +0000Convergence issues for small system sizes for the transverse field Ising model
http://itensor.org/support/3534/convergence-issues-system-sizes-transverse-field-ising-model
<p>I am a bit puzzled by strange convergence behavior of DMRG for the transverse field Ising model.</p>
<p>Using the Julia version, I am running the transverse field Ising model example for various system sizes N and the coupling h</p>
<pre><code>H = - \sum_{i} Z_i Z_{i+1} - h \sum_{i} X_i
</code></pre>
<p>My issue is that for certain values of h and N, the convergence seems to become very poor. I set energy tolerance of 1e-12 as a convergence criterion using a custom DMRGObserver, as shown in the documentation. For h>1.0, everything is good and DMRG converges very quickly. For example, even at critical h=1.0, I find it takes around ~10 sweeps.</p>
<p>However, for h=0.5, I notice that the convergence is very fast small N<10, but becomes quite poor for N~15, and then becomes very fast for N>24. For example, in a typical run, I find the following number of sweeps needed to reach an energy tolerance of 1e-12:</p>
<pre><code> Row │ N sweeps energy_tol
─────┼───────────────────────────
1 │ 6 7 9.3e-13
2 │ 8 14 7.2e-13
3 │ 10 23 8.2e-13
4 │ 12 55 4.3e-13
5 │ 16 100 2.0e-09
6 │ 24 4 1.4e-14
7 │ 32 4 3.1e-14
8 │ 48 4 3.2e-13
</code></pre>
<p>Note the rows for N=10,12,16. I am not sure what's happening at these intermediate values of N... why does the convergence suddenly become poor? This behavior depends on the coupling h. For example, in contrast to the above example, at h=1.0 (critical), there seems to be no problem and DMRG converges with very few sweeps (less than 10) within a tolerance of 1e-12 for N=6,..,48.</p>
<pre><code> Row │ N sweeps energy_tol
─────┼───────────────────────────
1 │ 6 4 9.7e-16
2 │ 8 6 1.4e-15
3 │ 10 5 8.7e-14
4 │ 12 6 9.5e-16
5 │ 16 6 3.3e-13
6 │ 24 8 9.6e-15
7 │ 32 11 4.9e-13
8 │ 48 12 4.7e-14
</code></pre>
<p>On the other hand, for h=0.2, I find that even L=6 has problem converging, but larger values of L become much better:</p>
<pre><code> Row │ N sweeps energy_tol
─────┼───────────────────────────
1 │ 6 100 2.5e-09
2 │ 8 36 6.9e-13
3 │ 10 3 2.6e-13
4 │ 12 4 1.1e-14
5 │ 16 3 4.0e-13
6 │ 24 4 5.5e-15
7 │ 32 4 1.5e-15
8 │ 48 4 5.4e-15
</code></pre>
<p>Larger h (greater than 1.0) seem to be all well behaved when I did a few spot checks. Does this behaviour make sense? My initial state is just a randomMPS. I tried playing with sweeps, both including noise and without. But that doesn't seem to matter very much. It's counter-intuitive to me that the problem is with small lattices, while larger ones do okay. Can you see what could be happening here? Thanks!</p>
http://itensor.org/support/3534/convergence-issues-system-sizes-transverse-field-ising-modelFri, 01 Oct 2021 22:41:45 +0000How to implement projector on Momentum eigenstates in Translational invariant system?
http://itensor.org/support/3495/implement-projector-eigenstates-translational-invariant
<p>Hi,<br>
essentially I am trying to measure the speed of sound in my system and for that I want to project an excited state onto a lattice momentum eigenstate. (In the Julia Version of ITensor)<br>
So I am looking at a spin-1/2 system that has translational invariance and N sites and would like to project certain states represented by an MPS with open boundary conditions onto states of definite lattice momentum via an projector of the form</p>
<p>@@P_l= \sum_k exp(2<em>\pi</em>i<em>k</em>l/N)T^k@@</p>
<p>where @@T^k@@ is a translator that acts as </p>
<p>@@T^k |s_1,s_2,...,s_N> = |s_{N-k+1},s_{N-k+2},...,s_{N-k}>@@</p>
<p>, so translating the spin configuration by k sites.<br>
I saw the function movesites but my impression from the documentation was that it just takes the tensor from one site and somehow puts it onto the new site, so the tensor that was on the new site gets lost. If I am mistaken please correct me.<br>
I thought that probably I can just multiply the sitetensors with delta tensors to change the index to change the siteindex to the translated one but then if I want to compute expectation values I will need to make a rather complicated multiplication. Therefore I wanted to know whether you know of a workaround to implement such a procedure for open boundary MPS, where I really get a MPS back that can be easily used afterwards? Or a nice other way to measure the speed of sound in the system?<br>
Best,<br>
Lev</p>
http://itensor.org/support/3495/implement-projector-eigenstates-translational-invariantFri, 17 Sep 2021 08:28:56 +0000DMRG for 2D Binary Spin-Lattice with a Specific Type of Hamiltonian (Julia)
http://itensor.org/support/3457/dmrg-binary-spin-lattice-with-specific-type-hamiltonian-julia
<p>Hello,<br>
I am quite new to Julia and ITensros lib and tensor networks overall. I have been studying them for a couple of weeks, yet I have some questions which I couldn’t resolve on my own. Sorry, if some of the questions are already mentioned in the documentation but couldn’t get the intuitive idea from there.</p>
<p>1) I want to approximate a 2D spin-lattice with dmrg. Spins are binary as 1 or 0. Is there a default configuration for this? If not, How can I define this from scratch?</p>
<p>2) This is one of the components I have in the Hamiltonian. Is it possible to define this with <em>OpSum()</em> and <em>ampo</em>? <img src="https://ibb.co/BTtq3M3" alt="Hamiltonian"></p>
<p>3) I have some other components in the Hamiltonian very similar to this one. How can I create <em>H = H1 + H2 + H3</em> for the overall Hamiltonian?</p>
<p>Hope I did not violate any rules. I am working on this for a project, so this is not a homework or exam problem. In case the image link is not working, I am adding one more: <img src="https://drive.google.com/file/d/1uUPB-K4vFbJ0JToJV7DPx9IjhiUlDP1C/view?usp=sharing" alt="Hamiltonian"></p>
<p>Direct Drive Link for image: <a rel="nofollow" href="https://drive.google.com/file/d/1uUPB-K4vFbJ0JToJV7DPx9IjhiUlDP1C/view?usp=sharing">https://drive.google.com/file/d/1uUPB-K4vFbJ0JToJV7DPx9IjhiUlDP1C/view?usp=sharing</a></p>
<p>Thanks in advance.</p>
http://itensor.org/support/3457/dmrg-binary-spin-lattice-with-specific-type-hamiltonian-juliaMon, 06 Sep 2021 06:53:49 +0000Multithreading different ITensor calculations
http://itensor.org/support/3416/multithreading-different-itensor-calculations
<p>Hi,</p>
<p>I have some difficulties using multithreading for my calculations which include tensor networks (in Julia). Just to clarify, I don't want to use multiple threads to speed-up contraction of large tensors, I want to evaluate a function for multiple configurations of parameters in parallel, and have each function call use ITensor for tensor contraction. </p>
<p>So far I tried to use the usual <code>Threads.@threads</code> at a beginning of a loop, but in each try I get a different error- sometimes one of the tensors end up with too many indices, which happen randomly at multiple places in the code, and sometimes one of the threads drink up all the memory of the cluster (in which case I couldn't pinpoint the exact place in the code which causes it).</p>
<p>If I don't use multithreading and just evaluate the function once at a time using a regular for loop I never had these problems. It seems as if the different threads interfere with each other and modify memory which the other threads use. I also tried to explicitly disable multithreading at levels of contractions with <code>BLAS.set_num_threads(1)</code>, but it didn't changed the results.</p>
<p>Am I doing something wrong? Do anyone know if there is might be some potential problems with multithreading function with ITensor calculations?</p>
<p>Thanks,<br>
Matan.</p>
http://itensor.org/support/3416/multithreading-different-itensor-calculationsWed, 01 Sep 2021 08:32:01 +0000Is it possible to add a fresh ancilla qubit in the middle of MPO/Locally Purified States? [Julia]
http://itensor.org/support/3197/possible-ancilla-qubit-middle-locally-purified-states-julia
<p>Hi,</p>
<p>I was wondering if the following would be possible: </p>
<ol>
<li>add a fresh ancilla qubit (initialized at state |0>) in the middle of/at the beginning/at the end of the MPO or MPS. </li>
<li>After adding the ancilla, run some time evolution in which the Hamiltonian couples the ancilla with the original sites. </li>
<li>After the time evolution, trace out the ancilla.</li>
</ol>
<p>I find that with PastaQ.jl one can use the LPDO but I don't know if there is any function that allows to add or trace out ancilla in one arbitrary location of the lattice. Any help/suggestions would be appreciated! </p>
http://itensor.org/support/3197/possible-ancilla-qubit-middle-locally-purified-states-juliaWed, 30 Jun 2021 09:23:30 +0000.svdBond() does not return spectrum
http://itensor.org/support/3116/svdbond-does-not-return-spectrum
<p>Hello,</p>
<p>I use the function .svdBond() and would like to obtain the truncation error. According to the documentation of this function, .svdBond() should return the corresponding spectrum containing information about the truncation error. However, I receive the error message "no match for ‘operator=’ (operand types are ‘itensor::Spectrum’ and ‘void’)", which indicates that .svdBond() does nor return any value. I suspect that I am missing something obvious but cannot resolve this problem.</p>
<p>Could you please help me with this problem?</p>
<p>Walter</p>
http://itensor.org/support/3116/svdbond-does-not-return-spectrumWed, 02 Jun 2021 12:48:57 +0000How to read multiple rows and multiple columns data using ITensor?
http://itensor.org/support/3102/read-multiple-rows-and-multiple-columns-data-using-itensor
<p>Dear all, I'm Meng. I want to know how to read data (for example 2 rows, 2 columns) from a file using itensor function directly? Although it can read the file data with the following C++ code, I guess itensor function maybe even simple and direct.</p>
<p>#include< iostream><br>
#include< fstream><br>
#include< typeinfo><br>
using namespace std;<br>
int main()<br>
{<br>
float data[2][2] = { 0 };<br>
ifstream infile;<br>
infile.open("file.dat");<br>
for (int i = 0; i < 2; i++)<br>
{<br>
for (int j = 0; j < 2; j++)<br>
{<br>
infile >> data[i][j];<br>
}<br>
}<br>
infile.close();</p>
<p>cout << data[0][0] << endl;<br>
cout << data[0][1] << endl;<br>
cout << data[1][0] << endl;<br>
cout << data[1][1] << endl;</p>
<p>return 0;<br>
}</p>
http://itensor.org/support/3102/read-multiple-rows-and-multiple-columns-data-using-itensorMon, 31 May 2021 22:02:36 +0000Transfer Matrix with iMPS (a further question)
http://itensor.org/support/3042/transfer-matrix-with-imps-a-further-question
<p>Dear ITensor,</p>
<p>I posted a question about this previously, but I thought I would create a new one since it was some time ago and I've made some progress. Please let me know if it would be better to just extend the original question.</p>
<p>I'm trying to calculate the fidelity per unit cell of an iMPS using a transfer matrix. From what I understand, the result of your idmrg code should be multiplied by psi(0) (at psi(1)) to give the orthogonalised wavefunction. I've implemented a class to use with arnoldi, which has the product function shown below. I've been testing it with a simple transverse Ising model. The MPSs psi1 and psi2 are stored in the class, which modifies them to have matching site indices and primes the links of psi2.</p>
<pre><code>void TMatrix::product(ITensor &other, ITensor &result) {
result = ITensor(other);
result = result * dag(psi1(0));
result = result * psi2(0);
for (int i = 1; i <= length(psi1); i++) {
result = result * dag(psi1(i));
result = result * psi2(i);
}
// "Fix" the indices (probably a bad idea). This runs with QNs but gets the wrong result.
//result = result.dag();
//result = result.conj();
// This gets nearly the correct result (using the PseudoInvert function from idmrg.h)
//auto z1 = psi1(0);
//auto z2 = dag(psi2(0));
//z1.apply(PseudoInvert(0));
//z2.apply(PseudoInvert(0));
//result *= z1;
//result *= z2;
}
</code></pre>
<p>However, this results in runtime errors with QN conservation enabled, as psi1(0) has both indices pointing "out" (as expected since it's the centre of an svd), which results in the leftmost link being flipped. It still doesn't get correct results with QNs disabled.</p>
<p>I tried a couple of things (commented out above): the first is to "fix" the link index so the multiplication works. However this produces incorrect results, out by a factor of 1/2. The other idea was to apply the inverse of psi(0) at the end of the product function, which results in an acceptable contraction of the indices and produces something very close to the correct result. I don't understand why this is the case, however. </p>
<p>I've studied various other questions here as well as the code in idmrg.h (which I understand only partially), but I don't seem to be able to get any further. Do you have any suggestions?</p>
<p>Thank you as always for your work on ITensor</p>
http://itensor.org/support/3042/transfer-matrix-with-imps-a-further-questionTue, 11 May 2021 02:16:45 +0000readFromFile() for custom mixed SiteSet
http://itensor.org/support/3025/readfromfile-for-custom-mixed-siteset
<p>Dear ITensor Team,</p>
<p>I have a problem with the readFromFile(FileName, sites) function. I am using a custom SiteSet "OpenSystemSite", which is a mixture of bosonic and fermionic sites. <br>
When compiling, the function throws an error</p>
<p>error: no matching function for call to ‘read(std::ifstream&, itensor::OpenSystemSite<itensor::BosonSiteOpen, itensor::ElectronSite>&)’</p>
<p>Reading in the MPS created on this SiteSet seems to work fine.<br>
Is the build-in function readFromFile() just not compatible with a mixed SiteSet or do you have an idea how I could fix this?</p>
<p>Best wishes and thanks for the great work on Itensor!</p>
<p>Luisa</p>
http://itensor.org/support/3025/readfromfile-for-custom-mixed-sitesetWed, 05 May 2021 06:31:37 +0000How to create and add MPS
http://itensor.org/support/2968/how-to-create-and-add-mps
<p>Hello there,</p>
<p>Sorry for the newbie question (and if that has been answered elsewhere but I haven't found approaching solutions) but here it is:</p>
<p>I want to create 2 MPS in Julia and add them. The first question is that I would like to customise the core MPS. As such, my first and last core MPS are different from the others in the indices they hold. Is there a way to do that ? I.e. do I have to create a MPS with say N sites and then customise one by one like MPS<a rel="nofollow" href="https://arxiv.org/pdf/2005.04351.pdf">1</a> = CustomTensor1; MPS[2] = CustomTensor2, etc... ? Then, I am not sure how would ITensor resolve the indexing then.</p>
<p>The other question is how to change the link dimension ? I heard about <code>pluss*</code> but not sure it was for Julia.</p>
<p>Finally, if I solve question 1 I assume I'd be able to sum them together. However, is that sum equivalent to the operations described in that <a rel="nofollow" href="https://arxiv.org/pdf/2005.04351.pdf">article</a> (bottom of page 7, top page 8) ? </p>
<p>Thanks for your help, that is really appreciated.</p>
<p>Kind regards,</p>
<p>Roland</p>
http://itensor.org/support/2968/how-to-create-and-add-mpsThu, 15 Apr 2021 14:01:58 +0000TDVP with time dependent term
http://itensor.org/support/2878/tdvp-with-time-dependent-term
<p>Hi all,<br>
I was trying to use the one center TDVP algorithm to study a system with a time-dependent term that is not part of the Hamiltonian. The overall system evolution is described by <br>
$$\dot y = H y + f(t)$$<br>
where y is the state, H the Hamiltonian, and f(t) is a time dependent vector. How should I modify the original TDVP code to treat this case?</p>
<p>Thanks,<br>
Raffaele</p>
http://itensor.org/support/2878/tdvp-with-time-dependent-termSun, 21 Feb 2021 09:12:32 +0000Is there a method that gives the quantum number flux of a particular element in an ITensor
http://itensor.org/support/2844/there-method-gives-quantum-number-particular-element-itensor
<p>From this answer</p>
<p><a rel="nofollow" href="http://itensor.org/support/2799/are-there-methods-for-returning-value-for-mps-or-flux-for-mpo">http://itensor.org/support/2799/are-there-methods-for-returning-value-for-mps-or-flux-for-mpo</a></p>
<p>I realized that one can use the "flux" function to get the quantum number flux of an ITensor. However I wonder if there is a method to get the quantum number flux <em>for a particular element</em> in an ITensor?</p>
http://itensor.org/support/2844/there-method-gives-quantum-number-particular-element-itensorSun, 07 Feb 2021 16:11:38 +0000A partial fix of arnoldi
http://itensor.org/support/2843/a-partial-fix-of-arnoldi
<p>Hi Matthew,</p>
<p>The <a rel="nofollow" href="https://github.com/ITensor/ITensor/issues/360">issue#360</a> in <code>arnoldi</code> function is because of an extra multiplication of <code>A</code> in <a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/fb83fde4a07f2122cf56f9a79f8e8ec01c7cad18/itensor/iterativesolvers.h#L809">the deflation</a>.</p>
<p>The current (incorrect) <code>arnoldi</code> calculates instead the first eigenvalues of <code>A</code> and <code>A-A^2</code>. That's why in <a rel="nofollow" href="https://github.com/ITensor/ITensor/issues/360">issue#360</a> the two eigenvectors are identical and the eigenvalues <br>
<code>lambda0 = (0.598975,0)
lambda1 = (0.240204,0)</code><br>
satisfy <code>lambda1 = lambda0 - lambda0^2</code>.</p>
<p>A minor pull request has been submitted <a rel="nofollow" href="https://github.com/ITensor/ITensor/pull/382">here</a>.</p>
<p>However, even after this fix the <code>arnoldi</code> function can only deal with Hermitian operator. Because the current deflation process cannot project to the correct subspace if the previously calculated eigenvectors are not orthogonal.</p>
<p>Ce</p>
http://itensor.org/support/2843/a-partial-fix-of-arnoldiSun, 07 Feb 2021 03:13:35 +0000initialize an ITensor from allocated memory
http://itensor.org/support/2842/initialize-an-itensor-from-allocated-memory
<p>Hi, </p>
<p>Is there any way to create an ITensor "in place" from some already allocated memory?</p>
<p>For example</p>
<pre><code>const int nx = 10;
const int ny = 10;
double* arr = new double[nx * ny] ;
Index i(nx);
Index j(ny);
ITensor A(i, j); //the storage is not yet initialized.
</code></pre>
<p>Currently I only know how to copy this allocated memory to the data vector of A as following</p>
<pre><code>vector_no_init<double>& dvec = (*((ITWrap<Dense<double>>*) & (*A.store()))).d.store;
dvec.assign(arr, arr + nx*ny);
</code></pre>
<p>What I'd like to do is to "steal" the allocated memory from <code>arr</code> and use that as the internal data vector of <code>A</code>. Although <code>memcpy</code> is in general very fast, sometimes we still want to avoid this overhead in case it is a huge <code>for</code> loop.</p>
<p>There's <a rel="nofollow" href="https://stackoverflow.com/questions/21917529/is-it-possible-to-initialize-stdvector-over-already-allocated-memory">some instruction</a> on how to steal the memory by overloading the allocator. But the data vector's allocator has already been overloaded as in the definition of <a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/fb83fde4a07f2122cf56f9a79f8e8ec01c7cad18/itensor/util/vector_no_init.h#L24">vector no init</a>. </p>
<p>Do you have any idea how to combine the two overloaded versions of allocator, s.t. it can work as described above?</p>
<p>Ce</p>
http://itensor.org/support/2842/initialize-an-itensor-from-allocated-memorySun, 07 Feb 2021 02:51:04 +0000[Julia] Largest truncation error in DMRG output
http://itensor.org/support/2818/julia-largest-truncation-error-in-dmrg-output
<p>Hi,</p>
<p>I've been using the julia version of ITensor lately, and I noticed that calling DMRG by default does not print any information regarding the maximum truncation error for each sweep, unlike the C++ version. I've searched the documentation but could not find anything related to the truncation error. Is there some way to turn this feature on? Or is it just not implemented yet?</p>
<p>Best,</p>
<p>Rafael</p>
http://itensor.org/support/2818/julia-largest-truncation-error-in-dmrg-outputTue, 02 Feb 2021 23:59:38 +0000Random Initial state for julia version?
http://itensor.org/support/2748/random-initial-state-for-julia-version
<p>I am trying to find the ground state for a 2D Heisenberg hamiltonian. I want to use different initial states. I read the answers/ discussions regarding the same.</p>
<p>How can I build the random state on X basis? ( maybe using Hadamard as mentioned in other discussions) for the Julia version?</p>
http://itensor.org/support/2748/random-initial-state-for-julia-versionTue, 15 Dec 2020 22:04:49 +0000Calculating correlations for fermions with spin
http://itensor.org/support/2707/calculating-correlations-for-fermions-with-spin
<p>Hi!<br>
I'm using the following code to calculate correlations of the type cdagup(i) cup(j) and take its log. I'm using Electron sites with {"ConserveSz=",false}</p>
<pre><code>auto ampo2 = AutoMPO(sites);
auto i = 100;
for(auto j=200;j<250;j++)
{
ampo2 += 1,"Cdagup",i,"Cup",j;
auto mpo = toMPO(ampo2);
auto result = innerC(psi,mpo,psi);
outfile<<i<<", "<<j<<", "<<log(abs(i-j))<<", "<<log(abs(result))<<"\n";
ampo2 = AutoMPO(sites);
}
outfile.close();
</code></pre>
<p>The answer depends on whether j is even or odd for a fixed i. Here is a small excerpt from the output. The log of the correlations are higher when j is odd.</p>
<p>i, j, Log(|i-j|), Log|cdagup(i) cup(j)| are printed below</p>
<p>100, 200, 4.60517, -8.32898<br>
100, 201, 4.61512, -6.1358<br>
100, 202, 4.62497, -8.33054<br>
100, 203, 4.63473, -6.1581<br>
100, 204, 4.64439, -8.33459<br>
100, 205, 4.65396, -6.17968<br>
100, 206, 4.66344, -8.34129<br>
100, 207, 4.67283, -6.20057</p>
<p>What is the reason for this? Is this a proper way to calculate the correlations?</p>
http://itensor.org/support/2707/calculating-correlations-for-fermions-with-spinSun, 29 Nov 2020 13:02:47 +0000Problem with nmultMPO on large Fermionic chain
http://itensor.org/support/2698/problem-with-nmultmpo-on-large-fermionic-chain
<p>Hi Miles&Matt,</p>
<p>I am encountering a problem with the nmultMPO function on the following minimal example:</p>
<pre><code> auto N=257;
auto sites = Electron(N);
auto ampo = AutoMPO(sites);
ampo += 1.0, "Ntot",2;
auto H = toMPO(ampo);
auto H2 = nmultMPO(H,prime(H));
</code></pre>
<p>For me this code works for N<257, but nmultMPO fails for N>=257 with the error message:<br>
terminate called after throwing an instance of 'std::runtime_error'<br>
what(): Error condition in diagHermitian<br>
Aborted (core dumped)</p>
<p>The same also happens for a less artificial Hamiltonian. For the Fermion SiteSet<br>
I observe something similar. However, instead of an error message nmultMPO seems to return just a zero MPO here (again, small systems work fine).<br>
Do you know where the problem could come from?<br>
I would appreciate any help.</p>
<p>Best regards,<br>
Lucas</p>
http://itensor.org/support/2698/problem-with-nmultmpo-on-large-fermionic-chainSun, 15 Nov 2020 00:45:35 +0000How to calculate string operator in ITensor2?
http://itensor.org/support/2632/how-to-calculate-string-operator-in-itensor2
<p>Hi ITensor team,<br>
Thanks for your wonderful software ! I want to calculate Haldane string operator correlation function, so I want to define string operator, for example <\prod<em>{n<I}exp(I\pi S</em>{n}^{z})S^{z}_{I}>.if I have string operator, then I can calculate correlation function as spin correlation function. But I don't know how to exponential operator Sz(maybe MPO). my naive partial code as follow:</p>
<p>auto phi1=expHermitian(sites.op("Sz",1),PI<em>Cplx_i);<br>
auto phi2=expHermitian(sites.op("Sz",1),PI</em>Cplx_i);</p>
<p>for(int n = 2; n < N/4; ++n)<br>
{<br>
phi1 <em>=expHermitian(sites.op("Sz",n),PI</em>Cplx_i);<br>
print(phi1);<br>
}<br>
auto Ss1 = phi1*sites.op("Sz",N/4);</p>
<p>for(int n = 2; n < 3<em>N/4; ++n)<br>
{<br>
phi2 *=expHermitian(sites.op("Sz",n),PI</em>Cplx_i);<br>
}<br>
auto Ss2 = phi2*sites.op("Sz",3*N/4);</p>
<p>Ss1 and Ss2 is string operator at N/4 and 3*N/4. BUT this code does't work. Please help me to check. Thank you !</p>
http://itensor.org/support/2632/how-to-calculate-string-operator-in-itensor2Thu, 22 Oct 2020 13:21:57 +0000Is there some built-in generalization of KrylovKit.eigsolve that optimizes over multiple input vectors?
http://itensor.org/support/2593/generalization-krylovkit-eigsolve-optimizes-multiple-vectors
<p>I know that the KrylovKit.eigsolve Julia function can find a vector @@x@@ to maximize or minimize @@x^\dagger Ax@@ for a fixed matrix @@M@@. We can think of this in index notation as @@M_{\alpha\beta}x^\alpha\overline{x}^\beta@@, where the bar denotes complex conjugation.</p>
<p>What I am wondering is: does some common package in Julia have a built-in generalization of this method that optimizes over multiple input vectors? For instance, is there a built-in function that finds vectors @@x@@ and @@y@@ to maximize or minimize @@M_{\alpha\beta\gamma\delta}x^\alpha\overline{x}^\beta y^\gamma\overline{y}^\delta@@?</p>
<p>In case you're wondering why I'm asking, basically I am wondering whether it is possible to do a single optimization step over two non-adjacent sites in a way that keeps them unliked, because if you just multiply the two tensors together and then optimize that, then it will introduce a link between those sites. Basically I want to just do this step once in a while to see whether it is possible to fix some problems with my trial Schwinger model (as I have already discussed in some other questions on this website).</p>
http://itensor.org/support/2593/generalization-krylovkit-eigsolve-optimizes-multiple-vectorsFri, 09 Oct 2020 14:25:18 +0000How to implement symmetry which anticommutes with hamiltonian
http://itensor.org/support/2510/how-implement-symmetry-which-anticommutes-with-hamiltonian
<p>Dear community,</p>
<p>How is it possible to implement the conservation of an anti-block structure for {H,U} = 0? </p>
<p>Let us consider for instance the example H = ∑ σˣᵢ + ∑ σˣᵢ σˣⱼ σˣₖ with U = ∏ σˣᵢ where the z-parity only anticommutes with the hamiltonian. Right now I am implementing this using the square of the Hamiltonian, since then [H²,U]=0 and we can use regular quantum numbers; however, this is a very bad solution. Can you think of a better way?</p>
<p>Best,</p>
<p>v.</p>
http://itensor.org/support/2510/how-implement-symmetry-which-anticommutes-with-hamiltonianFri, 11 Sep 2020 09:53:01 +0000How to measure the momentum of an MPS?
http://itensor.org/support/2319/how-to-measure-the-momentum-of-an-mps
<p>Hi,</p>
<p>I was trying to measure the momenta of some MPSs in the Electron site class. Here is my attempt:</p>
<p>I got the desired results when I measure the momentum @@P@@ using toMPO. However, when I used the function toExpH to exponentiate the momentum operator and get the usual translation operator @@T@@, I got the following error message:</p>
<pre><code>From line 885, file itensor.cc
div(T1)=QN({"Nf",0,-1},{"Sz",0}) must equal div(T2)=QN({"Nf",1,-1},{"Sz",-1}) when adding T1+T2
div(T1)=QN({"Nf",0,-1},{"Sz",0}) must equal div(T2)=QN({"Nf",1,-1},{"Sz",-1}) when adding T1+T2
Aborted (core dumped)
</code></pre>
<p>I wasn't able to figure out what this message is saying? Also is this the right way to measure the momenta of some MPSs, and is this the best way to exponentiate some MPO? Below is the code for obtaining the MPOs for the operators @@P@@ and @@T@@.</p>
<pre><code># define PI 3.1415926535897932
MPO Momentum(Electron const& sites)
{
auto N = length(sites);
auto ampo = AutoMPO(sites);
for(int k = 1; k <= N; ++k)
{
for(int i = 1; i <= N; ++i)
{
for(int j = 1; j <= N; ++j)
{
ampo += 2.0*PI/(N*N)*k*std::exp(Cplx_i*2.0*PI/N*k*(i-j)),"Cdagup",j,"Cup",i;
ampo += 2.0*PI/(N*N)*k*std::exp(Cplx_i*2.0*PI/N*k*(i-j)),"Cdagdn",j,"Cdn",i;
}
}
}
auto T = toExpH(ampo,1.0,{"Cutoff=",1E-20});
auto P = toMPO(ampo,{"Cutoff=",1E-20});
return T; //or P
}
</code></pre>
<p>Thanks,<br>
WunderNatur</p>
http://itensor.org/support/2319/how-to-measure-the-momentum-of-an-mpsThu, 02 Jul 2020 07:23:23 +0000Unable to adjust last site due to local constraint with neighbors --> Is it possible to "rotate" a state? (Julia)
http://itensor.org/support/2295/unable-adjust-constraint-neighbors-possible-rotate-julia
<p>I am interested in developing on ITensors.jl the lattice Schwinger model with alternating (anti)fermion sites and links (representing electric flux). Each spatial site has 4 ITensors sites--first a fermion site, then a link, then an antifermion site, and then another link. It incorporates a local constraint given by Gauss's Law, and I've gotten it to mostly work (I think) by using a few tricks.</p>
<p>However, I am still running into one problem. Basically, the smallest "unit" that you can change without changing anything else is a unit consisting of two (anti)fermion sites and the link between them. For example, I can change sites 1-3 without changing anything else; similar for 3-5, 5-7, etc. This is why I run 3-site DMRG (this isn't natively in ITensors; I developed this code and have put a pull request for it here: <a rel="nofollow" href="https://github.com/ITensor/ITensors.jl/pull/434).">https://github.com/ITensor/ITensors.jl/pull/434).</a> However, this spells trouble when you reach the end. One of the "units" that you should be able to change is that consisting of sites 4N-1, 4N, and 1, where N is the number of spatial sites. However, DMRG doesn't do such a thing, because it only works on a bundle of adjacent sites. This means that, due to the Gauss's Law constraint enforced by sites 4N, 1, and 2, site 4N is stuck unless one also changes either site 1 or site 2, which only happens if one uses k-site DMRG for k=4N-1 or 4N (i.e. adjusting the whole state, minus at most one site, in each step). For example, for 2 spatial sites, I need 7-site DMRG to be able to change site 8 at all, and for 3 spatial sites, I need 11-site DMRG. This is simply infeasible for any lattice larger than 3 spatial sites.</p>
<p>I am wondering whether anyone has any ideas about how to handle this or has dealt with something similar before. One idea I had was "rotating" the state between or during sweeps in the DMRG process, so that every site has at least some time not being the one at the end, which is stuck in place. As an example, one could "rotate" the state so that the last two sites are now the first two, and then sites 4N, 1, and 2 (which are now sites 2-4), are together and can be optimized. And then one can rotate the state back and complete the rest of the sweep. But I'm not sure how one would do such a thing, or whether it would really produce the desired results. Does anyone know of a feasible fix for this, whether by rotating the state or by any other means?</p>
<p>It is true that this error should in principle become relatively small for a sufficiently large number of spatial sites, but in my research, I will mostly be working with fairly small lattices, for which such limits won't apply. Also, I need my code to be accurate in finding the ground state so that I can accurately evaluate excited states, as well as assess my code against existing results on the Schwinger model produced using other computational methods (e.g. exact diagonalization). Any help on this would be greatly appreciated.</p>
http://itensor.org/support/2295/unable-adjust-constraint-neighbors-possible-rotate-juliaMon, 29 Jun 2020 05:04:14 +0000Loop over Args
http://itensor.org/support/2293/loop-over-args
<p>Hello, </p>
<p>Is there a way to loop over the Args elements?</p>
<pre><code>for(Val const & a: args){
//Do something with a
}
</code></pre>
<p>I'm using Args to simplify the construction of operators. Since this construction is quite general, I don't know what Args have been added so I would like to loop over all elements. Thank you very much.</p>
<p>Best,<br>
João</p>
http://itensor.org/support/2293/loop-over-argsSun, 28 Jun 2020 17:12:56 +0000std::bad_alloc when measuring two point correlation functions with periodic boundary condition.
http://itensor.org/support/2246/bad_alloc-measuring-correlation-functions-boundary-condition
<p>Hi Miles,</p>
<p>I am working with a 20-site electron system with periodic boundary condition. I obtained the ground state with dmrg and measure the spin correlation functions following <a rel="nofollow" href="http://itensor.org/docs.cgi?vers=cppv3&page=formulas/correlator_mps">this formula</a>. However, when the largest bond dim @@\gtrsim 500@@, I always got the error message </p>
<pre><code>terminate called after throwing an instance of 'std::bad_alloc'
</code></pre>
<p>If I run the code in gdb, I got the following error message:</p>
<pre><code>Program received signal SIGABRT, Aborted.
0x00007ffff640570f in raise () from /lib64/libc.so.6
</code></pre>
<p>This seems to be an issue of running out of memory. However, I have ~400G memory and this program seems only using @@\gtrsim@@10G memory. I am not sure whether this is an issue of my code or I really run out of memory. The relevant part of the code is the following function:</p>
<pre><code>Real TwopointCorrelation(const Electron& sites, MPS& psi, string Opi, string Opj, int site_i, int site_j)
{
int N = length(sites);
auto op_i = op(sites,Opi,site_i);
auto op_j = op(sites,Opj,site_j);
//'gauge' the MPS to site i
//any 'position' between i and j, inclusive, would work here
psi.position(site_i);
//Create the bra/dual version of the MPS psi
auto psidag = dag(psi);
//Prime the link indices to make them distinct from
//the original ket links
psidag.prime("Link");
//index linking i-1 to i:
auto li_1 = leftLinkIndex(psi,site_i);
auto C = prime(psi(site_i),li_1) * op_i * prime(psidag(site_i),"Site");
for(int k = site_i+1; k < site_j; ++k)
{
C *= psi(k) * psidag(k);
}
//index linking j to j+1:
auto lj = rightLinkIndex(psi,site_j);
C *= prime(psi(site_j),lj) * op_j * prime(psidag(site_j),"Site");
auto result = elt(C); //or eltC(C) if expecting complex
return result;
}
</code></pre>
<p>Thank you so much!<br>
WunderNatur</p>
http://itensor.org/support/2246/bad_alloc-measuring-correlation-functions-boundary-conditionSun, 21 Jun 2020 23:18:07 +0000Questions about spin and charge gap on Holstein-Hubbard model
http://itensor.org/support/2229/questions-about-spin-and-charge-gap-holstein-hubbard-model
<p>I'm following an article: arXiv:0808.1675. When I calculate the spin and charge gap of Fig.2, I can't get the correct answer,my codes is:</p>
<pre><code>#include "itensor/all.h"
</code></pre>
<p>using namespace itensor;</p>
<p>int<br>
main()<br>
{<br>
using Holstein =MixedSiteSet<ElectronSite,BosonSite>;<br>
auto N=60;<br>
auto U=1.0;<br>
auto t=1.0;<br>
auto eplison=1.25;<br>
auto omega=5.0;<br>
auto sites=Holstein(N,{"ConserveNf",true,"ConserveNb",false,"MaxOcc=",4});</p>
<pre><code>auto ampo =AutoMPO(sites);
for(int j=1;j<=N-2;j=j+2)
{
ampo += -t,"Cdagup",j+2,"Cup",j;
ampo += -t,"Cdagdn",j+2,"Cdn",j;
ampo += -t,"Cdagup",j,"Cup",j+2;
ampo += -t,"Cdagdn",j,"Cdn",j+2;
}
for(int j=1;j<=N;j=j+2)
{
ampo += U,"Nup",j,"Ndn",j;
ampo += -sqrt(eplison*omega),"Nup",j,"A",j+1;
ampo += -sqrt(eplison*omega),"Nup",j,"Adag",j+1;
ampo += -sqrt(eplison*omega),"Ndn",j,"A",j+1;
ampo += -sqrt(eplison*omega),"Ndn",j,"Adag",j+1;
ampo += omega,"Adag",j+1,"A",j+1;
}
auto H=toMPO(ampo);
auto sweeps =Sweeps(20);
sweeps.noise()=1E-6,1E-6,1E-8,1E-12;
sweeps.maxdim()=10,20,100,100,200,400,800;
sweeps.cutoff()=1E-10;
auto state =InitState(sites);
for(auto j:range1(N))
{
if(j%4==1)state.set(j,"Dn");
else if(j%4==3)state.set(j,"Up");
else state.set(j,"0");
}
auto psi0=randomMPS(state);
auto [energy,psi]=dmrg(H,psi0,sweeps,{"Quiet=",true});
auto state1=InitState(sites);
for(auto j:range1(N))
{
if(j==1)state1.set(j,"UpDn");
else if(j%4==1&&j!=1)state1.set(j,"Dn");
else if(j%4==3)state1.set(j,"Up");
else state1.set(j,"0");
}
auto psi1=randomMPS(state1);
auto [energyadd,psi2]=dmrg(H,psi1,sweeps,{"Quiet=",true});
auto state2=InitState(sites);
for(auto j:range1(N))
{
if(j==3)state2.set(j,"Emp");
else if(j%4==1)state2.set(j,"Dn");
else if(j%4==3&&j!=3)state2.set(j,"Up");
else state2.set(j,"0");
}
auto psi3=randomMPS(state2);
auto [energyminus,psi4]=dmrg(H,psi3,sweeps,{"Quiet=",true});
auto state3=InitState(sites);
for(auto j:range1(N))
{
if(j==1)state3.set(j,"Up");
else if(j%4==1&&j!=1)state3.set(j,"Dn");
else if(j%4==3)state3.set(j,"Up");
else state3.set(j,"0");
}
auto psi5=randomMPS(state3);
auto [energyspin,psi6]=dmrg(H,psi5,sweeps,{"Quiet=",true});
printfln("spin gap=",energyspin-energy);
printfln("charge excitation=", energyadd+energyminus-2*energy);
return 0;
}
</code></pre>
<p>When I calculate N=60 in the code(actually the system is 30) , lambda=0.625, boson is 4. the spin gap is 0.351311, the charge gap is 0.442756. They are not correct. I try the other ways, but it doesn't work. Whether I ignore something? </p>
http://itensor.org/support/2229/questions-about-spin-and-charge-gap-holstein-hubbard-modelFri, 19 Jun 2020 01:39:44 +0000The block size and index in QDense
http://itensor.org/support/2133/the-block-size-and-index-in-qdense
<p>Hi,</p>
<p>When I print a tensor in QDense format, the result is as follows:</p>
<p>A----size(): 136<br>
A----offsets: Block: 0,0,0, Offset: 0<br>
Block: 1,2,0, Offset: 12<br>
Block: 1,0,1, Offset: 20<br>
Block: 0,1,1, Offset: 68<br>
Block: 2,2,1, Offset: 76<br>
Block: 2,0,2, Offset: 88<br>
Block: 1,1,2, Offset: 115<br>
Block: 3,2,2, Offset: 127<br>
Block: 3,0,3, Offset: 130<br>
Block: 2,1,3, Offset: 133</p>
<p>The size of each dimension is: 10 x 5 x 10 (by reviewing the dim in Con.Lis/Con.Ris/Con.Nis). There will be 500 elements (10x5x10) and 136 dense elements (A.size()) in this 3-order tensor. I have three questions:</p>
<p>1) What is the block size in this case? For example, the number of elements between blocks (1,0,1) and (0,1,1) is 68 - 20 = 48. Also, how many blocks in this case?</p>
<p>2) How to map the index of block (4 x 3 x 4?) to the coordination (10 x 5 x 10) in the COO format?</p>
<p>3) Is the block size fixed for all blocks?</p>
<p>Thank you so much in advance for any comments!</p>
http://itensor.org/support/2133/the-block-size-and-index-in-qdenseMon, 25 May 2020 06:46:23 +0000How do we properly add two IQMPO's?
http://itensor.org/support/2110/how-do-we-properly-add-two-iqmpos
<p>(I'll use the language of ITensorV2 for this question, but I don't believe my question is version specific.)</p>
<p>As discussed by <a rel="nofollow" href="https://arxiv.org/pdf/1008.3477.pdf">Schollwock</a> (pg 58 and 42), if I wish to add two MPO's, say <br>
Ha = A1 * A2 * ... *AN<br>
and<br>
Hb = B1 * B2 * ... *BN<br>
for some N-site system; then I'll need to form the direct product out of all the local tensors Ai and Bi. In other words, form a larger tensor with Ai and Bi on the diagonal: Mi = diagonal(Ai,Bi), where Ha+Hb = M1 * M2 * ... * MN. From which it follows the new tensor would have dimensions dim(Mi) = dim(Ai) + dim(Bi).</p>
<p>It's not so clear to me how one would do this if Ai and Bi are block sparse IQTensors. If LinkA and LinkB represent the sets of Link indices for A and B, then would I need to create a new set LinkM, where the dimensions of like-QN sectors are summed? What is the best way of doing this, or are there functions which already handle this?</p>
<p>I'm aware there is a function add(Ha,Hb), however, doing this fails with the complaint: </p>
<pre><code>From line 271, file itensor_operators.cc
ITensorT::operator+=: different index structure
</code></pre>
<p>In this particular run, Ha and Hb are nearly identical, and have identical quantum number. (I'm happy to share my code if that will help.)</p>
http://itensor.org/support/2110/how-do-we-properly-add-two-iqmposThu, 14 May 2020 19:50:35 +0000Project MPS into inversion-symmetry subspace.
http://itensor.org/support/2089/project-mps-into-inversion-symmetry-subspace
<p>By inversion-symmetry I mean the exchange of lattice indices @@c<em>i\to c</em>{ -i}@@. I need to project the state into the subspace with +1 (or -1) eigenvalue of inversion symmetry, how can I do that in MPS language? Thanks in advance.</p>
http://itensor.org/support/2089/project-mps-into-inversion-symmetry-subspaceFri, 08 May 2020 21:05:08 +0000Eigenvalues of Transfer Operator in iDMRG
http://itensor.org/support/2087/eigenvalues-of-transfer-operator-in-idmrg
<p>Hi Miles,</p>
<p>I am trying to look at dynamical quantum phase transitions (DQPTs) in a particular model by numerically finding Fisher zero lines @@z \in \mathcal{C} @@ such that @@\langle \psi (0) | \psi (z) \rangle = 0@@, where @@ | \psi (z) \rangle := e^{zH} | \psi (0) \rangle@@. </p>
<p>I would like to work directly in the thermodynamic limit using iDMRG code based on <a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/v2/sample/idmrg.cc">this example</a>, and identify Fisher zeros based on crossings in the eigenspectrum of the Transfer Matrix. How would I compute the transfer matrix of two MPS and obtain its eigenvalues, similarly to <a rel="nofollow" href="https://tenpy.github.io/reference/tenpy.networks.mps.TransferMatrix.html">what is done</a> in TenPy?</p>
<p>Also, are there any subtleties I need to be aware of when performing real and imaginary time evolution of iMPS in ITensor, or can I use the same functionality as for generic MPS?</p>
<p>Thanks so much for your help!</p>
http://itensor.org/support/2087/eigenvalues-of-transfer-operator-in-idmrgFri, 08 May 2020 19:32:31 +0000DMRGpy installation
http://itensor.org/support/2052/dmrgpy-installation
<p>Hello,<br>
I have a question concerning the DMRGpy library installation <a rel="nofollow" href="https://github.com/joselado/dmrgpy">https://github.com/joselado/dmrgpy</a></p>
<ol>
<li>I use Windows10 and installed Itensor via Cygwin64.<br>
In Anaconda Prompt I typed <code>git clone https://github.com/joselado/dmrgpy</code></li>
</ol>
<p>and <code>set DMRGROOT="C:/Users/(...)/dmrgpy/src",</code> and <br>
in python script I wrote <code>import os ; import sys ; sys.path.append(os.environ["DMRGROOT"])</code></p>
<p>I got the following error <code>ImportError: cannot import name 'spinchain' from 'dmrgpy' (unknown location)</code></p>
<p>How one can relate libraries BLAS, LAPACK to dmrgpy?</p>
<ol>
<li>Is using DMRGpy as effective as Itensor? i.e. Is any problem to be computed in Itensor can be implemented in DMRGpy as well?</li>
</ol>
<p>Sorry for the questions, however Joselado didn't replied. </p>
<p>Thank you.</p>
http://itensor.org/support/2052/dmrgpy-installationThu, 30 Apr 2020 16:55:40 +0000About Hubbard model to tJ limit
http://itensor.org/support/2012/about-hubbard-model-to-tj-limit
<p>Dear all,</p>
<p>I am using the exthubbard.cc code in the sample folder to calculate ground state of Hubbard model. My question is, if I take a very high value of U1 in exthubbard.cc, i.e. in the limit t/U1 >> 1, does this model gives results corresponding to tJ model (tJ model is the Hubbard model in large on-site interaction limit)?</p>
<p>Sincerely<br>
Sreetama</p>
http://itensor.org/support/2012/about-hubbard-model-to-tj-limitThu, 16 Apr 2020 01:36:44 +0000Avoiding local minima in DMRG
http://itensor.org/support/1959/avoiding-local-minima-in-dmrg
<p>Hi,</p>
<p>I am trying to use DMRG to compute a gap between Sz=0 and Sz=1 states.<br>
My (fermionic) model is by no means intricate: a given 1D tight-binding model at half-filling with Hubbard interactions.<br>
I am sure there is a gap in my particular system, but I am getting 0.<br>
I tested several different things, so let me try to summarize my struggles:</p>
<p>1) Getting stuck in local minima (which depends on the initial state) while conserving symmetries</p>
<p>In principle, I want to converse N and Sz in this type of calculations: first, calculations are faster; second, I can get the gap by simply computing groundstates with the desired QNs. When I do that, I have to initialize my system in a state that has the QNs that I want. If I use Fock states, I can easily get stuck in local minima (as replied by Miles in <a rel="nofollow" href="http://itensor.org/support/105/sweeps-system-size-clarification-choice-intial-state-dmrg).">http://itensor.org/support/105/sweeps-system-size-clarification-choice-intial-state-dmrg).</a> I believe this is what happens in my code, even though I've tried many different initial guesses (all of them Fock states). For that reason, now I want to feed DMRG with an "arbitrary" combination of states (similarly to what is asked in <a rel="nofollow" href="http://www.itensor.org/support/1359/how-to-create-a-particular-initial-state-as-a-mps,">http://www.itensor.org/support/1359/how-to-create-a-particular-initial-state-as-a-mps,</a> <a rel="nofollow" href="http://itensor.org/support/1357/setting-random-initial-product-state,">http://itensor.org/support/1357/setting-random-initial-product-state,</a> and <a rel="nofollow" href="http://itensor.org/support/490/starting-initial-state-as-product-state-of-singlets?show=490#q490)">http://itensor.org/support/490/starting-initial-state-as-product-state-of-singlets?show=490#q490)</a> <strong>that still has the right N and Sz</strong>. However, I have not been able to create states as in the first and second links while conserving QNs (I get errors saying "Setting Tensor element non-zero would violate its symmetry"). In addition, I don't fully understand the syntax of the solution proposed in the third link to make something similar for electrons.<br>
Let me give a concrete example. Let's say that instead of starting with a Neel-like Fock state, |up,dn,up,dn,...>, I want to start with something like 1/sqrt(2)(|up>+|dn>)1/sqrt(2)(|up>-|dn>)..., which has the same N and Sz. How can I run DMRG, starting from this initial state, and still conserving N and Sz?</p>
<p>2) "ConserveQNs"==false not working properly in version v3 for electrons?</p>
<p>While I could not fix the previous issue, other option that I had in mind was to not conserve symmetries at all (which allows me to start with a randomized wave function via the "randomMPS" function) and then look for the ground state (which has Sz=0) and to excited states (until I get one with Sz=1). Since the Sz=1 can be degenerate, to explore this option I would probably need to add a Zeeman splitting term in the Hamiltonian as well. However, it looks like there is a bug in version v3 when "ConserveQNs"==false is set for electrons (I think this is acknowledged in <a rel="nofollow" href="https://github.com/ITensor/ITensor/issues/311).">https://github.com/ITensor/ITensor/issues/311).</a> For that reason, I am installing version v2 and exploring that route.</p>
<p>I believe this should be a quite common problem for people more experienced than me in DMRG calculations (I have just started). So, if someone has any other idea in mind to tackle this difficulty, please let me know. </p>
<p>Let me add that I have also played with the "noise" parameter in DMRG, but I couldn't fix my problems with that.</p>
<p>Best,<br>
Gonçalo Catarina</p>
<p>EDIT: minor modifications to my questions, before any reply, for the sake of clarity.</p>
http://itensor.org/support/1959/avoiding-local-minima-in-dmrgMon, 09 Mar 2020 12:20:52 +0000ITensor in Jupyter Notebooks
http://itensor.org/support/1955/itensor-in-jupyter-notebooks
<p>I was wondering if anyone had success getting ITensor running in Jupyter notebooks using Xeus-Cling. [I am new to Xeus-Cling, so I am undoubtedly doing something naive.] If you have any suggestions, please let me know.</p>
<p>What I did so far:<br>
- Installed Xeus-Cling using conda<br>
- Compiled Itensor, using the flag: ITENSOR<em>MAKE</em>DYLIB=1</p>
<p>I start up a notebook, and run:</p>
<pre><code>#pragma cling add_include_path("/Users/emueller/Itensor3Clean/itensor")
#pragma cling add_library_path("/Users/emueller/Itensor3Clean/itensor/lib")
#include "itensor/index.h"
</code></pre>
<p>Everything works fine, I can create and manipulate index objects.</p>
<p>The problem comes when I try to include some of the other header files. For example:</p>
<pre><code>#include "itensor/itensor.h"
</code></pre>
<p>yields an error (quoted below so as not not mess up the flow of the question) -- along with the errors that I get when I try to include a few other headers.</p>
<p>In case it matters, I am using Mac OSX 10.14.6, Cling 0.6, Xeus 0.23.3. ITensor 3.0. </p>
<p>ITensor works great for me when run in the regular way (compiling and linking using Clang). I think that getting it running in a Jupyter notebook would be great for teaching, and also make for a good development workflow (at least for me). </p>
<p>Erich</p>
<p>Sample include's, and the error messages:</p>
<pre><code>#include "itensor/itensor.h"
</code></pre>
<p>yeilds</p>
<p>In file included from input<em>line</em>1:1:<br>
In file included from /Users/emueller/anaconda/envs/cling/include/c++/v1/new:90:<br>
In file included from /Users/emueller/anaconda/envs/cling/include/c++/v1/exception:80:<br>
In file included from /Users/emueller/anaconda/envs/cling/include/c++/v1/cstddef:110:<br>
/Users/emueller/anaconda/envs/cling/include/c++/v1/type<em>traits:1078:75: error: no member named 'value' in 'std::<strong>1::integral_constant<bool, true>'<br>
_IsNotSame<decltype(</strong>is</em>referenceable_impl::__test<_Tp>(0)), __two>::va...</p>
<p>and so on...</p>
<pre><code>#include "itensor/util/readwrite.h"
</code></pre>
<p>yields</p>
<p>In file included from input<em>line</em>37:1:<br>
In file included from /Users/emueller/Itensor3Clean/itensor/itensor/util/readwrite.h:19:<br>
In file included from /Users/emueller/anaconda/envs/cling/include/c++/v1/fstream:188:<br>
/Users/emueller/anaconda/envs/cling/include/c++/v1/filesystem:852:13: error: no viable overloaded '+='<br>
__pn_ += preferred_separator;</p>
<p>and so on...</p>
<pre><code> #include "itensor/tensor/lapack_wrap.h"
</code></pre>
<p>yields</p>
<p>In file included from input<em>line</em>39:1:<br>
In file included from /Users/emueller/Itensor3Clean/itensor/itensor/tensor/lapack<em>wrap.h:84:<br>
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs<br>
/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h:20:<br>
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs<br>
/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Headers/../Frameworks/vecLib.framework/Headers/vecLib.h:64:<br>
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs<br>
/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/Solve.h:4462:<br>
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs<br>
/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/SolveImplementation.h:53:<br>
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs<br>
/MacOSX.sdk/usr/include/os/log.h:14:<br>
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs<br>
/MacOSX.sdk/usr/include/os/trace.h:8:<br>
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs<br>
/MacOSX.sdk/usr/include/os/trace</em>base.h:95:27: error: expected unqualified-id<br>
extern struct mach_header __dso_handle;</p>
<p>and so on...</p>
http://itensor.org/support/1955/itensor-in-jupyter-notebooksMon, 02 Mar 2020 19:25:19 +0000Issues using applyExpH
http://itensor.org/support/1925/issues-using-applyexph
<p>Hi,<br>
I am trying to calculate the MPS resulting from exp(-tau H)|psi> where where H has up to three site interaction terms, and the exponential is the usual Boltzmann operator in this case.<br>
I can't use expH because of the three term interactions so I moved to applyExpH, but I keep on having an allocation error which I cannot trace back.</p>
<p>Here is a snippet of my code</p>
<pre><code>auto args = Args("Cutoff=",1E-8,"MaxDim=",20,"Order=",2);
for (int i = 1; i<= Nstep; i++)
{
std::cout << "Step " << i << std::endl;
applyExpH(psi1,H,dt,res,args);
psi1 = res;
println("Norm: ",norm(res));
}
writeToFile(pfile,psi1);
</code></pre>
<p>The error I get is the following:<br>
terminate called after throwing an instance of 'std::bad<em>alloc'<br>
what(): std::bad</em>alloc<br>
Removing the three site interactions the error disappear so it must be related to the Hamiltonian structure. Is this a normal behaviour?</p>
<p>Regards,<br>
Raffaele</p>
http://itensor.org/support/1925/issues-using-applyexphFri, 31 Jan 2020 16:11:36 +0000Initial state with specific momentum
http://itensor.org/support/1901/initial-state-with-specific-momentum
<p>Hi,</p>
<p>I was wondering if it is possible to prepare as initial state for the real time evolution a state with one (or more) free particles (let's say fermions) with specific momenta (k1, k2, etc). For instance, I would like to study the evolution of a state with two particles initially at large distance with opposite momenta. </p>
<p>Thanks a lot,<br>
Giuseppe </p>
http://itensor.org/support/1901/initial-state-with-specific-momentumTue, 14 Jan 2020 09:54:14 +0000ITensor3 is slower than same code on ITensor2
http://itensor.org/support/1849/itensor3-is-slower-than-same-code-on-itensor2
<p>Hello,</p>
<p>I recently switched from ITensor 2 to version 3 and I noticed that the same code runs noticeably slower on the newer version.<br>
A calculation that was taking ~7 hours in ITensor 2 now takes almost twice as much time.<br>
I am not sure whether it is ITensor that is responsible to this or something in the cluster configuration where I am running the code, but I would appreciate any help or ideas about what might be causing this.</p>
<p>In particular, on the cluster I am using, I only have access to certain gcc compilers, and in order to use c++17 I had to switch from gcc 4.9.3 to gcc9.1.0 (the only one that supports c++17).<br>
In both cases, I am using LAPACK 3.6.1.</p>
<p>Thanks,</p>
http://itensor.org/support/1849/itensor3-is-slower-than-same-code-on-itensor2Wed, 11 Dec 2019 22:03:53 +0000Disappearing value of Sx and Sy, while measuring expected values of spin (per site)
http://itensor.org/support/1705/disappearing-value-while-measuring-expected-values-spin-site
<p>I'm trying to measure expected values of <code>Sx</code>, <code>Sy</code> and <code>Sz</code> on each site for given Hamiltonian and graph. My code looks as follows:</p>
<pre><code>#include "itensor/all.h"
using namespace itensor;
int
main(int argc, char* argv[])
{
int Nx = 8; // Nx can be understood as the size of an elementary cell
auto N = atoi(argv[1])*Nx;
auto sites = SpinOne(N,{"ConserveQNs=",false});
auto ampo = AutoMPO(sites);
// [Definitiion of my Hamiltonian]
auto H = toMPO(ampo);
auto state = InitState(sites);
for (int i = 1; i <= N; i++) {
state.set(i,"Up");
}
auto sweeps = Sweeps(10);
sweeps.maxm() = 50,100,200,300,400;
sweeps.cutoff() = 1E-10;
println(sweeps);
//
// Begin the DMRG calculation
// for the ground state
//
auto [en0,psi0] = dmrg(H,randomMPS(sites),sweeps,{"Quiet=",true});
//
// Print the final energies reported by DMRG
//
printfln("\n Ground State Energy = %.10f",en0);
//
// Measuring Sx, Sy & Sz
//
println("Ground state");
println("\nj | Sx | Sy | Sz | S_total |: ");
for( auto j : range1(N) ) {
// Re-gauge psi0 to get ready to measure at position j
psi0.position(j);
auto ket = psi0(j);
auto bra = dag(prime(ket,"Site"));
auto Sxjop = op(sites,"Sx",j);
auto Syjop = op(sites,"Sy",j);
auto Szjop = op(sites,"Sz",j);
//take an inner product
auto sxj = eltC(bra*Sxjop*ket);
auto syj = eltC(bra*Syjop*ket);
auto szj = eltC(bra*Szjop*ket);
println(j, " | ", sxj, " | ", syj, " | ", szj, " | ", sxj + syj + szj, " | ");
}
return 0;
</code></pre>
<p>}</p>
<p>When I run the above program I get:</p>
<pre><code>Ground state
j | Sx | Sy | Sz |:
1 | (2.82726e-12,0) | (0,-2.64747e-28) | (-0.98518,0) |
[...]
</code></pre>
<p>However, if I only change the part:</p>
<pre><code>[...]
auto Sxjop = op(sites,"Sx",j);
auto Syjop = op(sites,"Sy",j);
auto Szjop = op(sites,"Sz",j);
[...]
</code></pre>
<p>into:</p>
<pre><code>[...]
auto Sxjop = op(sites,"Sx2",j);
auto Syjop = op(sites,"Sy2",j);
auto Szjop = op(sites,"Sz2",j);
[...]
</code></pre>
<p>I get:</p>
<pre><code>Ground state
j | Sx^2 | Sy^2 | Sz^2 | S_total^2 |:
1 | (0.5,0) | (0.5,0) | (1,0) | (2,0) |
[...]
</code></pre>
<p>which makes sense, because I believe the square of total spin satisfies following rules: </p>
<p>$$<br>
S<em>{total}^2 = S</em>x^2 + S<em>y^2 + S</em>z^2<br>
S_{total}^2 = S ( S + 1),<br>
$$</p>
<p>so for the spin @@ S = 1 @@ I should get @@ S_{total}^2 = 2 @@, which holds.</p>
<p>But I have to measure the values <code>Sx</code>, <code>Sy</code> and <code>Sz</code> instead of their squares. Do you have any suggestions?</p>
http://itensor.org/support/1705/disappearing-value-while-measuring-expected-values-spin-siteWed, 28 Aug 2019 14:40:33 +0000