ITensor Support Q&A - Recent questions and answers
http://itensor.org/support/qa
Powered by Question2AnswerAnswered: Writing MPS to .h5 file in a multi-core process
http://itensor.org/support/3611/writing-mps-to-h5-file-in-a-multi-core-process?show=3614#a3614
<p>For people that are interested, I accidentally found a way around this. </p>
<p>The original shell script I tried for job submission contains the following:<br>
#SBATCH -n 6<br>
srun -n 4<br>
where the -n 6 means saving 6 cores for the calculation, and the -n 4 means using 4 of them. The purpose of the extra 2 cores is to provide some more memory space in case the 4 cores aren't enough, so that the job wouldn't be killed. </p>
<p>It's exactly the -n 4 cores used that seems to be giving me the problem in creating the .h5 file and save data, which I still haven't figured out why. In my new shell script, I simply changed the -n 4 to be -n 1, which surprisingly worked very well. It's a single core, so no file creation issue, and at the same time we have the 6 cores backup, so no memory issue. </p>
<p>My initial misconception was that the srun -n has to take care of the most part of the memory consumption, so that in order to resolve the memory issue, it has to be more than 1 core. This turned out not to be the case. Again, I still don't know why due to my very limited knowledge in computer science. </p>
<p>Hopefully this could be useful to people in the future, and I would also love to hear about why this is the case from the experts. </p>
http://itensor.org/support/3611/writing-mps-to-h5-file-in-a-multi-core-process?show=3614#a3614Wed, 24 Nov 2021 02:04:44 +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 +0000Answered: Wave function of real space parallel DMRG.
http://itensor.org/support/3606/wave-function-of-real-space-parallel-dmrg?show=3610#a3610
<p>Hi Zongsheng,<br>
Glad the point about the V tensors helped. Yes I think that's the key point to notice. Additionally, there could also be some subtlety about the state of each node as the calculation is stopped which could leave them in an incompatible state, so that is another thing to consider.</p>
<p>In general, that parallel DMRG code was not very focused on the ability to restart the calculations, with the thinking that anyway the time to store and re-prepare the state (e.g. recalculating the tensors which wrap the Hamiltonian into the MPS) does not have good parallel scaling so could cancel out the benefits of doing a parallel calculation in the first place. Also it's just a more complicated aspect of the code to get working correctly.</p>
<p>Hope you find a way to use it that's helpful to you –</p>
<p>Miles</p>
http://itensor.org/support/3606/wave-function-of-real-space-parallel-dmrg?show=3610#a3610Mon, 15 Nov 2021 17:22:03 +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 +0000Answered: Correlation function for 1d Heisenberg hamiltonian
http://itensor.org/support/3593/correlation-function-for-1d-heisenberg-hamiltonian?show=3596#a3596
<p>Hi, so I could see two answers to your question. Could you clarify which one you are interested in discussing further?</p>
<p>(1) if your question is about how to use DMRGpy (i.e. regarding the error you got), you should contact the maintainer or DMRGpy, Jose Lado. Another Python package for DMRG is TeNPy which you might want to try if you are staying with Python.</p>
<p>(2) if you are willing to learn Julia, which is not too hard to learn especially if you start from example codes for DMRG and correlation functions which we provide in the ITensor documentation, then you could certainly use ITensor to compute spin correlation functions of the Heisenberg model.</p>
<p>For the case of (2), please see the following examples of how to do (a) DMRG of the Heisenberg model and (b) compute a spin correlation function using the ITensor function called <code>correlation_matrix</code></p>
<p>(a) <a rel="nofollow" href="https://itensor.github.io/ITensors.jl/stable/tutorials/DMRG.html">https://itensor.github.io/ITensors.jl/stable/tutorials/DMRG.html</a></p>
<p>(b) <a rel="nofollow" href="https://itensor.github.io/ITensors.jl/stable/examples/MPSandMPO.html#Computing-Correlation-Functions">https://itensor.github.io/ITensors.jl/stable/examples/MPSandMPO.html#Computing-Correlation-Functions</a></p>
http://itensor.org/support/3593/correlation-function-for-1d-heisenberg-hamiltonian?show=3596#a3596Sun, 07 Nov 2021 14:47:43 +0000Answered: Strange error for free fermions with longer-range hopping
http://itensor.org/support/3590/strange-error-for-free-fermions-with-longer-range-hopping?show=3595#a3595
<p>Hi Mason,<br>
I checked myself and as mentioned above, putting a line like </p>
<pre><code>noise!(sweeps,1E-5)
</code></pre>
<p>fixes the issue. Cases like this where the Hamiltonian is very sparse and/or not very 1d-like need techniques like the DMRG noise term to converge well. Another important technique for convergence is choosing a more generic initial state such as one with a finite bond dimension, though I found that noise alone was sufficient here.</p>
<p>Miles</p>
http://itensor.org/support/3590/strange-error-for-free-fermions-with-longer-range-hopping?show=3595#a3595Sun, 07 Nov 2021 14:42:25 +0000Answered: Noise in measured quantity even after sufficient sweeps and setmaxdim
http://itensor.org/support/3566/noise-measured-quantity-after-sufficient-sweeps-setmaxdim?show=3585#a3585
<p>(Please see above discussion.)</p>
http://itensor.org/support/3566/noise-measured-quantity-after-sufficient-sweeps-setmaxdim?show=3585#a3585Thu, 04 Nov 2021 14:14:08 +0000Answered: Non-Hermitian operator time evolution
http://itensor.org/support/3541/non-hermitian-operator-time-evolution?show=3581#a3581
<p>(Please see discussion above.)</p>
http://itensor.org/support/3541/non-hermitian-operator-time-evolution?show=3581#a3581Wed, 03 Nov 2021 19:02:12 +0000Answered: why can't I exponantiate this ?
http://itensor.org/support/3577/why-cant-i-exponantiate-this?show=3579#a3579
<p>The code "Gj = exp(-1.0imtau/2*hj) " should be replaced by "Gj = exp(-1.0im*tau/2*hj)" . </p>
<p>the apply function can handle non-nearest-neighbor gates, I am not sure that Trotter gates cannot deal with long-range interactions in the versions of ITensor? </p>
http://itensor.org/support/3577/why-cant-i-exponantiate-this?show=3579#a3579Wed, 03 Nov 2021 01:00:35 +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 +0000Answered: Davidson algorithm and dmrg sweeping
http://itensor.org/support/3561/davidson-algorithm-and-dmrg-sweeping?show=3562#a3562
<p>Hi Murod,<br>
Yes the statement in the docs about the Davidson iterations is based mainly on experience and numerical experiments. But it's also justifiable based on how DMRG works: as the algorithm nears convergence and reaches a fixed point where the MPS is already a very good approximation for the ground state, then the initial vector used in Davidson will also already be an equally good eigenvector of the matrix there as the MPS is of the whole Hamiltonian. So in fact the Davidson steps can be taken lower and lower toward the end of DMRG, not raised, without any problem. (Of course it can only be taken as low as doing one Davidson iteration otherwise the algorithm would no longer be doing anything at all!)</p>
<p>Thanks for sharing that code you're working on - sounds interesting.</p>
<p>Miles</p>
http://itensor.org/support/3561/davidson-algorithm-and-dmrg-sweeping?show=3562#a3562Tue, 26 Oct 2021 18:47:02 +0000Answered: Projecting an arbitary MPS onto a particular symmetry sector
http://itensor.org/support/3555/projecting-an-arbitary-mps-onto-particular-symmetry-sector?show=3556#a3556
<p>Hi Alexei,<br>
Thanks for a great question, though my answer might be disappointing to you. The answer is that there is in principle a nice algorithm to do this, but I don't think it's ever been published and I don't know of an existing code that offers it, including ITensor. It's certainly something we could add, in the sense of being a feature that would be a good fit for our library and we'd like to offer, but I can't promise any time frame for when we would add it.</p>
<p>The shortest version I can give of how this algorithm would work starts with some background: your idea of using an MPO projector would indeed run into an issue but it may not be exactly the one you meant. The issue is not that the final MPS would end up with a large bond dimension - that would not happen - but that the actual MPO itself would be very large so that using it would still be prohibitively expensive on a large system.</p>
<p>So the algorithm I would write would go more like this (it's a very rough description): first you would project the first site into various symmetry sectors (for the case of particle number or U(1) symmetry these would be different particle numbers). Then you would keep track of the different projection results by either storing separate tensors corresponding to each type of projection (0 particle tensor, 1 particle tensor, etc.) or by actually starting to construct the MPO you were talking about and having its first tensor.</p>
<p>Next, you would make a projector that combines the information about the previous projection with the projection on the next site, and creates new tensors corresponding to the various outcomes, which would now cover a larger range of possibilities: 0, 1, 2, etc particles. At this point it starts to become important to <em>truncate</em> this set of tensors in some way. This would depend on the details of the algorithm. The simplest version would be to evaluate the probability of seeing the particular total quantum numbers you are keeping track of and discard the ones whose probability falls below some threshold. A more sophisticated way would to be to continue to use this "partial projector MPO" picture to devise a truncation procedure.</p>
<p>Proceeding this way, one would continue to alternate between projecting and truncating, site by site. </p>
<p>The crucial thing is that one has to truncate "on the fly" as the projection is being done to avoid a blowup of costs. Otherwise, the algorithm just won't be efficient in general.</p>
<p>Sorry that my answer is so vague, but it's not an algorithm that's written down anywhere I am aware of. I hope to write more about it or implement it at some point.</p>
<p>Best regards,<br>
Miles</p>
<p>P.S. there may be some other easier things that can be tried. For example, one could create an MPO which enforces an energy penalty that favors a particular total quantum number over others, and include this MPO in a DMRG calculation to 'target' a state with these particular quantum numbers. This can be used as a kind of "poor man's" approach to, say, get a certain SU(2) quantum number in a code, like ITensor, that currently only offers Abelian quantum number conservation. I've done this particular one before and it worked well.</p>
http://itensor.org/support/3555/projecting-an-arbitary-mps-onto-particular-symmetry-sector?show=3556#a3556Mon, 18 Oct 2021 19:31:28 +0000Answered: Commutator between MPO
http://itensor.org/support/3542/commutator-between-mpo?show=3543#a3543
<p>Good question. While you can use the <code>apply</code> function to apply a single-site operator to an MPO, there is a more "manual" way to do this also just using ITensor contractions and the fact that an MPO has an interface like an array of tensors.</p>
<p>A very analogous case is the manual method for applying a single-site operator to an MPS, which is given in detail here:<br>
<a rel="nofollow" href="https://itensor.github.io/ITensors.jl/stable/examples/MPSandMPO.html#Applying-a-Single-site-Operator-to-an-MPS">https://itensor.github.io/ITensors.jl/stable/examples/MPSandMPO.html#Applying-a-Single-site-Operator-to-an-MPS</a></p>
<p>Following very similar steps, you can apply a single-site operator to an MPO, by paying careful attention to the prime levels of the MPO site indices and of the operator you are applying, and adjusting these prime levels appropriately.</p>
<p>Then by adjusting the prime levels in a different way, you can make the operator act on the "bra" indices of the MPO tensor versus the "ket" indices, which would be like doing BA instead of AB. </p>
<p>Finally, if you take the resulting two MPOs and subtract them, you will have the commutator.</p>
<p>Please try that out, first on paper then in code, and let us know if you have more questions along the way.</p>
<p>Miles </p>
http://itensor.org/support/3542/commutator-between-mpo?show=3543#a3543Thu, 07 Oct 2021 16:10:18 +0000Answered: Memory issue with DMRG
http://itensor.org/support/3532/memory-issue-with-dmrg?show=3539#a3539
<p>Hi Mason,<br>
Thanks for the question: I've run into a similar behavior before, and I believe it's to do with something fundamental about DMRG. I think what's going on is that for first sweep where the max bond dimension is the largest one you set, or the one you are hoping will continue to fit in memory for subsequent sweeps, actually many of the MPS link or bond indices have not yet reached their maximum value. So even though they are allowed to reach this value, they actually haven't yet. Relatedly, tensors such as the "projections" of the Hamiltonian into pieces of the MPS have indices which are not yet as large as they could be.</p>
<p>Then, in the next sweep, finally all indices start to reach their maximum values and this is when you run out of memory.</p>
<p>Does that sound plausible? At any rate, the key point is that you are running out of memory somewhere even if it's not where you were initially expecting. So then the main thing you can do is to start having DMRG store tensors to disk before that point.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/3532/memory-issue-with-dmrg?show=3539#a3539Mon, 04 Oct 2021 20:57:14 +0000Issue in the result of two-site MPO operator with density operator.
http://itensor.org/support/3538/issue-the-result-two-site-mpo-operator-with-density-operator
<p>I am facing an issue regarding the implementation of two site MPO operators with a density matrix. </p>
<p>Basically, I have evolved a density matrix and want to calculate the spin current at each time-steps.</p>
<pre><code> \rho(t) = \exp(-iHt/h) \rho(0) \exp(iHt/h)
</code></pre>
<p>For this, I have used this implementation <a rel="nofollow" href="https://github.com/ITensor/ITensors.jl/blob/main/examples/gate_evolution/mpo_gate_evolution.jl">https://github.com/ITensor/ITensors.jl/blob/main/examples/gate_evolution/mpo_gate_evolution.jl</a></p>
<p>Now, I want to calculate the spin current < I<em>i (t)> = Tr{\rho(t) J</em>i} <br>
where J <em>i = S</em>x ^i S<em>y^{i+1} - S</em>y^i S_x^{i+1}</p>
<p>My implementation in ITensor Julia</p>
<p>p = AutoMPO()</p>
<p>p+= 1,"Sx",50,"Sy",51<br>
p+= -1,"Sy",50,"Sx",51</p>
<p>Operator = MPO(p,s)</p>
<p>I<em>50 = inner(Operator,rho</em>t)</p>
<p>But, I am getting zero as the output for I_50 at every time step. I would appreciate it if you could look into the issue.</p>
http://itensor.org/support/3538/issue-the-result-two-site-mpo-operator-with-density-operatorSun, 03 Oct 2021 19:46:26 +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 +0000Answered: Out Of Memory Error()when using correlation_matrix()
http://itensor.org/support/3528/out-of-memory-error-when-using-correlation_matrix?show=3531#a3531
<p>Hi Xin-Chi,<br>
Thanks again for reporting this. I found that there was indeed a bug in the correlation_matrix code. The bug was that certain tensor contractions were happening in the wrong order, leading to some intermediate tensors which were very large. I just submitting a pull request (<a rel="nofollow" href="https://github.com/ITensor/ITensors.jl/pull/754)">https://github.com/ITensor/ITensors.jl/pull/754)</a> which reorders these contractions. Now the code is much faster than before and uses a reasonable amount of memory (I measured only 500Mb usage or so with the new code).</p>
<p>This updated code will be included in the next version of ITensors.jl which I'll register later today.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/3528/out-of-memory-error-when-using-correlation_matrix?show=3531#a3531Thu, 30 Sep 2021 17:39:35 +0000Answered: Issue with finding dimension of index
http://itensor.org/support/3523/issue-with-finding-dimension-of-index?show=3527#a3527
<p>(Please see discussion above.)</p>
http://itensor.org/support/3523/issue-with-finding-dimension-of-index?show=3527#a3527Wed, 29 Sep 2021 21:40:15 +0000Answered: Conserve_qns not working for custom MPO
http://itensor.org/support/3481/conserve_qns-not-working-for-custom-mpo?show=3517#a3517
<p>Hi Chris,<br>
I found the issue, which is that our <code>apply</code> function fails in certain cases if the MPO passed to it does not have any link or virtual indices. Ideally it would be able to just work in that case, since I'm sure you'd agree it's more convenient to just make the MPO the way you did without putting in link indices by hand also.</p>
<p>But for now, I've made an improved version of your "initial" function as well as a helper function called "putlinks!" which puts dimension-1 link indices into the MPO. After using putlinks!, I find that the apply code runs fine even with quantum numbers (basing it on the example code here: <a rel="nofollow" href="https://github.com/ITensor/ITensors.jl/blob/main/examples/gate_evolution/mpo_gate_evolution.jl">https://github.com/ITensor/ITensors.jl/blob/main/examples/gate_evolution/mpo_gate_evolution.jl</a> )</p>
<pre><code>function putlinks!(rho::MPO)
N = length(rho)
links = Index[]
space = hasqns(rho[1]) ? (QN()=>1) : 1
for n=1:N
l = Index(space;tags="Link,n=$n")
push!(links,l)
end
for n=1:N-1
rho[n] *= dag(onehot(links[n]=>1))
rho[n+1] *= onehot(links[n]=>1)
end
end
function initial(N::Int, mu::Float64, index)
rho = MPO(N)
Nh = div(N,2)
for x=1:Nh
rho[x] = 0.5*(op("Id", index[x]) + 2*mu*op("Sz",index[x]))
end
for x=Nh+1:N
rho[x] = 0.5*(op("Id", index[x]) - 2*mu*op("Sz",index[x]))
end
putlinks!(rho)
return rho
end
</code></pre>
http://itensor.org/support/3481/conserve_qns-not-working-for-custom-mpo?show=3517#a3517Mon, 27 Sep 2021 18:55:02 +0000Answered: ITensors QN - Type
http://itensor.org/support/3503/itensors-qn-type?show=3514#a3514
<p>Hi Giuseppe,<br>
I had drafted a similar answer to Matt's – including it in case the extra details are helpful. We are discussing whether it's a good idea to make the amount of QNs changeable in a simpler way, though it could lead to some errors if not done at the very beginning of a program.</p>
<p>Here's my answer:<br>
If you change the variable "maxQNs" to be greater than 4, then you will be able to use any amount of QNs you want that way, and the rest of the code should continue to work. To make this change, you will need to do the following steps:</p>
<ol>
<li><p>change the ITensors package to be in "dev" mode if you haven't already: in the package manager (type ] to enter package mode) run the command "dev ITensors"</p></li>
<li><p>navigate in your shell to the folder ~/.julia/dev/ITensors/src/qn/</p></li>
<li><p>edit the file qn.jl by changing the maxQNs variable on line 62<br>
<a rel="nofollow" href="https://github.com/ITensor/ITensors.jl/blob/1e44c0c874f531ac6ba767fb67551ba6fac11e18/src/qn/qn.jl#L62">https://github.com/ITensor/ITensors.jl/blob/1e44c0c874f531ac6ba767fb67551ba6fac11e18/src/qn/qn.jl#L62</a></p></li>
</ol>
<p>Now if you restart any running Julia session or run a new one, you should be able to use more QNs.</p>
<p>Finally, note that after switching to dev mode, you will not get updates of version of ITensors.jl in the usual way (i.e. your version will be pinned to the current one unless you manually pull the code from Github). So to update your ITensor library code you'll need to revert any code edits you made, then do "free ITensors" in the Julia package manager.</p>
http://itensor.org/support/3503/itensors-qn-type?show=3514#a3514Mon, 27 Sep 2021 15:59:09 +0000Answered: Computing expectation value for a given observable after DMRG simulation
http://itensor.org/support/3509/computing-expectation-value-observable-after-simulation?show=3510#a3510
<p>Thanks for the question. There isn't exactly a built-in feature for what you are asking, but it's straightforward to do. I made a sample code below that hopefully show you the steps you need.</p>
<p>To transform psi into a "vector" (tensor with N indices in the full Hilbert space), you can contract all of the MPS tensors into a single tensor using either a for loop or the <code>prod</code> function (prod does something similar to the capital-Pi symbol in mathematics). </p>
<p>From what I understand of your question, there should be no need to really form the entire density matrix from psi. This is because it's a pure state so just an outer product of psi with itself and therefore much more efficient to deal with each copy of psi separately.</p>
<p>In the code below, after transforming psi into a single tensor psiT, I make another (arbitrary) tensor AT which has two copies of the "site" indices: one set with prime level 0 and the other with prime level 1. Performing the tensor contraction using the ITensor * operation contracts over the unprimed indices, and then the noprime function removes the primes from the remaining indices.</p>
<p>In the end, the resulting density matrix is formally defined as this new state Apsi outer producted with your original state psi (being sloppy here about conjugation, but that's easy to include if dealing with complex numbers or QN-conserving tensors). </p>
<p>Please reply below if you have any follow-up questions.</p>
<pre><code>using ITensors
let
N = 10
chi = 2
s = siteinds("S=1/2",N)
# Make a random MPS with sites s
# and bond dimension chi:
psi = randomMPS(s,chi)
# psi could come from a DMRG
# calculation instead
# Contract MPS tensors
# together to make full
# wavefunction tensor:
psiT = ITensor(1.0)
for j=1:N
psiT = psiT*psi[j]
end
# s1 s2 s3 ...
# | | | |
# psiT = ============== ...
#
# Note:
# A shorter way to do the above
# is just `psiT = prod(psi)`
#
# Make a random tensor with
# s and s' indices:
A = randn(2^N,2^N)
AT = ITensor(A,prime.(s)...,s...)
#
# s1' s2' s3' ...
# | | | |
# AT = ============== ...
# | | | |
# s1 s2 s3 ...
#
ApsiT = noprime(AT*psiT)
# Note: afterward can turn ApsiT
# back into an MPS by calling
# `Apsi = MPS(ApsiT,s...;cutoff=1E-10)`
return
end
</code></pre>
http://itensor.org/support/3509/computing-expectation-value-observable-after-simulation?show=3510#a3510Mon, 27 Sep 2021 15:07:54 +0000Answered: [Julia] DMRG with handmade H MPO
http://itensor.org/support/3504/julia-dmrg-with-handmade-h-mpo?show=3507#a3507
<p>So it turns out that making my problem presentable and revising a lot the code that I want to share made me find one mistake already!<br>
Thanks for existing, ITensor community, otherwise I wouldn't have found it :D</p>
<p>The mistake snuck in when I copied the ITensors.jl template of manufactoring the bulk MPO. The mistake happens when I project out the first and left side of the bulk tensor to form open boundary conditions: Here I kept the last row vector of the bulk MPO. Correct would have been the second row vector, w.r.t. the bulk MPO presented in my first comment!</p>
<p>I fixed this and now it seems to work just fine!</p>
http://itensor.org/support/3504/julia-dmrg-with-handmade-h-mpo?show=3507#a3507Fri, 24 Sep 2021 13:58:28 +0000Answered: Multithreading bug after updating to 0.2 Julia Itensor
http://itensor.org/support/3477/multithreading-bug-after-updating-to-0-2-julia-itensor?show=3502#a3502
<p>This should be fixed on the latest version (0.2.7).</p>
http://itensor.org/support/3477/multithreading-bug-after-updating-to-0-2-julia-itensor?show=3502#a3502Wed, 22 Sep 2021 23:08:33 +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 +0000Answered: How to calculate symmetry breaking phase efficiently
http://itensor.org/support/3480/how-to-calculate-symmetry-breaking-phase-efficiently?show=3493#a3493
<p>(Please see discussion above.) </p>
http://itensor.org/support/3480/how-to-calculate-symmetry-breaking-phase-efficiently?show=3493#a3493Fri, 17 Sep 2021 01:36:11 +0000Answered: Single site DMRG C++
http://itensor.org/support/3485/single-site-dmrg-c?show=3488#a3488
<p>Hi, the answer is unfortunately single-site DMRG is not fully implemented. Are you able to use two-site DMRG for your problem?</p>
<p>Thanks,<br>
Miles</p>
http://itensor.org/support/3485/single-site-dmrg-c?show=3488#a3488Thu, 16 Sep 2021 22:40:23 +0000Answered: Very simple scalar contraction
http://itensor.org/support/3467/very-simple-scalar-contraction?show=3474#a3474
<p>Given the arrays <code>A</code>, <code>a</code>, <code>b</code>, <code>c</code>, <code>f</code>, <code>e</code>, you can just do:</p>
<pre><code>n = ndims(A)
is = Tuple(Index(size(A, n)) for n in 1:5)
Ait = itensor(A, is)
Ms = (a, b, c, f, e)
tn = [itensor(Ms[j], is[j]) for j in 1:n]
pushfirst!(tn, Ait)
contract(tn)
</code></pre>
<p>For number of dimensions <code>n == 5</code>, I get this result: <code>9.823 μs (73 allocations: 14.75 KiB)</code>, so much slower than <code>LoopVectorization</code>. This isn't entirely surprising for such small dimensions, since ITensor uses a transpose-transpose-gemm-transpose (TTGT) approach (<a rel="nofollow" href="https://arxiv.org/pdf/1607.00145.pdf),">https://arxiv.org/pdf/1607.00145.pdf),</a> where we first permute the tensor data so the contraction can be performed as a matrix multiplication. Therefore, we do the contractions pairwise, and each contraction potentially has a nontrivial amount of intermediate data allocated.</p>
<p>On the other hand, in this case <code>LoopVectorization</code> is able to perform the calculation with no intermediate tensor values, and also does a bunch of tricks to perform the loops in very efficient ways. I'm curious how they compare for larger tensor orders and dimensions, but this very specific tensor contraction that reduces to a single number may be better suited for the strategy that <code>LoopVectorization</code> takes (and in principle we can detect this kind of contraction and dispatch to <code>LoopVectorization</code> for special contractions like this, which we would like to investigate).</p>
<p>As for performing the calculation on GPU, you should be able to just install the ITensorsGPU package (<a rel="nofollow" href="https://github.com/ITensor/ITensorsGPU.jl)">https://github.com/ITensor/ITensorsGPU.jl)</a> and perform the contraction like this instead:</p>
<pre><code>using ITensorsGPU
tn_gpu = cu.(tn)
contract(tn_gpu)
</code></pre>
<p>Note that I've found that using single precision (<code>Float32</code>) gives the best performance on GPU, so you may want to try that.</p>
http://itensor.org/support/3467/very-simple-scalar-contraction?show=3474#a3474Fri, 10 Sep 2021 19:00:04 +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 +0000Answered: Overlaps with odd number of fermion operators
http://itensor.org/support/3376/overlaps-with-odd-number-of-fermion-operators?show=3420#a3420
<p>(Please see discussion above.)</p>
http://itensor.org/support/3376/overlaps-with-odd-number-of-fermion-operators?show=3420#a3420Wed, 01 Sep 2021 14:51:47 +0000Answered: Julia ITensor: SVD of an ITensor with QN dimension wrong?
http://itensor.org/support/3356/julia-itensor-svd-of-an-itensor-with-qn-dimension-wrong?show=3419#a3419
<p>Thanks again for the question. To close this question, we looked into this behavior and found that it is currently the expected behavior of the code, because of subtleties of truncating block-sparse tensors when there are degenerate, or nearly degenerate eigenvalues near the cutoff point (or requested maxdim value). Presumably there could be a different way to do things where the requested maxdim is always satisfied as long as the cutoff is small enough, but the library code would need to be significantly more complicated and there still might be some surprising “edge cases”. </p>
<p>So we will continue to think about this issue but will treat it as a future enhancement rather than a bug for now.</p>
<p>Miles</p>
http://itensor.org/support/3356/julia-itensor-svd-of-an-itensor-with-qn-dimension-wrong?show=3419#a3419Wed, 01 Sep 2021 14:47:23 +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 +0000Answered: Calculating observables from density matrices
http://itensor.org/support/3350/calculating-observables-from-density-matrices?show=3413#a3413
<p>For the part of your question (in comments above) about preparing the initial state MPO, since it is a tensor product of local operators, you can make each operator separately as an ITensor and then "load" them into an MPO by assigning the tensors of the MPO one by one (in a for loop of course) to be the operators you want.</p>
<p>For example, just showing the first site:</p>
<p>N = 100<br>
s = siteinds("S=1/2",N)</p>
<p>rho = MPO(N)</p>
<p>rho[1] = op("Id",s[1]) + mu*op("Sz",s[1])</p>
<p>and similar for sites 2,...N/2 in a for loop (use div(N,2) to get N/2 in Julia). Then another loop to go from N/2+1 to N with the other sign for the Sz term.</p>
<p>Some of our algorithms may complain if there are not virtual or link indices between the tensors of the MPO. If that happens, let us know and we can recommend a course of action. Thanks!</p>
<p>Miles</p>
http://itensor.org/support/3350/calculating-observables-from-density-matrices?show=3413#a3413Wed, 01 Sep 2021 02:23:55 +0000Answered: Reading MPS from mps.h5 that contains complex numbers
http://itensor.org/support/3397/reading-mps-from-mps-h5-that-contains-complex-numbers?show=3407#a3407
<p>Answer is in the comment above.</p>
http://itensor.org/support/3397/reading-mps-from-mps-h5-that-contains-complex-numbers?show=3407#a3407Tue, 31 Aug 2021 19:27:44 +0000Answered: How to construct Bose-Hubbard model?
http://itensor.org/support/3295/how-to-construct-bose-hubbard-model?show=3394#a3394
<p>(Please see discussion above & marking this question as answered.)</p>
http://itensor.org/support/3295/how-to-construct-bose-hubbard-model?show=3394#a3394Mon, 30 Aug 2021 18:06:50 +0000Answered: Finite temperature initial wave function for spin-1
http://itensor.org/support/3384/finite-temperature-initial-wave-function-for-spin-1?show=3388#a3388
<p>Hi Javad,<br>
Good question. The part you would need to change are the lines of the form wf.set(…); These are the lines which initialize the tensor wf to be a “Bell pair” or some kind of perfectly entangled state between sites s1 and s2. For the case of a code that is not trying to conserve quantum numbers, it doesn’t matter which maximally entangled state you choose here, as the ‘ancilla’ sites get traced out anyway, so all you need to do is to work out some kind of maximally entangled state for a pair of S=1 spins on paper, then define the non-zero components of wf to put it into that state.</p>
<p>In the above code, the non-zero components are the |1>|2> and |2>|1> components, with amplitudes 1/sqrt(2) and -1/sqrt(2) respectively, making a S=1/2 singlet state. So you would need to adjust and generalize that code for a maximally entangled state of a pair of S=1 spins.</p>
<p>Best,<br>
Miles </p>
http://itensor.org/support/3384/finite-temperature-initial-wave-function-for-spin-1?show=3388#a3388Mon, 30 Aug 2021 15:25:03 +0000Answered: How do I time evolve an MPO in Julia?
http://itensor.org/support/3324/how-do-i-time-evolve-an-mpo-in-julia?show=3386#a3386
<p>See the comments above.</p>
http://itensor.org/support/3324/how-do-i-time-evolve-an-mpo-in-julia?show=3386#a3386Mon, 30 Aug 2021 15:18:52 +0000Answered: How to capture the long-range order with spontaneous symmetry breaking
http://itensor.org/support/3349/capture-long-range-order-with-spontaneous-symmetry-breaking?show=3379#a3379
<p>Hi Yi, the questions and issues you raise here are good ones. First of all, regarding your three ideas, I would say there is no single best one, but it depends on various details like the kind of order you are studying, the sizes of systems you can reach, and the accuracy of your calculations. Let us get back to that in a moment.</p>
<p>One point you raised is about SU(2) conservation of DMRG and the idea that not having it could prevent seeing symmetry breaking. In fact, the situation is the exact opposite: conserving a symmetry means the code is not allowed to break that symmetry, even if the actual physical system would. For example, if one conserves Z2 spin parity in the transverse-field Ising model (something you can do in ITensor since it is an Abelian symmetry), then the ground states DMRG will return in the symmetry breaking ferromagnetic phase will actually be linear combinations of all spins up plus all spins down, thus not actually breaking the symmetry. Whereas if you studied the system with all symmetry conservation turned off, then the code could return a ground state which is just all spins up, say (or all spins down and which one depends on subtle details of your initial state).</p>
<p>This ties into your other point about finite systems not being able to break a symmetry. Technically this is absolutely correct, however in practice the energy difference between a state which breaks the symmetry and one which does not is extremely tiny, and goes to zero exponentially with system size. So in DMRG, unless you study rather small systems and push the calculation to very high accuracy, often the approximate ground state DMRG returns will in fact break the symmetry if that is what the system wants to do. But also in practice DMRG might not break the symmetry in a "clean" way, and could return a state which is some mixture of two or more of the symmetry-equivalent ground states. Which brings me to my next point.</p>
<p>The safest "best practice" for observing symmetry breaking with DMRG is usually your third idea, about applying a field. Except here the best idea is usually to apply the field only at the edges of the system, so that you minimally disrupt the physics in the bulk of the system. See for example this review article which discusses this idea in more detail: <a rel="nofollow" href="https://arxiv.org/abs/1105.1374">https://arxiv.org/abs/1105.1374</a><br>
With the edge-pinning idea, you don't have to adjust the size of the field, but can just adjust the length of your system and do finite-size scaling, which is nice.</p>
<p>Measuring correlation functions can also be a good idea, but because you are measuring the square of two operators, this quantity can be affected more by approximations such as the truncation of an MPS that is done by DMRG. The number that you obtain from this method is smaller and so can be harder to converge. But in many cases it can still be a good method to use, because it can be an easier method for detecting complicated orders which might be more easily missed by just guessing an order parameter to measure.</p>
<p>So briefly, I would usually recommend a combination of (1) and (3), with the fields in (3) only applied at the edges. But (2) can also be a good option. Ideally trying both together and comparing the results is the best, especially when first exploring a new system and trying to understand it.</p>
<p>Hope that's helpful -</p>
<p>Miles</p>
http://itensor.org/support/3349/capture-long-range-order-with-spontaneous-symmetry-breaking?show=3379#a3379Sun, 29 Aug 2021 18:53:38 +0000Answered: [Julia] Julia DMRG gives inconsistent result for weak interactions
http://itensor.org/support/3351/julia-julia-dmrg-gives-inconsistent-result-weak-interactions?show=3369#a3369
<p>Thanks for catching this issue. I have just created a fix for the OpSum / AutoMPO system that makes the Hamiltonian more accurate in this case.</p>
<p><a rel="nofollow" href="https://github.com/ITensor/ITensors.jl/pull/726">https://github.com/ITensor/ITensors.jl/pull/726</a></p>
<p>Please let me know if the other issue persists, where even after many DMRG sweeps the result does not match ED closely enough.</p>
<p>Miles</p>
http://itensor.org/support/3351/julia-julia-dmrg-gives-inconsistent-result-weak-interactions?show=3369#a3369Fri, 27 Aug 2021 16:21:24 +0000Answered: Error in using MPS loaded from mps.h5 file in julia
http://itensor.org/support/3359/error-in-using-mps-loaded-from-mps-h5-file-in-julia?show=3364#a3364
<p>Hi Mason,<br>
Yes, your diagnosis is correct about what is causing the issue. There are two ways around this:</p>
<p>1) you can write the <code>sites</code> array to your HDF5 file too, and read it back in instead of making a new sites array. Then when you make your MPO using AutoMPO, it will use your old sites array and things will match.</p>
<p>2) we have a function called <code>replace_siteinds(M::MPS,sites)</code> which given an MPS <code>M</code> and an array of site indices <code>sites</code>, will replace all of the site indices of M (it figures these out for you) by the new ones in the provided array. So in your case you would just call <code>psi = replace_siteinds(psi,sites)</code> before using <code>psi</code> in your code. There is an in-place version too called <code>replace_siteinds!</code>.</p>
<p>Hope that helps!</p>
<p>Miles</p>
http://itensor.org/support/3359/error-in-using-mps-loaded-from-mps-h5-file-in-julia?show=3364#a3364Thu, 26 Aug 2021 22:41:46 +0000Answered: mixed spin-1/2 and spin-1
http://itensor.org/support/3358/mixed-spin-1-2-and-spin-1?show=3362#a3362
<p>Hi Javad,<br>
Thanks for the question. This is a case we had thought about quite a bit, so we have a way to do it in both the C++ and Julia versions of ITensor. I'll give an answer for both.</p>
<p>---- Julia ITensor ----</p>
<p>Starting from a usual DMRG code such as the one in this example: </p>
<p><a rel="nofollow" href="https://itensor.github.io/ITensors.jl/stable/examples/DMRG.html">https://itensor.github.io/ITensors.jl/stable/examples/DMRG.html</a></p>
<p>right after making the <code>siteinds</code> array (which is just a Julia array of indices), modify the first and last indices to be S=1/2 indices, like this</p>
<pre><code>N = 100
sites = siteinds("S=1",N)
sites[1] = siteind("S=1/2")
sites[N] = siteind("S=1/2")
</code></pre>
<p>---- C++ ITensor ----</p>
<p>Starting from the usual DMRG code for a S=1 chain, such as the sample code here:</p>
<p><a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/v3/sample/dmrg.cc">https://github.com/ITensor/ITensor/blob/v3/sample/dmrg.cc</a></p>
<p>change the line <code>auto sites = SpinOne(N);</code> to include an extra named argument asking for the edge spins to be spin-half, like this:</p>
<pre><code>auto sites = SpinOne(N,{"SHalfEdge=",true});
</code></pre>
http://itensor.org/support/3358/mixed-spin-1-2-and-spin-1?show=3362#a3362Thu, 26 Aug 2021 22:34:02 +0000Answered: Adding a single site to an MPS [Julia]
http://itensor.org/support/3344/adding-a-single-site-to-an-mps-julia?show=3346#a3346
<p>Hi, so this is definitely something you can do, but needs to be done “manually” by manipulating MPS tensors. The procedure I would use is this:</p>
<p>Say you have an original MPS psi with length(psi)==N.</p>
<ol>
<li><p>define a new MPS with one more tensor than before:<br>
M = MPS(N+1)</p></li>
<li><p>copy most of the MPS tensors unchanged, such as M[1] = psi[1]; M[2] = psi[2]; etc.</p></li>
<li><p>wherever you want to add the ancilla, make the tensor there be the outer product of an identity matrix connecting the virtual or link index from the previous MPS tensor to the next MPS tensor. Outer product into this the tensor defining the state of the ancilla site. Graphically it would look like this:</p>
<pre><code> |
O
———————
</code></pre></li>
</ol>
<p>Hope that gives you enough to get started on it. </p>
<p>For quantum numbers, you would need the identity matrix to have the appropriate arrows to match the link indices of the neighboring MPS tensors. </p>
<p>An alternative to all of this is to define your original MPS on the enlarged system from the very beginning, with the ancilla already there, and just ignore or skip over the ancilla in your original calculation or preparation that makes the MPS (such as a DMRG calculation, but with a Hamiltonian that skips over the ancilla site). Then later it will still be there and you can couple to it.</p>
<p>Miles</p>
http://itensor.org/support/3344/adding-a-single-site-to-an-mps-julia?show=3346#a3346Mon, 23 Aug 2021 19:37:24 +0000Answered: Using kwargs with ITensors.op and AutoMPO in Julia
http://itensor.org/support/3322/using-kwargs-with-itensors-op-and-autompo-in-julia?show=3343#a3343
<p>Thanks for this feedback. These are great suggestions and I think we should implement this feature. I just created an enhancement issue to remind us to do it:</p>
<p><a rel="nofollow" href="https://github.com/ITensor/ITensors.jl/issues/722">https://github.com/ITensor/ITensors.jl/issues/722</a></p>
http://itensor.org/support/3322/using-kwargs-with-itensors-op-and-autompo-in-julia?show=3343#a3343Thu, 19 Aug 2021 02:30:17 +0000Answered: Issue using eigen() in Julia
http://itensor.org/support/3334/issue-using-eigen-in-julia?show=3342#a3342
<p>Thanks again. We've filed this as a bug and will fix it: <a rel="nofollow" href="https://github.com/ITensor/ITensors.jl/issues/721">https://github.com/ITensor/ITensors.jl/issues/721</a></p>
<p>Glad you have a workaround in the meantime!</p>
http://itensor.org/support/3334/issue-using-eigen-in-julia?show=3342#a3342Thu, 19 Aug 2021 02:27:16 +0000Answered: [Julia] Spin gap behavior and boundary effects
http://itensor.org/support/3330/julia-spin-gap-behavior-and-boundary-effects?show=3333#a3333
<p>Hi, thanks for the question. The j=1:2:N loop makes me a bit nervous since j+1 might be greater than N. But I guess not as long as N is an even number, since the last value there will be j=N-1. </p>
<p>But the key issue here, I would bet, is that you are just not doing enough DMRG sweeps. Especially when obtaining excited states with DMRG, it’s important to check that enough sweeps have been done, because for excited states convergence can be rather slow. </p>
<p>Relatedly, I don’t recommend putting a sequence of DMRG calculations into one big loop (the loop over <code>i</code> here). It’s tempting, but almost every time I’ve seen users do it, the resulting problem is that they are studying different points in their phase diagram using the same DMRG settings, whereas near phase transitions or at various other harder points, they need to do a more careful study of DMRG convergence in both number of sweeps and other parameters such as maxdim and cutoff.</p>
<p>Please also check that at various points your results are converged in those parameters (maxdim and cutoff) too, since if you don’t have convergence in those, it could also strongly affect what gaps you find.</p>
<p>Finally, these kinds of phases (Haldane) phase can have subtle zero-energy edge states which can complicate how one calculates and defines the gap. Please check that the state you are treating as the first excited state is not actually a second, third, or even fourth degenerate ground state.</p>
<p>Hope that helps!</p>
<p>Miles</p>
http://itensor.org/support/3330/julia-spin-gap-behavior-and-boundary-effects?show=3333#a3333Tue, 17 Aug 2021 13:50:23 +0000Answered: Entanglement Entropy from density matrix
http://itensor.org/support/3306/entanglement-entropy-from-density-matrix?show=3328#a3328
<p>Hi Vittorio,<br>
As we discussed, one option is to compute the second Renyi entropy of a density matrix which is represented as an MPO. This can be done efficiently; I believe the von Neumann entropy is more complicated and harder to obtain.</p>
<p>Here is a short note I made about how to obtain the second Renyi entropy of an MPO:</p>
<p><a rel="nofollow" href="https://itensor.org/RenyiMPO.pdf">https://itensor.org/RenyiMPO.pdf</a></p>
<p>Please let me know if you have questions of course. To perform the traces, you can use the "delta" function in ITensor to make an identity or Kronecker delta ITensor, and contract it with each MPO tensor you want to trace.</p>
<p>Miles</p>
http://itensor.org/support/3306/entanglement-entropy-from-density-matrix?show=3328#a3328Mon, 16 Aug 2021 22:00:26 +0000Answered: New sitetype with julia
http://itensor.org/support/3313/new-sitetype-with-julia?show=3318#a3318
<p>Hi, thanks for pointing out this issue! We have fixed it, and it will be fixed in the new version 0.2.5 which will be available in the next few hours or so (after the Julia registration system updates).</p>
<p>Miles</p>
http://itensor.org/support/3313/new-sitetype-with-julia?show=3318#a3318Wed, 11 Aug 2021 00:50:24 +0000Answered: expectation value of expH
http://itensor.org/support/3132/expectation-value-of-exph?show=3300#a3300
<p>Hi LZ,<br>
Sorry for the slow reply on this. Hope the answer is still useful, or feel free to ask an updated question on the forum. </p>
<p>As Matt correctly said above, the MPO returned by toExpH is not very close to 1-tau<em>H but of a more complicated form with significant higher-order terms. So the imaginary part probably receives a large correction from these terms compared to what you'd expect from 1-tau</em>H.</p>
<p>What was your goal in trying to compute this? Were you just wanting to learn about how toExpH works? If so, I can point you to a very helpful paper which it is based on. If something else, please let us know.</p>
<p>Thanks,<br>
Miles</p>
http://itensor.org/support/3132/expectation-value-of-exph?show=3300#a3300Wed, 04 Aug 2021 20:39:21 +0000Answered: Product of many local operators
http://itensor.org/support/3289/product-of-many-local-operators?show=3294#a3294
<p>Hi Marcin,<br>
Thanks for the question. It's helpful to see the structure of your operator, which as I understand is a product of single-site operators. So then actually you should not have to use an MPO at all, or any machinery to sum operators or multiply MPOs together. </p>
<p>(1) Instead you can just apply each operator onto each tensor of your MPS to compute the product D|psi>. If you call the resulting (unnormalized) state |phi> = D|psi> you can then compute the overlap <phi|psi> to obtain the expectation value <psi|D|psi>. </p>
<p>(2) Alternatively you could think of D as an MPO, but which has a bond dimension of 1, so it is just a product of operators. In that approach, AutoMPO is not really the best tool to use to make the MPO. Instead it would be better to make the MPO "by hand" by setting each MPO tensor one by one. </p>
<p>I would recommend approach #1 above. To perform the action of D onto |psi> you could write code similar to in this "code formula" page to apply each operator d_j onto your MPS:<br>
<a rel="nofollow" href="http://itensor.org/docs.cgi?vers=cppv3&page=formulas/mps_onesite_op">http://itensor.org/docs.cgi?vers=cppv3&page=formulas/mps_onesite_op</a> <br>
By looping over all j from 1 to N you will end up with the state |phi> = D|psi>.<br>
Then you can just use the function <code>inner</code> to compute <code>inner(phi,psi)</code> to get your expectation value.</p>
<p>Hope that helps - we can discuss more if you have questions.</p>
<p>Miles</p>
http://itensor.org/support/3289/product-of-many-local-operators?show=3294#a3294Tue, 03 Aug 2021 21:15:32 +0000Answered: Write/Read tensors in HDF5 format between C++v3 and Julia version
http://itensor.org/support/3277/write-read-tensors-in-hdf5-format-between-and-julia-version?show=3291#a3291
<p>Hi Yi,<br>
As Matt indicated, this is a feature we have been planning but was not quite yet finished. But now I have finished adding support for all ITensor types and objects with the exception of complex-valued ITensors. As long as your data is real, you should be able to write it to HDF5 (including MPS and MPO objects) and read it again in the Julia version of ITensor.</p>
<p>To obtain this functionality, please do a "git pull" on the "v3" branch of C++ ITensor to get the latest code there.</p>
<p>As an example of how to write objects to HDF5 files, please see the code in unittest/hdf5_test.cc and in general the pattern is like this:</p>
<pre><code>//Make an MPS
auto N = 4;
auto s = SpinHalf(N,{"ConserveQNs=",false});
auto M = randomMPS(s,4);
//Write the MPS to an HDF5 file named "test.h5" to a group (folder) named "mps_M"
auto fo = h5_open("test.h5",'w');
h5_write(fo,"mps_M",M);
close(fo);
</code></pre>
<p>Please let us know if you have any questions or run into any trouble using this feature.</p>
<p>Best,<br>
Miles</p>
http://itensor.org/support/3277/write-read-tensors-in-hdf5-format-between-and-julia-version?show=3291#a3291Tue, 03 Aug 2021 04:37:45 +0000Answered: How to get the MPO of L^+L from the one of L ?[julia]
http://itensor.org/support/3276/how-to-get-the-mpo-of-l-l-from-the-one-of-l-julia?show=3278#a3278
<p>Hi JR,<br>
Thanks for the question. In Julia this function is called <code>contract</code>. Here is the documentation on it:</p>
<p><a rel="nofollow" href="https://itensor.github.io/ITensors.jl/dev/MPSandMPO.html#ITensors.NDTensors.contract-Tuple{MPO,%20MPO}">https://itensor.github.io/ITensors.jl/dev/MPSandMPO.html#ITensors.NDTensors.contract-Tuple{MPO,%20MPO}</a></p>
<p>Please let us know if you don't get the results you expect. A good way to test that this is working as you want is to make random MPS using the <code>randomMPS</code> function and compute matrix elements of your squared MPO as well as in an exact way using the function inner(A,psi,B,psi) where A and B are MPOs. The function inner(A,psi,B,psi) computes <psi|A^+ B|psi> using a different algorithm so would provide a good check.</p>
<p>Best,<br>
Miles</p>
http://itensor.org/support/3276/how-to-get-the-mpo-of-l-l-from-the-one-of-l-julia?show=3278#a3278Tue, 27 Jul 2021 14:31:48 +0000