ITensor Support Q&A - Recent questions and answers
http://itensor.org/support/qa
Powered by Question2AnswerAnswered: Use removeQNs to partially remove QNs for MPS in Anderson-Holstein Model
http://itensor.org/support/1809/removeqns-partially-remove-qns-mps-anderson-holstein-model?show=1810#a1810
<p>Feng,<br>
This is a great idea for a feature we should have, so I opened an issue for it on our issue tracker page on Github.</p>
<p>However, unfortunately we will not be able to add this feature soon, as once we thought about the technical steps they are somewhat involved and we are also working to complete the Julia version of ITensor.</p>
<p>As a short-term fix, would you be able to just not conserve boson number in your initial ground state calculation? Maybe the ground state of that Hamiltonian has zero boson number anyway? Or if not, maybe you can include a chemical potential term to tune to the zero-boson-number ground state case?</p>
<p>You can always measure the total expected boson number after DMRG of course, to check.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1809/removeqns-partially-remove-qns-mps-anderson-holstein-model?show=1810#a1810Mon, 11 Nov 2019 18:08:21 +0000Answered: Using itensor as basis for a mathematical toolbox
http://itensor.org/support/1795/using-itensor-as-basis-for-a-mathematical-toolbox?show=1808#a1808
<p>Hi Sebastian,<br>
Thanks for sharing about your plans. Yes, it is indeed an error to put two copies of exactly the same Index on an ITensor, due to the fact that it would lead to an ambiguity when using the star operation to contract. (It does make me think of a possibly interesting future idea where we do allow it, but then enforce the tensor elements must remain symmetry under exchange of identical indices...)</p>
<p>That is great you are planning to implement heuristics for optimal contraction order. That is something we definitely want to add too, we are just thinking of the best place to handle it, whether automatically / internally, or by calling a certain function.</p>
<p>We are actually very interested in having ITensor become more useful for general applied math applications beyond quantum physics. But since applied math topics are quite diverse, we cannot always anticipate what functionality will be needed. So I think we will continue implementing ones we know about (automatic differentiation; point-wise non-linearities; Khatri-Rao product; slicing would be four off-hand examples of things we don't have but would like to) and also rely very much on feedback from users about additional features they need.</p>
<p>So please do share with us any ideas you have about making ITensor better. And we do have lots of features coming in the future but it will take a bit of time since we are doing an entire port to the Julia language currently (though almost done!).</p>
<p>Miles</p>
http://itensor.org/support/1795/using-itensor-as-basis-for-a-mathematical-toolbox?show=1808#a1808Fri, 08 Nov 2019 16:52:58 +0000Answered: Are extremely small singular values (less than ~10^-15) trustworthy?
http://itensor.org/support/1806/are-extremely-small-singular-values-less-than-trustworthy?show=1807#a1807
<p>Good question, though I don't feel comfortable giving a totally absolute answer. It's one of those "it depends" things as with any very technical matter.</p>
<p>But as a rule of thumb, when working with double-precision floating point numbers most operations are only trustworthy to about a precision of 10^-13 or so. This is because, among other reasons, that while double can store numbers much more precise than that, precision losses occur when subtracting two similar numbers for example. It's hard to avoid these kinds of operations in most algorithms of course.</p>
<p>Here is a sample calculation I just did in the Julia REPL to illustrate this:</p>
<p>Start by generating some random numbers:</p>
<p>julia> r1 = rand()<br>
0.034238108102722764</p>
<p>julia> r2 = rand()<br>
0.7802465824048777</p>
<p>julia> r3 = rand()<br>
0.09507249159735309</p>
<p>Now do some arithmetic and then undo it</p>
<p>julia> x = (r1/r2)*r3-100<br>
-99.9958281108584</p>
<p>julia> y = (100+x)/r3*r2 # y should equal r1 if using exact arithmetic<br>
0.03423810810274365</p>
<p>julia> r1<br>
0.034238108102722764 # you can see the last few digits differ from y</p>
<p>julia> y-r1<br>
2.0886070650760757e-14</p>
http://itensor.org/support/1806/are-extremely-small-singular-values-less-than-trustworthy?show=1807#a1807Fri, 08 Nov 2019 16:44:26 +0000Answered: Lapack flags missing in sample/tutorial makefiles?
http://itensor.org/support/1794/lapack-flags-missing-in-sample-tutorial-makefiles?show=1804#a1804
<p>Haha, god damn it. This took me one hour. You are correct, somehow FLAGS became FLASG, but I have do idea how this happened. I fixed it and now your original makefiles work. Thanks!</p>
http://itensor.org/support/1794/lapack-flags-missing-in-sample-tutorial-makefiles?show=1804#a1804Fri, 08 Nov 2019 10:26:59 +0000Answered: Severe Discrepancy between MPO and Trotter Time-Evolution?
http://itensor.org/support/1789/severe-discrepancy-between-mpo-and-trotter-time-evolution?show=1802#a1802
<p>In addition to Matt's answer, which I also agree looks very likely to be the issue, I'd like to note that we have been finding that the toExpH approach to performing time evolution has not always been the most reliable unfortunately (though it depends on details of the Hamiltonian and time step size etc.). So in general you might not be able to get as good of results with that method as, say, the Trotter method for cases where both can be used.</p>
<p>In the near future, we are planning to offer alternative time evolution methods which will supersede the toExpH approach.</p>
<p>Miles</p>
http://itensor.org/support/1789/severe-discrepancy-between-mpo-and-trotter-time-evolution?show=1802#a1802Thu, 07 Nov 2019 19:04:36 +0000Answered: How to realize Kondo-Heisenberg model with good quantum number on ITensor-3
http://itensor.org/support/1781/realize-kondo-heisenberg-model-with-quantum-number-itensor?show=1792#a1792
<p>Hello,</p>
<p>The error you are seeing when you try to conserve Nf but not Sz is due to the fact that currently in ITensor, you can't use a SiteSet that has some indices with QNs and some without. When you set <code>"ConserveSz=",false</code>, in the <code>SpinHalfSite</code> definition it will lead to the case where the Index is made without any QNs. If you would like to make that case work, you could try changing this line:</p>
<p><a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/v3/itensor/mps/sites/spinhalf.h#L59">https://github.com/ITensor/ITensor/blob/v3/itensor/mps/sites/spinhalf.h#L59</a></p>
<p>from <code>s = Index(2,ts);</code> to <code>s = Index(QN(),2,ts);</code> (I haven't tried it, so please let us know if that works). This will make an Index with an empty QN, which should work. It may be a good idea for us to add an option for that case. One could argue that if you set <code>"ConserveQNs=",true</code> and <code>"ConserveSz=",false</code> then it should default to making an Index with empty QNs.</p>
<p>As for the cases you are seeing that are running without error but are not converging, you may have to play around with the <code>Sweeps</code> object, like changing the bond dimension growth schedule, the noise, or the number of davidson iterations. Perhaps someone else (like Miles) can comment on strategies for getting more complicated Hamiltonians like this to converge with DMRG.</p>
<p>-Matt</p>
http://itensor.org/support/1781/realize-kondo-heisenberg-model-with-quantum-number-itensor?show=1792#a1792Mon, 04 Nov 2019 15:45:42 +0000Different results for spin up and down
http://itensor.org/support/1786/different-results-for-spin-up-and-down
<p>Hi,</p>
<p>I'm running tDMRG for a simple anderson impurity coupled to two semi-infinite chain at different chemical potential, but get different dynamics for different spin states. Details are following:</p>
<p>First in the DMRG part, I decouple left chain, impurity, right chain to calculate the ground state of the decoupled system. Left chain and right chain are both half filled with same number of spin-up and spin-down electrons, and impurity is empty. My DMRG results are correct compared with analytic results (for a finite chain with even number of sites, the ground state of half filling has exactly local occupation of 0.5 for both spin-up and spin-down states.)</p>
<p>Secondly, I quench the whole system by coupling the impurity site and chains, and measure the dynamics of local occupation of spin-up and spin-down states. But these two occupations deviate very fast, which is unphysical considering that the Hamiltonian is symmetric under spin inversion). See the following results</p>
<p>t=0.01, Nup = 0.000945655, Ndn = 0.000945656<br>
t=0.02, Nup = 0.00370455, Ndn = 0.0037134 <br>
t=0.03, Nup = 0.00812654, Ndn = 0.00818666<br>
t=0.04, Nup = 0.0140243, Ndn = 0.0142351<br>
t=0.05, Nup = 0.0211824, Ndn = 0.0217184<br>
t=0.06, Nup = 0.0293665, Ndn = 0.03049 <br>
t=0.07, Nup = 0.0383324, Ndn = 0.0404003<br>
t=0.08, Nup = 0.0478346, Ndn = 0.0512999<br>
t=0.09, Nup = 0.057634, Ndn = 0.0630419<br>
t=0.10, Nup = 0.0675047, Ndn = 0.0754844</p>
<p>My code is:<br>
#include"itensor/all.h"<br>
#include <math.h><br>
#include <br>
using namespace itensor;</p>
<pre><code>int main(int argc, char *argv[])
{
float U=4;
float e0=-2;
float tb=10;
float td=3.1623;
float V=4;
int L=101;
double tau=0.01;
float t_tot=3;
auto Nc=L/2+1;//center site, impurity
double el=V/2;
double er=-V/2;
//Read ground-state
Electron sites;
readFromFile("site_file",sites);
MPS psi(sites);
readFromFile("ground_state",psi);
auto ampo = AutoMPO(sites);
//Right Chain
for(int j=Nc+1;j <=L-1; j+=1)
{
ampo += -tb,"Cdagup",j,"Cup",j+1;
ampo += -tb,"Cdagup",j+1,"Cup",j;
ampo += -tb,"Cdagdn",j,"Cdn",j+1;
ampo += -tb,"Cdagdn",j+1,"Cdn",j;
ampo += er,"Ntot",j;
}
ampo+=er,"Ntot",L;
//Left chain
for(int j=1;j < Nc-1; j+=1)
{
ampo += -tb,"Cdagup",j,"Cup",j+1;
ampo += -tb,"Cdagup",j+1,"Cup",j;
ampo += -tb,"Cdagdn",j,"Cdn",j+1;
ampo += -tb,"Cdagdn",j+1,"Cdn",j;
ampo += el,"Ntot",j;
}
ampo+=el,"Ntot",Nc-1;
//Impurity site
ampo+=e0,"Ntot",Nc;
ampo+=U,"Nup",Nc,"Ndn",Nc;
//Coupling
ampo+= -td,"Cdagup",Nc-1,"Cup",Nc;
ampo+= -td,"Cdagup",Nc,"Cup",Nc-1;
ampo+= -td,"Cdagdn",Nc-1,"Cdn",Nc;
ampo+= -td,"Cdagdn",Nc,"Cdn",Nc-1;
ampo+= -td,"Cdagup",Nc+1,"Cup",Nc;
ampo+= -td,"Cdagup",Nc,"Cup",Nc+1;
ampo+= -td,"Cdagdn",Nc+1,"Cdn",Nc;
ampo+= -td,"Cdagdn",Nc,"Cdn",Nc+1;
auto nt=round(t_tot/tau);
auto expH=toExpH(ampo,tau*Cplx_i);
auto args=Args("Method=","DensityMatrix","Cutoff=",1E-9,"MaxDim=",1000);
Real Ild, Ilu, Ird, Iru, nu, nd;
for(int j=1;j<=nt;j++){
psi=applyMPO(expH,psi,args);
psi.noPrime().normalize();
printf("t=%g\n",tau*j);
psi.position(Nc);
//Occu
nu=std::real(eltC(psi(Nc)*Nu*dag(prime(psi(Nc),"Site"))));
nd=std::real(eltC(psi(Nc)*Nd*dag(prime(psi(Nc),"Site"))));
printf("Nu=%g, Nd=%g, ",nu,nd);
return 0;
}
</code></pre>
<p>Can anyone help? THANK YOU!</p>
http://itensor.org/support/1786/different-results-for-spin-up-and-downMon, 04 Nov 2019 00:32:07 +0000Answered: Difference between S_x S_x +S_y S_y and S+S- +S-S+ for MPO
http://itensor.org/support/1782/difference-between-s_x-s_x-s_y-s_y-and-s-s-s-s-for-mpo?show=1784#a1784
<p>Hi, thanks for the question.</p>
<p>So I believe the answer to your first question is that S+S- + S-S+ is proportional to SxSx + SySy, not SxSx+SzSz. So unless your wavefunction is perfectly spin-rotationally invariant you will in general get a different answer when measuring these operators which are different.</p>
<p>You don’t have to convert operators to S+ S- form if you aren’t conserving the total Sz quantum number. However if you are conserving total Sz, you must input your Hamiltonian in terms of operators which change total Sz by a well-defined amount, so mainly Sz, S+, and S- (and not Sx or Sy).</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1782/difference-between-s_x-s_x-s_y-s_y-and-s-s-s-s-for-mpo?show=1784#a1784Sun, 03 Nov 2019 02:59:17 +0000Answered: Problem about convergence of tJ model
http://itensor.org/support/1780/problem-about-convergence-of-tj-model?show=1783#a1783
<p>Hi, thanks for the question. Are you using the very latest version of ITensor on the v3 branch? We recently fixed a bug specifically with the tJ site set which was causing Hamiltonians made from it to not be Hermitian, which could lead to the behavior you are seeing.</p>
<p>Please pull and recompile ITensor and then please let me know if the behavior persists. If it does we'll be happy to look deeper into it.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1780/problem-about-convergence-of-tj-model?show=1783#a1783Sat, 02 Nov 2019 15:20:06 +0000Answered: tDMRG parallel calculation
http://itensor.org/support/1774/tdmrg-parallel-calculation?show=1775#a1775
<p>Thanks for the question. We don’t have a parallel time evolution code available. Just out of curiosity though, what part of the algorithm were you hoping to parallelize and did you mean across multiple cores or using MPI across different nodes?</p>
<p>Best regards,<br>
Miles </p>
http://itensor.org/support/1774/tdmrg-parallel-calculation?show=1775#a1775Thu, 24 Oct 2019 13:33:03 +0000Answered: How to calculate two-operator correlation functions with conserved quantum numbers
http://itensor.org/support/1768/calculate-operator-correlation-functions-conserved-quantum?show=1769#a1769
<p>Hi, so instead of removing QNs at all, I would recommend using the fact that Sx = (S+ + S-)/2. Then if you measure four correlation functions: </p>
<pre><code><S+ S+>, <S+ S->, <S- S+>, <S- S->
</code></pre>
<p>, you can recombine those numbers to get </p>
<pre><code><Sx Sx>
</code></pre>
<p>. It doesn’t require any extra code if you wrap your measurement code in a function and pass the operator names into this function in the four combinations above.</p>
<p>Does that sound good to you?</p>
<p>Miles</p>
http://itensor.org/support/1768/calculate-operator-correlation-functions-conserved-quantum?show=1769#a1769Tue, 15 Oct 2019 01:02:40 +0000Answered: Error while compiling itebd package
http://itensor.org/support/1764/error-while-compiling-itebd-package?show=1765#a1765
<p>Hi, so I believe the error is coming because you are perhaps using the v3 branch of ITensor, whereas the iTEBD code requires the v2 branch. Please try switching to the v2 branch (git checkout v2) and recompiling (make clean; make).</p>
<p>Also, please note that the iTEBD code is maintained by a separate developer from us, and not maintained as part of ITensor. We are happy to help you to try to get it to work, but if it ultimately requires fixing bugs in that code you will need to contact the developer of it.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1764/error-while-compiling-itebd-package?show=1765#a1765Tue, 08 Oct 2019 14:24:00 +0000Answered: Difference between "Fit" and "DensityMatrix" for ApplyMPO
http://itensor.org/support/1753/difference-between-fit-and-densitymatrix-for-applympo?show=1754#a1754
<p>Hello,</p>
<p>The "DensityMatrix" algorithm is described here:</p>
<p><a rel="nofollow" href="http://tensornetwork.org/mps/algorithms/denmat_mpo_mps/">http://tensornetwork.org/mps/algorithms/denmat_mpo_mps/</a></p>
<p>It is a direct method (in that it only requires one sweep over the system), and is very reliable. However, it's accuracy may be limited to around 1e-8, because it relies on forming the density matrix which involves squaring the singular values, which can decrease the precision (but that is only an issue if you need very high precision).</p>
<p>The "Fit" algorithm involves variationally optimizing the overlap between an initial guess MPS and the MPO*MPS you are interesting in approximating with a sweeping algorithm similar to DMRG. It is known to get "stuck" (i.e. not find the correct MPS approximation) if the initial guess is not very good, or may take a lot of sweeps to converge (so you may want to try increasing the number of sweeps). This algorithm scales better with the bond dimensions of the input MPS/MPO compared to the "DensityMatrix" method.</p>
<p>If in your code applying the MPO to the MPS is not a performance bottleneck, and you do not need very high precision for your final MPS, then the "DensityMatrix" method is better to use. Otherwise, you will need to use the "Fit" method (and possibly play around with finding a better initial guess in order to get it to converge properly).</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1753/difference-between-fit-and-densitymatrix-for-applympo?show=1754#a1754Tue, 01 Oct 2019 14:32:46 +0000Answered: Implementing AutoMPO for thermal state calculations
http://itensor.org/support/1751/implementing-autompo-for-thermal-state-calculations?show=1752#a1752
<p>So I figured it out, it was somewhere else in my code that the issue was arising. For anyone else having the same issue, AutoMPO automatically puts the identity on operators that are not specified.</p>
http://itensor.org/support/1751/implementing-autompo-for-thermal-state-calculations?show=1752#a1752Tue, 01 Oct 2019 01:44:41 +0000Answered: Time evolution of Hamiltonian containing 4-operator term with MPO.
http://itensor.org/support/1749/time-evolution-hamiltonian-containing-operator-term-with?show=1750#a1750
<p>Hi, so unfortunately our toExpH feature is limited to Hamiltonians consisting of at most 2-operator terms only. The reason is that it's technical to extend the same method that lets AutoMPO work for > 2 operator terms to also define the exponential of H, even though in principle this could be done perhaps.</p>
<p>But additionally, since implementing toExpH, we and the tensor network community have found that MPO-based time evolution is not a particulary reliable or accurate time-evolution method (in relative terms, since it does work but just not as well) compared to other methods. The best method to use would be TDVP which only needs the Hamiltonian MPO as input. (See the recent review by Paeckel et al. for a technical discussion of both time-evolution methods.) So this is unfortunate given the convenience of MPO methods, but is a useful thing to keep in mind.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1749/time-evolution-hamiltonian-containing-operator-term-with?show=1750#a1750Thu, 26 Sep 2019 16:42:08 +0000Answered: Can an Observer function access pre- and post- truncation eigenvalues?
http://itensor.org/support/1747/can-observer-function-access-post-truncation-eigenvalues?show=1748#a1748
<p>Hi Jon,<br>
So looking at the current ITensor code, the Spectrum object only contains the post-truncation density matrix eigenvalues. This could be modified if you really need them. Probably an easier way to go about this, though (if cost isn't a huge issue), would be to do the SVD twice inside of DMRG: once without any truncation, then a second time with truncation.</p>
<p>To do the SVD step twice, just repeat line 404 of this file:<br>
<a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/v3/itensor/mps/dmrg.h">https://github.com/ITensor/ITensor/blob/v3/itensor/mps/dmrg.h</a></p>
<p>but the first time, write the line like this:</p>
<p>auto spec_full = psi.svdBond(b,phi,(ha==1?Fromleft:Fromright),PH,{args,"Truncate=",false});</p>
<p>The "spec_full" Spectrum object should have the full spectrum contained inside.</p>
<p>As you can see from line 423 of dmrg.h, the Observer is given the truncation error though its args. Take a look at this file:<br>
<a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/v3/itensor/mps/DMRGObserver.h">https://github.com/ITensor/ITensor/blob/v3/itensor/mps/DMRGObserver.h</a><br>
to see how DMRGObserver grabs this truncation error, and takes a max over it over each sweep, only reporting the max. You could modify DMRGObserver or make your own observer which does a different thing with the truncation error information.</p>
<p>Due to limitations of C++, the observer doesn't have access to the spectrum. You'll have to modify the code in dmrg.h directly to save / print / otherwise access the spectrum during DMRG.</p>
<p>Finally, definitely consider also how meaningful the spectrum of eigenvalues is <em>during</em> DMRG versus that of the MPS <em>after</em> DMRG. As you know, these eigenvalues during DMRG will change depending on many possible, reasonable choices of the sweep parameters. So they might not be precisely physically meaningful, and rather reflect how the optimization was done. But of course toward the later sweeps, they should become close to those of the fully optimized MPS.</p>
<p>Miles</p>
http://itensor.org/support/1747/can-observer-function-access-post-truncation-eigenvalues?show=1748#a1748Tue, 24 Sep 2019 11:59:37 +0000Answered: Allocate an ITensor with given index structure
http://itensor.org/support/1732/allocate-an-itensor-with-given-index-structure?show=1737#a1737
<p>Hello,</p>
<p>An easy way to replace the indices of an ITensor is by multiplying with a series of delta tensors. If the original tensor has indices {i,j,k} and you want it changed to {a,b,c}, you can do:</p>
<pre><code>G2 = G2 * delta(i,a) * delta(j,b) * delta(k,c);
</code></pre>
<p>In your case, {i,j,k} would be the indices of G2, and {a,b,c} would be the corresponding indices of G1.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1732/allocate-an-itensor-with-given-index-structure?show=1737#a1737Mon, 16 Sep 2019 18:32:42 +0000Answered: TRG sample code provided on the hompage produces errors during compilation
http://itensor.org/support/1733/sample-provided-hompage-produces-errors-during-compilation?show=1734#a1734
<p>Thank you for catching that, that needs to be fixed in the way that you show.</p>
<p>The correct code can be found in the "sample" directory of the ITensor library (<a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/v3/sample/trg.cc">https://github.com/ITensor/ITensor/blob/v3/sample/trg.cc</a> ), we forgot to update the website with the proper code.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1733/sample-provided-hompage-produces-errors-during-compilation?show=1734#a1734Mon, 16 Sep 2019 13:58:19 +0000Answered: Question about InputGroup and Args
http://itensor.org/support/1724/question-about-inputgroup-and-args?show=1727#a1727
<p>Hi Nick,<br>
I'm not sure I understand the part of your question about the input parameters changing mid program. I believe when you read in the input file the parameters are set at that point (are read into the InputGroup object), then when you retrieve them they will be whatever they were when the file was read. Are you planning on changing your input file while your program is running? Conceptually that's possible but I would not recommend it.</p>
<p>In terms of how the input.h / InputGroup system relates to Args, they were developed separately so don't really interoperate. At one point I made them have a similar interface so it would be easier to remember how to use them. I did plan to later on make them more interoperable, like having the option to retrieve the input parameters as an Args object. But I had more pressing things so haven't done it. It would be a good project for someone to do and I think would not be too hard; the code for each is relatively straightforward and well written I think.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1724/question-about-inputgroup-and-args?show=1727#a1727Fri, 13 Sep 2019 17:49:20 +0000Answered: Efficient calculation of magnetization susceptibility
http://itensor.org/support/1719/efficient-calculation-of-magnetization-susceptibility?show=1720#a1720
<p>Hi RS,<br>
Good question. Yes: making an MPO is definitely the way to go. I've used this technique before and it works very well. </p>
<p>In fact, there is some code here you can use or copy to make the MPO:<br>
<a rel="nofollow" href="https://github.com/emstoudenmire/finiteTMPS/blob/master/S2.h">https://github.com/emstoudenmire/finiteTMPS/blob/master/S2.h</a></p>
<p>(It is ITensor v2 code, which shouldn't be hard to upgrade to v3 if you read our guide, or we can chat about it).</p>
<p>For measuring expectation values of MPOs, there's no need to think about the gauge of the MPS. The reason is that the algorithm to compute the expectation value contracts the entire MPS with the MPO with another (entire) copy of the MPS. So the gauge simply plays no role.</p>
<p>In ITensor (v3) you can use the function inner(psi,W,psi) where W is your MPO to compute <psi|W|psi>. Use innerC if your MPS is complex-valued.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1719/efficient-calculation-of-magnetization-susceptibility?show=1720#a1720Mon, 02 Sep 2019 18:41:41 +0000Answered: std::bad_alloc in Transfer Matrix calculation
http://itensor.org/support/1712/std-bad_alloc-in-transfer-matrix-calculation?show=1713#a1713
<p>Hi Yixuan,<br>
Yes, the reason for this error message is that your system has run out of memory / RAM. So one solution is definitely to try a system with more RAM if possible.</p>
<p>But another solution could be to write any large tensors you are not using at a particular step to disk. You can estimate the size of various tensors by multiplying the dimension of their indices together. Using this estimate, you might find that individual MPS tensors themselves aren't using a lot of memory, but tensors formed from the MPS can use a very large amount. (Or you might find that the MPS tensors alone are using a lot of memory; it depends on the details.)</p>
<p>We have some automatic facilities to write parts of an MPS to disk. But these may not work ideally for a transfer matrix calculation and are designed mostly to be used inside a DMRG calculation. </p>
<p>But you can even do writing to disk manually by just writing a tensor to a particular file with a good file name, then overwriting the tensor with an empty tensor to 'free' it from memory. Later, when you need the tensor again you can read it back in from the file and overwrite the read-in tensor onto your empty tensor to restore it.</p>
<p>If you decide to follow one of the three approaches above and run into issues, please post a comment below or a new question.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1712/std-bad_alloc-in-transfer-matrix-calculation?show=1713#a1713Thu, 29 Aug 2019 20:20:26 +0000Answered: Error with symmetry while measuring the properties of an MPS wavefunction (with conserved QNs)
http://itensor.org/support/1704/error-symmetry-measuring-properties-wavefunction-conserved?show=1711#a1711
<p>Hello,</p>
<p>An immediate thing to note is that since the state you are measuring has a well-defined Sz quantum number, measuring Sx will always be zero (since the Sx operator will change the total spin of your state, so Sx|psi> will have a different total Sz from |psi> so <psi|Sx|psi> must be zero).</p>
<p>However, this question brought up the fact that this operation is currently not as easy as it should be to do right now in ITensor. Currently, this is the easiest way I can think of to measure a non-QN conserving operator of a QN-conserving MPS:</p>
<pre><code>auto N = 10;
auto sites = SpinOne(N);
auto state = InitState(sites,"Up");
auto psi = MPS(state);
// Measure Sx on site j
auto j = 3;
psi.position(j);
// Get the site index without QNs
auto sj = removeQNs(sites(j));
// Create a SpinOneSite from the Index
// without QNs to use in the op function
auto Sxj = op(SpinOneSite(sj),"Sx");
auto sxj = elt(psi(j)*Sxj*dag(prime(psi(j),"Site")));
PrintData(sxj);
</code></pre>
<p>We are discussing alternative solutions to be able to do this more generally (without manually modifying the Index and then creating the correct Site type), but unfortunately they require fairly technical solutions right now given the current system.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1704/error-symmetry-measuring-properties-wavefunction-conserved?show=1711#a1711Thu, 29 Aug 2019 14:30:29 +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 +0000Answered: What is "restricted sweeping over sub-region" as described in docs?
http://itensor.org/support/1700/what-is-restricted-sweeping-over-sub-region-described-docs?show=1702#a1702
<p>Hello,</p>
<p>In the documentation page you link to (<a rel="nofollow" href="https://itensor.org/docs.cgi?page=classes/dmrg">https://itensor.org/docs.cgi?page=classes/dmrg</a> ) the last DMRG version listed can be used for "restricted sweeping".</p>
<p>That version accepts boundary tensors that represent the Hamiltonian projected into a fixed basis (you can think of it as a boundary condition for the DMRG calculation). You would have to pre-calculate those boundary tensors by projecting your Hamiltonian into the MPS basis you are interested in. </p>
<p>If you have any questions about how it would be used, please let us know.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1700/what-is-restricted-sweeping-over-sub-region-described-docs?show=1702#a1702Tue, 27 Aug 2019 14:30:25 +0000Answered: Segmentation fault when trying to read in site and wavefunctions
http://itensor.org/support/1683/segmentation-fault-when-trying-read-site-and-wavefunctions?show=1699#a1699
<p>Question is answered in above comments</p>
http://itensor.org/support/1683/segmentation-fault-when-trying-read-site-and-wavefunctions?show=1699#a1699Fri, 23 Aug 2019 00:54:10 +0000Answered: Index does not contain given QN block
http://itensor.org/support/1665/index-does-not-contain-given-qn-block?show=1666#a1666
<p>Hi, so one thing that jumps out at me is that you already give the vector "v" a size, but then use emplace_back to put things into it, which will put more things at the end, still leaving 2*dim+1 default-initialized pair<QN,long> 's at the beginning.</p>
<p>There may be other issues but this looks like a definite one!</p>
<p>Miles</p>
http://itensor.org/support/1665/index-does-not-contain-given-qn-block?show=1666#a1666Thu, 08 Aug 2019 18:27:20 +0000Answered: solve an eigenvalue problem of non-hermitian tensor
http://itensor.org/support/1615/solve-an-eigenvalue-problem-of-non-hermitian-tensor?show=1664#a1664
<p>I ported <code>arnoldi</code> to ITensor V3 to find dominant eigenvectors and eigenvalues of non-Hermitian sparse matrices. You can take a look at these tests:</p>
<p><a rel="nofollow" href="https://github.com/ITensor/ITensor/blob/v3/unittest/iterativesolvers_test.cc#L252">https://github.com/ITensor/ITensor/blob/v3/unittest/iterativesolvers_test.cc#L252</a></p>
<p>to get an idea for how it is used.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1615/solve-an-eigenvalue-problem-of-non-hermitian-tensor?show=1664#a1664Wed, 07 Aug 2019 20:37:39 +0000Answered: Different boson number cutoffs for different sites
http://itensor.org/support/1639/different-boson-number-cutoffs-for-different-sites?show=1659#a1659
<p>Just to begin answering this question - it’s a good question.</p>
<p>Yes you can definitely create two different types of sites when making your own site set in ITensor. This is easier to do and works better in version 3 of ITensor. </p>
<p>Essentially all you have to do is to first follow the procedure for making each type of site separately, using classes like BosonSite as an example, but adjust the dimension of the site index and/or range of the quantum numbers to what you want. </p>
<p>Now that you have two different site classes, “AType” and “BType” say, you can make your site set as:<br>
using MySiteSet = MixedSiteSet<AType,BType>; <br>
which will make the odd-numbered sites be AType sites and the even-numbered sites BType sites.</p>
<p>See the sample/mixedspin.cc sample code for an example of this using in action.</p>
<p>Alternatively, if the AType and BType sites are similar enough in their design, you could have them be just the same type and control their properties through passing named arguments (Args) and looking at the site number when constructing them. But this could ultimately make things more complicated, since when getting operators you will also have to put in checks about what kind of site you are making operators for.</p>
<p>Which of the above two ways to go depends then on the details.</p>
<p>Good luck! </p>
<p>Miles</p>
http://itensor.org/support/1639/different-boson-number-cutoffs-for-different-sites?show=1659#a1659Wed, 07 Aug 2019 14:45:10 +0000Answered: Pass vector of QNs to create Index
http://itensor.org/support/1650/pass-vector-of-qns-to-create-index?show=1658#a1658
<p>For those who are interested, this is the solution:</p>
<pre><code> ExcitonSite(Args const& args = Args::global())
{
dim = args.getInt("on_site_dim", 5);
auto ts = TagSet("Site,Exciton");
int n = args.getInt("SiteNumber");
ts.addTags("n="+str(n));
auto v = std::vector<std::pair<QN, long int>>(2 * dim + 1);
int cntr = 0;
for (int j = -dim; j <= dim; ++j)
{
auto q = QN({"Sz",j});
v.emplace_back(q, 1);
}
s = Index(std::move(v),Out,ts);
}
</code></pre>
http://itensor.org/support/1650/pass-vector-of-qns-to-create-index?show=1658#a1658Tue, 06 Aug 2019 21:28:30 +0000Answered: Subspace expansion to get excited states
http://itensor.org/support/1648/subspace-expansion-to-get-excited-states?show=1653#a1653
<p>Hi Titas,</p>
<p>Can you extend the subspace expansion trick from that paper to excited states by replacing the use of <code>H</code> by <code>H - |psi0><psi0|</code>, where <code>|psi0></code> is the ground state you previously found? </p>
<p>It looks like the expansion term they use just depends on the current guess for the MPS you are optimizing and the MPO you are finding the ground state of, so you should be able to extend the formulas in the paper for the case when the MPO is a sum of MPOs, i.e. the Hamiltonian plus the projector onto the ground state.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1648/subspace-expansion-to-get-excited-states?show=1653#a1653Mon, 05 Aug 2019 21:05:12 +0000Answered: Overwriting MPS tensors loses/invalidates index information?
http://itensor.org/support/1651/overwriting-tensors-loses-invalidates-index-information?show=1652#a1652
<p>Hello,</p>
<p>Could you please post some sample code so we know what you are trying to achieve? Are you taking two MPS and trying to partial Kronecker product them together? Having more information would help us debug what is going on and figure out the best way to proceed.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1651/overwriting-tensors-loses-invalidates-index-information?show=1652#a1652Mon, 05 Aug 2019 20:54:53 +0000optimizing over product states
http://itensor.org/support/1640/optimizing-over-product-states
<p>Hi, </p>
<p>I am trying to run a DMRG optimizing over product states. <br>
My guess was setting maxm = 1 in the final sweeps. </p>
<p>I used the following setup:</p>
<pre><code>Sweeps sweeps = Sweeps(15);
sweeps.maxm() = 5,10,20,50,100,50,20,10,5,1;
sweeps.cutoff() = 1E-15;
sweeps.niter() = 2,2,2,3,4,3,2,2,1;
sweeps.noise() = 1e-4,1e-5,1e-6,1e-7,1e-8,0;
dmrg(psi0, H, sweeps);
</code></pre>
<p>The problem is, once in a while, the DMRG keeps m=0 and I get a segfault, e.g.,</p>
<pre><code>Sweep=9, HS=1, Bond=1/2
I 0 q 8E-13 E -0.1662838484
I 1 q 8E-13 E -0.1662838484
Truncated to Cutoff=1.0E-15, Min_m=1, Max_m=5
Trunc. err=0.0E+00, States kept: m=2
Sweep=9, HS=1, Bond=2/2
I 0 q 8E-13 E -0.1662838484
I 1 q 7E-13 E -0.1662838484
Truncated to Cutoff=1.0E-15, Min_m=1, Max_m=5
Trunc. err=0.0E+00, States kept: m=2
Sweep=9, HS=2, Bond=2/2
I 0 q 7E-13 E -0.1662838484
I 1 q 7E-13 E -0.1662838484
Truncated to Cutoff=1.0E-15, Min_m=1, Max_m=5
Trunc. err=0.0E+00, States kept: m=2
Sweep=9, HS=2, Bond=1/2
I 0 q 7E-13 E -0.1662838484
I 1 q 7E-13 E -0.1662838484
Truncated to Cutoff=1.0E-15, Min_m=1, Max_m=5
Trunc. err=0.0E+00, States kept: m=2
vN Entropy at center bond b=1 = 0.693147179809
Eigs at center bond b=1: 0.5000 0.5000
Largest m during sweep 9/15 was 2
Largest truncation error: 0
Energy after sweep 9/15 is -0.166283848350
Sweep 9/15 CPU time = 0.000961s (Wall time = 0.00123s)
Sweep=10, HS=1, Bond=1/2
I 0 q 7E-13 E -0.1662838484
I 1 q 7E-13 E -0.1662838484
Truncated to Cutoff=1.0E-15, Min_m=1, Max_m=1
Trunc. err=5.0E-01, States kept: m=0
Sweep=10, HS=1, Bond=2/2
Intel MKL ERROR: Parameter 14 was incorrect on entry to cblas_dgemm.
Intel MKL ERROR: Parameter 9 was incorrect on entry to cblas_dgemm.
</code></pre>
<p>First, i thought it was the MKL, but it also happens with the OSX Accelerate framework. Btw., I am using v2.</p>
<p>I chose such sweeps.maxm() to give it room to escape local minima, but I don't know whether it is the best approach to optimize over product states.</p>
<p>Any thoughts on that?</p>
<p>Thanks in advance,</p>
http://itensor.org/support/1640/optimizing-over-product-statesWed, 31 Jul 2019 20:03:59 +0000Answered: Different index structure after applying MPO to MPS
http://itensor.org/support/1634/different-index-structure-after-applying-mpo-to-mps?show=1637#a1637
<p>Hello,</p>
<p>The short answer is that in V3, you should unprime the output MPS in order to make it have unprimed site indices:</p>
<pre><code>auto Hpsi = applyMPO(H,psi);
Hpsi.noPrime("Site");
</code></pre>
<p>This was a change made to the <code>applyMPO</code> function in V3. In V2, <code>applyMPO</code> automatically unprimed the output MPS. However, this was making an assumption that the MPO had indices of the form (s1,s1',s2,s2',...). This is however not always the case, for example in other tensor network algorithms where the indices on either side of the MPO are completely different (but the algorithm for applying an MPO to an MPS works essentially the same). Basically, it was a tradeoff between making the algorithm much more general but a bit more inconvenient for certain use cases.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1634/different-index-structure-after-applying-mpo-to-mps?show=1637#a1637Wed, 31 Jul 2019 13:35:57 +0000Answered: Different DMRG results between Version 3 and Version 2?
http://itensor.org/support/1633/different-dmrg-results-between-version-3-and-version-2?show=1635#a1635
<p>Hi Jin, it could be a number of things but most likely it’s some recent changes to the truncation logic used in the SVD (or density matrix diagonalization) part of DMRG.</p>
<p>Is the energy decreasing slower than before, and if so by a significant amount? If it’s decreasing faster than this is actually a good thing and would be evidence that the changes we made were a success. </p>
<p>Best regards,<br>
Miles </p>
http://itensor.org/support/1633/different-dmrg-results-between-version-3-and-version-2?show=1635#a1635Wed, 31 Jul 2019 04:23:01 +0000Answered: How to get the MPO of H^2 from the one of H ?
http://itensor.org/support/1627/how-to-get-the-mpo-of-h-2-from-the-one-of-h?show=1630#a1630
<p>Hi Yas,</p>
<p>The new version of <code>nmultMPO</code> in V3 works a little bit differently from the one from V2. Now, the input is a little bit more "literal", in that it finds the indices common to the two input MPOs, contracts over those, and returns an MPO with the indices that are not common between the two MPOs. </p>
<p>In short, you should call the function like this:</p>
<pre><code>auto res = nmultMPO(H, prime(H),{"Cutoff",1e-8});
res.mapPrime(2,1);
</code></pre>
<p>to get the same thing as ITensor V2. </p>
<p>The problem was that the function wasn't working since it was automatically contracting over all of the site indices of the input MPO. However, this should have a better error message, I will add a check for that.</p>
<p>To explain why the behavior changed, the reason is that there are many MPOs you could make (such as in more general tensor networks) that don't have pairs of indices (s1,s1',s2,s2',...), and that wasn't allowed in the previous version. The new behavior makes the code a bit more general (and I personally feel is a bit more intuitive, since now contracting MPOs works more like contracting ITensors).</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1627/how-to-get-the-mpo-of-h-2-from-the-one-of-h?show=1630#a1630Mon, 29 Jul 2019 21:39:09 +0000Answered: How to add two MPS of different QN blocks
http://itensor.org/support/1626/how-to-add-two-mps-of-different-qn-blocks?show=1629#a1629
<p>Hi Chenrong,</p>
<p>If I understand your question correctly, the short answer is that you cannot add IQMPS/IQTensors with different total QN, since it would result in an IQMPS/IQTensor with ill-defined QN flux. You should be able to convert the IQMPS to MPS using the <code>toMPS</code> function (<a rel="nofollow" href="http://www.itensor.org/docs.cgi?vers=cppv2&page=classes/mps">http://www.itensor.org/docs.cgi?vers=cppv2&page=classes/mps</a> ) and then add them together.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1626/how-to-add-two-mps-of-different-qn-blocks?show=1629#a1629Mon, 29 Jul 2019 20:05:15 +0000Answered: Support of QR decomposition for a very large sparse 2-D matrix
http://itensor.org/support/1616/support-of-qr-decomposition-for-a-very-large-sparse-d-matrix?show=1618#a1618
<p>Hi Victor,</p>
<p>Unfortunately we don't have support for general sparse tensors beyond the ones that you listed (though that would be great to have). For now and in the foreseeable future you would have to look for another library for that.</p>
<p>Cheers,<br>
Matt</p>
http://itensor.org/support/1616/support-of-qr-decomposition-for-a-very-large-sparse-d-matrix?show=1618#a1618Tue, 23 Jul 2019 19:04:29 +0000Answered: Difference in convention while calculating norm
http://itensor.org/support/1611/difference-in-convention-while-calculating-norm?show=1612#a1612
<p>Hi Aditya,<br>
Yes, that is the reason for giving those functions the specific names that they have, where inner means an inner or dot product, so no square root, while norm involves a square root by definition. But please let me know if you were expecting something different. </p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1611/difference-in-convention-while-calculating-norm?show=1612#a1612Sat, 20 Jul 2019 21:13:52 +0000Answered: The tensors calculated by idmrg do not obey the right orthogonality condition.
http://itensor.org/support/1242/tensors-calculated-idmrg-obey-right-orthogonality-condition?show=1605#a1605
<p>Hi, sorry for the very slow reply. I think the issue may be where you write</p>
<pre><code>psi.A(ni-1)
</code></pre>
<p>The .A method of an MPS is 1-indexed. On the other hand, it does allow you to input A(0), but this retrieves the "center" tensor which has no site index, and is the singular values resulting from a Schmidt decomposition of the infinite system done between two unit cells. So it should not obey the right-orthogonal gauge. I understand this is not well documented. So for version 3 we are moving the iDMRG code to a separate "code" project and planning to replace it with a better implementation that is also better documented.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1242/tensors-calculated-idmrg-obey-right-orthogonality-condition?show=1605#a1605Wed, 17 Jul 2019 03:55:20 +0000Answered: svd compiling error with itensor v3
http://itensor.org/support/1602/svd-compiling-error-with-itensor-v3?show=1603#a1603
<p>Hi, thanks for reporting this issue. However, I was not able to reproduce it unfortunately. Could you please post some minimal code that you were trying to compile that led to getting this message? (So like the contents of myappname.cc?) Thanks!</p>
<p>Miles</p>
http://itensor.org/support/1602/svd-compiling-error-with-itensor-v3?show=1603#a1603Wed, 17 Jul 2019 03:37:54 +0000Answered: whether itensor can realize cavity induced model?
http://itensor.org/support/1599/whether-itensor-can-realize-cavity-induced-model?show=1600#a1600
<p>Hi Weijie,<br>
Yes, DMRG and ITensor can be used to study a Hamiltonian of this type (and any Hamiltonian which is a sum of local terms on a lattice). </p>
<p>But special care has to be taken with bosons, as you know, since one has to make their Hilbert space finite in some way. So you could use the Boson site set in ITensor and adjust the MaxOcc parameter to make sure your results are converged with the maximum boson occupancy per site. </p>
<p>Your other question about Hubbard-Holstein might be relevant for others reading this question, so I'm linking it here: <a rel="nofollow" href="http://itensor.org/support/1502/how-to-realize-hubbard-holstein-model?show=1502#q1502">http://itensor.org/support/1502/how-to-realize-hubbard-holstein-model?show=1502#q1502</a></p>
http://itensor.org/support/1599/whether-itensor-can-realize-cavity-induced-model?show=1600#a1600Tue, 16 Jul 2019 15:06:02 +0000Answered: Get partial tensor
http://itensor.org/support/1592/get-partial-tensor?show=1596#a1596
<p>Hi Aditya,<br>
Good to meet you in person and discuss, but I'll also post the answer here.</p>
<p>To fix, clamp, or set an index to a particular value, a good solution is to contract the tensor with another tensor produced by the "setElt" function. (See setElt on this page: <a rel="nofollow" href="http://itensor.org/docs.cgi?vers=cppv3&page=classes/itensor).">http://itensor.org/docs.cgi?vers=cppv3&page=classes/itensor).</a> Calling setElt(i=n) makes an ITensor which has the index "i" and has a component 1.0 in the nth entry, and zero otherwise.</p>
<p>Then you can multiply it by your tensor T like: T *= setElt(i=n).</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1592/get-partial-tensor?show=1596#a1596Mon, 15 Jul 2019 14:37:46 +0000Answered: Write a CMatrix type to file.
http://itensor.org/support/1588/write-a-cmatrix-type-to-file?show=1590#a1590
<p>Hi Nick,<br>
This was just something that was missing; I didn't define reading and writing of the "range" type that matrices use to store their column and row size. I just defined that and pushed the change to Github. So if you do "git pull" and recompile ITensor you should now be able to use writeToFile with CMatrix.</p>
<p>Thanks for the bug report!</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1588/write-a-cmatrix-type-to-file?show=1590#a1590Wed, 10 Jul 2019 13:58:43 +0000Answered: Can I use ITensor for CTMRG?
http://itensor.org/support/1586/can-i-use-itensor-for-ctmrg?show=1589#a1589
<p>Hi Tatsuo,<br>
Yes, you can definitely use ITensor to perform CTMRG calculations. However, we do not have a pre-written CTMRG code that we provide, so you would have to write it yourself. </p>
<p>As you know, the key steps of CTMRG are tensor contractions and singular value decompositions of certain tensors. ITensor lets you do both of these operations very conveniently.</p>
<p>Please let me know if you do begin writing it and need help with how to perform a certain step.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1586/can-i-use-itensor-for-ctmrg?show=1589#a1589Wed, 10 Jul 2019 13:52:17 +0000Answered: Seg fault in sum
http://itensor.org/support/1582/seg-fault-in-sum?show=1587#a1587
<p>I solved this issue by adding</p>
<pre><code> V[0].position(c);
WP[0].position(c);
WP[0].replaceSiteInds(siteInds(V[0]));
</code></pre>
<p>To make sure the positions and the indices matched before adding. For some reason the sum function that takes a vector of MPS' does not work, but at least this does.</p>
http://itensor.org/support/1582/seg-fault-in-sum?show=1587#a1587Wed, 10 Jul 2019 06:29:01 +0000Error when calculating excited states (with conserved quantities)
http://itensor.org/support/1581/error-when-calculating-excited-states-conserved-quantities
<p>Hi!</p>
<p>The issue I have is similar to one found <a rel="nofollow" href="http://itensor.org/support/441/segmentation-fault-in-calculation-of-excited-states?show=441#q441">here</a>. It looks like it's still there.</p>
<p>I want to calculate few excited states for spin-1/2 XY model. <br>
Since total Sz is conserved, I want to restrict myself to a sector with fixed nonzero Sz (equal to <strong>SzSector</strong> in the code below). I do so by picking <strong>InitState</strong> which belongs to this sector, and putting <strong>ConserveQNs=true</strong>.</p>
<p>However, I still can catch the segfault, with the following error message:</p>
<blockquote>
<p>div(T1)=QN({"Sz",-2}) must equal div(T2)=QN() when adding T1+T2</p>
</blockquote>
<p>While for SzSector=+1 I get:</p>
<blockquote>
<p>div(T1)=QN({"Sz",2}) must equal div(T2)=QN({"Sz",0}) when adding T1+T2</p>
</blockquote>
<p>The minimal (non-)working example code is following:</p>
<pre><code>#include "itensor/all.h"
using namespace itensor;
int main(int argc, char* argv[]) {
int N = 20;
int SzSector = -1;
int nstates = 2;
// Building Hamiltonian
auto sites = SpinHalf(N, {"ConserveQNs=", true});
auto ampo = AutoMPO(sites);
for (int x = 1; x <= N-1; x++) {
ampo += -1,"S+",x,"S-",x+1;
ampo += -1,"S-",x,"S+",x+1;
}
MPO H = toMPO(ampo);
// Preparing random initial state
InitState state(sites);
for (int i = 1; i <= N; i++) {
state.set(i, i <= N/2 + SzSector ? "Up" : "Dn");
}
//MPS psi0 = randomMPS(state);
MPS psi0(state);
// Initializing sweep parameters
auto sweeps = Sweeps(5);
sweeps.maxdim() = 200;
sweeps.cutoff() = 1e-9;
sweeps.niter() = 2;
sweeps.noise() = 1e-9;
// DMRG
std::vector<MPS> states;
std::vector<double> energies;
for (int i = 0; i < nstates; i++) {
auto [energy,psi] = dmrg(H, states, psi0, sweeps, {"Quiet=", true, "Weight=", 20.0});
states.push_back(psi);
energies.push_back(energy);
}
return 0;
}
</code></pre>
<p>The code with <strong>randomMPS(state)</strong> doesn't work as well.</p>
http://itensor.org/support/1581/error-when-calculating-excited-states-conserved-quantitiesMon, 08 Jul 2019 20:20:14 +0000Answered: Spin S Hamiltonians with quadratic terms
http://itensor.org/support/1578/spin-s-hamiltonians-with-quadratic-terms?show=1579#a1579
<p>Hi Jacopo,<br>
Although it sounds tedious, the approach you'll need to take is to just expand the dot product into a sum of products of non-vector-operator terms. It should only make your AutoMPO input for loops a bit more complicated but AutoMPO will be able to handle this input well and give you an optimally compressed MPO. </p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1578/spin-s-hamiltonians-with-quadratic-terms?show=1579#a1579Mon, 08 Jul 2019 13:51:30 +0000Answered: Compatibility problem for reading MPS from disk
http://itensor.org/support/1570/compatibility-problem-for-reading-mps-from-disk?show=1573#a1573
<p>Hi Yixuan,<br>
To answer your first question, at the moment the file formats used by ITensor are not guaranteed to be stable to version changes, due to the fact that we write out the binary representation of objects in memory. So they are also not guaranteed to work across different machines with different binary formats. So it's still a useful feature for writing objects to disk and reading them back throughout a single calculation or within the same version of ITensor, but not meant as a long-term storage solution.</p>
<p>One feature we are planning to add after we first address some other things is to add support for HDF5. Then we can have long-term stability of ITensors written to disk.</p>
<p>To answer your other question, I think you are right that combining TagSets and Index's in the prime function doesn't currently work. So as a work-around for now, please just call prime twice with the different arguments you would like to use and that should work. But also could you please file an issue about allowing this combination since I think it would be straightforward for Matt to add it.</p>
<p>Thanks,<br>
Miles</p>
http://itensor.org/support/1570/compatibility-problem-for-reading-mps-from-disk?show=1573#a1573Thu, 04 Jul 2019 17:14:25 +0000Answered: Apply a local operator to an MPS
http://itensor.org/support/1569/apply-a-local-operator-to-an-mps?show=1572#a1572
<p>Hi Nick,<br>
Yixuan's answer is correct and his solution is good. I also just added a code formula here with an answer to your question:<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></p>
<p>The formula I added is a bit more general, e.g. assuming the operator could come from anywhere and not only the op(sites,"Sz",i) function, though that is a very good way to get the "Sz" operator for your case. Also the formula does not call psi.position(i) because strictly speaking it's not necessary to do so for a one-site operation (since no truncation afterward is involved) but it can still be a good idea for reasons I discuss at the end of the formula page.</p>
<p>Miles</p>
http://itensor.org/support/1569/apply-a-local-operator-to-an-mps?show=1572#a1572Thu, 04 Jul 2019 17:06:24 +0000Create random initial MPS and IQMPS with given bond dimension
http://itensor.org/support/1567/create-random-initial-mps-and-iqmps-with-given-bond-dimension
<p>Hello,</p>
<p>I was wondering if is there an easy way in ITensor to initialise a state into a random MPS or IQMPS with given bond dimension. Most of the available routines are indeed to initialise random product states but not states with larger bond dimension. <br>
Thanks a lot! </p>
<p>Best,<br>
Jacopo.</p>
http://itensor.org/support/1567/create-random-initial-mps-and-iqmps-with-given-bond-dimensionFri, 28 Jun 2019 19:12:56 +0000