ITensor Support Q&A - Recent questions and answers
http://itensor.org/support/qa
Powered by Question2AnswerAnswered: Cannot find libiomp5 & libpthread in MKL library
http://itensor.org/support/1079/cannot-find-libiomp5-%26-libpthread-in-mkl-library?show=1080#a1080
<p>Hi, so the exact flags you have to use varies with different installations of MKL and different versions unfortunately. On our cluster at my office, I have to include also some headers associated with the Intel compiler to get MKL to work properly (though I don't believe this is necessary in general).</p>
<p>As you can see in your mkl/lib/intel64 folder, there are no libiomp5.so and libpthread.so files so that's the immediate reason why you're getting the error. As to where these files actually are on your system, that sort of depends.</p>
<p>A very useful thing to do can be to use the Intel "Link Line Advisor" website which asks you some questions about your system then recommends linker flags:</p>
<p><a rel="nofollow" href="https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor">https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor</a></p>
<p>Hope that helps -</p>
<p>Miles</p>
http://itensor.org/support/1079/cannot-find-libiomp5-%26-libpthread-in-mkl-library?show=1080#a1080Wed, 19 Sep 2018 02:01:41 +0000Answered: A potential low level bug with MPS class
http://itensor.org/support/1065/a-potential-low-level-bug-with-mps-class?show=1075#a1075
<p>Hi, thanks for the report - could you please email me a code that reproduces the issue? (Ideally with the minimal amount of code and running time to still see the issue.) Otherwise I don't know if I'll be able to see where it could be happening since I haven't been observing this behavior. </p>
<p>Thanks!</p>
<p>Miles</p>
http://itensor.org/support/1065/a-potential-low-level-bug-with-mps-class?show=1075#a1075Sun, 16 Sep 2018 01:58:10 +0000Is it possible to use toExpH more-than-two-operator terms ?
http://itensor.org/support/1071/is-it-possible-to-use-toexph-more-than-two-operator-terms
<p>If not. Can one suggest something which can be implemented using itensor library.</p>
<p>THanks.</p>
http://itensor.org/support/1071/is-it-possible-to-use-toexph-more-than-two-operator-termsFri, 14 Sep 2018 18:49:41 +0000Answered: Exponentiating autompo with 3-site operators
http://itensor.org/support/1062/exponentiating-autompo-with-3-site-operators?show=1063#a1063
<p>Hi, so AutoMPO's containing more than two-site operators cannot currently be exponentiated using the toExpH feature. It is a feature we'd like to add soon.</p>
<p>If you definitely need to time evolve a Hamiltonian with more than two-site terms, then an alternative could be to use a "time step targeting" method such as TDVP or the method described in this paper:<br>
<a rel="nofollow" href="https://arxiv.org/abs/1706.09537">https://arxiv.org/abs/1706.09537</a></p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1062/exponentiating-autompo-with-3-site-operators?show=1063#a1063Wed, 05 Sep 2018 21:49:54 +0000Answered: Which tensor library to use?
http://itensor.org/support/1052/which-tensor-library-to-use?show=1060#a1060
<p>Hi Xaver,<br>
I think this is a good question. I can't really speak with much knowledge about the others besides ITensor, except to say that Uni10 and TenPy are also good choices. TensorOperations in Julia may also be a reasonable choice. The main difference between these are probably:<br>
(1) which language they are in (C++ for ITensor, Uni10; python for TenPy; Julia for TensorOperations; etc.)<br>
(2) availability of certain operations you might need, such as quantum numbers and certain advanced tensor "index merging/folding" operations etc.<br>
(3) how much they make you deal with lower-level details, such as the ordering of indices and reshaping of tensors</p>
<p>For #1, this is a big difference so you'll have to decide what language you're most comfortable using. My feeling is that while python is easy to learn, later on you'll be frustrated by bugs that keep occurring and are hard to find and by parts of the code that will be slow and will be hard to speed up without putting in pieces of C/C++. Julia is great and I would recommend that language unreservedly. C++ is also good, but has a steep learning curve for the more advanced sort of features. However, if you write C++ similar to how you'd write python or Julia there is a subset of modern C++ that is nice and fairly easy to use.</p>
<p>For #2 you'll have to check the status of each library yourself. I think quantum numbers are particularly easy to work with and nicely handled in ITensor, and less so in some other libraries I've seen. But this may have changed. Also you might be more focused on other features. </p>
<p>For #3, this is where ITensor particularly excels. You hardly ever have to think about the ordering of indices and you never have to reshape a tensor. These details can be quite a pain in more sophisticated algorithms beyond MPS algorithms. One concern that more advanced people I know had about ITensor was that for PEPS, sometimes it's quite important to control the order of indices so as to avoid extra reshaping during the contraction step. But ITensor now offers a .order(...) method that lets you change the index ordering for cases like PEPS codes. So if you find this is an issue for you when trying ITensor, we can discuss and I can help you to make this no longer an issue.</p>
<p>So in summary I think ITensor would be quite a good choice for writing a PEPS code, provided that you are comfortable using C++. I would say also to check out Uni10, which is aimed at 2D tensor networks specifically, and also TenPy which is written by some top people in the field of tensor networks. TensorOperations in Julia is reasonable too if you want to do a lot "by hand" with the other features using Julia built-in tensor manipulations. TNT and the others I'm less knowledgeable about but hopefully someone else can say something about them here.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1052/which-tensor-library-to-use?show=1060#a1060Wed, 05 Sep 2018 14:45:56 +0000Answered: Is there a simple way to calculate bipartite entanglement entropy for 2D system?
http://itensor.org/support/1058/there-simple-calculate-bipartite-entanglement-entropy-system?show=1059#a1059
<p>Hi, so yes you can calculate this kind of entanglement (I assume you mean using DMRG to first compute a ground-state MPS of a 2D system?). </p>
<p>The way to do it is to arrange the numbering of your sites to first visit every site in the left half of your system, then every site in the right half. If you do the "zig zag" path of an MPS through a 2D cylinder or rectangle this property will already be fulfilled.</p>
<p>Then simply compute the entanglement entropy the same way you would for a 1D system, cutting on the bond that separates the two halves of your system.</p>
<p><a rel="nofollow" href="http://itensor.org/docs.cgi?page=formulas/entanglement_mps">http://itensor.org/docs.cgi?page=formulas/entanglement_mps</a></p>
<p>Here are some related questions and answers:<br>
<a rel="nofollow" href="http://itensor.org/support/74/how-to-define-and-implement-a-zig-zag-chain?show=80#a80">http://itensor.org/support/74/how-to-define-and-implement-a-zig-zag-chain?show=80#a80</a><br>
<a rel="nofollow" href="http://itensor.org/support/580/entanglement-entropy-of-2d-mps?show=580#q580">http://itensor.org/support/580/entanglement-entropy-of-2d-mps?show=580#q580</a></p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1058/there-simple-calculate-bipartite-entanglement-entropy-system?show=1059#a1059Wed, 05 Sep 2018 14:36:36 +0000Answered: AutoMPO for fermions and DMRG
http://itensor.org/support/1054/autompo-for-fermions-and-dmrg?show=1055#a1055
<p>Hi, it looks like your Hamiltonian is not Hermitian for <code>ampo</code>. That's probably why its different every time you run it. Assuming you directly copied and pasted:</p>
<pre><code>ampo += -1.0,"Cup",b,"Adagup",b+1;
</code></pre>
<p>is the offending line. The <code>Adagup</code> should be <code>Cdagup</code></p>
<p>Once you fix that, they still don't agree and that's because you didn't write your C operators in normal ordering, so they are off by a commutator I think? When I do</p>
<pre><code>ampo += -1.0,"Cdagup",b,"Cup",b+1; //Hopping for spin up
ampo += -1.0,"Cdagup",b+1,"Cup",b; // <-
ampo += -1.0,"Cdagdn",b,"Cdn",b+1; //Hopping for spin down
ampo += -1.0,"Cdagdn",b+1,"Cdn",b;// <-
</code></pre>
<p>I get the same value for both cases using this change</p>
http://itensor.org/support/1054/autompo-for-fermions-and-dmrg?show=1055#a1055Thu, 30 Aug 2018 19:59:02 +0000Answered: Compare two (same rank) tensors
http://itensor.org/support/1050/compare-two-same-rank-tensors?show=1053#a1053
<p>Hi, good question. So first of all it's a good thing that ITensor throws an error here, because in a general case one shouldn't be able to add or subtract tensors with different indices.</p>
<p>But we've been needing a feature for a while that will conveniently replace indices with equivalent ones. A key use case would be making an operator once, then "sliding" it down a chain of sites.</p>
<p>So I added a function just now to ITensor called "reindex". Here is the documentation for it:<br>
<a rel="nofollow" href="http://itensor.org/docs.cgi?page=classes/itensor#reindex">http://itensor.org/docs.cgi?page=classes/itensor#reindex</a></p>
<p>You can use it in your case by replacing T2 by reindex(T2,s2,s1) in your norm calculation. (Also no need for the separate -1*T2; it's ok to subtract ITensors, once they have the same indices.)</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1050/compare-two-same-rank-tensors?show=1053#a1053Wed, 29 Aug 2018 21:52:24 +0000Time Evolving Kagome Heisenberg AF Ground State
http://itensor.org/support/1051/time-evolving-kagome-heisenberg-af-ground-state
<p>I'm trying to perform real-time evolution of the Heisenberg anti-ferromagnet on a Kagome lattice using fitApplyMPO. When I try to do this with a spin-half chain I don't get any errors. For the kagome lattice, the Hamiltonian I generate gives me a reasonable ground state so I think the problem isn't in the MPO itself. Furthermore, I also don't get errors (even in debug mode) when I do </p>
<pre><code>auto expH = toExpH<ITensor>(aH, tau*Cplx_i);
</code></pre>
<p>The problem only occurs during this line:</p>
<pre><code>psi = fitApplyMPO(psi, expH, args);
</code></pre>
<p>This is the error I get:</p>
<pre><code>terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
</code></pre>
<p>Any idea what is going on? I'm confused because this exact code works for a spin chain and the Hamiltonian itself, which is the only thing that is different, isn't causing issues directly.</p>
<p>Thanks in advance for the help!</p>
http://itensor.org/support/1051/time-evolving-kagome-heisenberg-af-ground-stateWed, 29 Aug 2018 06:42:34 +0000Answered: Compiling for multithreading
http://itensor.org/support/1043/compiling-for-multithreading?show=1049#a1049
<p>Hi Josh,<br>
So currently the only part of ITensor that uses multithreading is when ITensor makes calls to BLAS dgemm (and in some cases zgemm) for performing tensor contractions. When the contracted tensors are sufficiently large, BLAS libraries like MKL will automatically use multi-threading to speed them up.</p>
<p>So if you are using a good BLAS library such as MKL and you do calculations involving large tensors, you should see a speedup when you leave OMP<em>NUM</em>THREADS or set it to a larger value versus setting OMP<em>NUM</em>THREADS=1. </p>
<p>If you aren't seeing a speedup, it could be because the tensors involved in your code are not quite large enough, or your code's running time isn't dominated by tensor contractions.</p>
<p>In the future we plan to exploit multithreading more within ITensor itself.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1043/compiling-for-multithreading?show=1049#a1049Wed, 15 Aug 2018 21:23:08 +0000Answered: FQHE in iTensor?
http://itensor.org/support/1044/fqhe-in-itensor?show=1048#a1048
<p>Hi, good question. So this should certainly be possible to do with ITensor. The way to handle the momentum quantum number should be that label the allowed y-periodic momenta by integers, then create a "slot" in the QNs which you set up to have a Z<em>N addition rule, where N is the maximum allowed momentum (dependent on the transverse system size L</em>y of course).</p>
<p>This paper which you've probably seen has some helpful details:<br>
<a rel="nofollow" href="https://arxiv.org/abs/1512.03318">https://arxiv.org/abs/1512.03318</a></p>
<p>To set up the QNs, you can do something like this:</p>
<p>First site IQIndex along a column of your cylinder (qn values are spin, charge, momentum):</p>
<pre><code>IQIndex("S1",Index("e1",1),QN({0,1},{0,-1},{0,Nmax}),
Index("up1",1),QN({1,1},{1,-1},{0,Nmax}),
Index("dn1",1),QN({-1,1},{1,-1},{0,Nmax}),
Index("ud1",1),QN({0,1},{2,-1},{0,Nmax}))
</code></pre>
<p>Second site IQIndex</p>
<pre><code>IQIndex("S1",Index("e1",1),QN({0,1},{0,-1},{1,Nmax}),
Index("up1",1),QN({1,1},{1,-1},{1,Nmax}),
Index("dn1",1),QN({-1,1},{1,-1},{1,Nmax}),
Index("ud1",1),QN({0,1},{2,-1},{1,Nmax}))
</code></pre>
<p>To understand the notation inside the QN better, see the QN documentation page:<br>
<a rel="nofollow" href="http://itensor.org/docs.cgi?page=classes/qn">http://itensor.org/docs.cgi?page=classes/qn</a></p>
http://itensor.org/support/1044/fqhe-in-itensor?show=1048#a1048Wed, 15 Aug 2018 03:30:15 +0000Answered: How do I use iTEBD for disordered Heisenberg spin chain ( to study dynamics in Many Body Localized systems) in ITensor?
http://itensor.org/support/1045/disordered-heisenberg-dynamics-localized-systems-itensor?show=1046#a1046
<p>Hi sayandip,<br>
When you say iTEBD, do you mean to find the ground state or to do real-time evolution? Since you referrred to MBL, I'm assuming you mean real time evolution but I'll comment on both.</p>
<p>Here is a "code formula" page that shows how to make a code to do time evolution of MPS using Trotter gates, which is the best approach if you have a short ranged Hamiltonian:<br>
<a rel="nofollow" href="http://itensor.org/docs.cgi?page=formulas/tevol_trotter">http://itensor.org/docs.cgi?page=formulas/tevol_trotter</a></p>
<p>To include disorder, just define the individual Hamiltonian terms ("hterm" in the code) appropriately, with parameters depending on the bond number "b". Be careful that you use the same parameters for the reverse set of gates defined in the second loop going from N-1 down to 1. </p>
<p>If you pass the Gate::tReal flag as shown in the sample code, it will produce real-time evolving gates of the form exp(-i h tau). If you pass the Gate::tImag flag it will do imaginary time evolution and you can use that to project into the ground state.</p>
<p>But for finding the ground state, a more powerful approach is to use DMRG. Be careful, though, as DMRG can get stuck in an eigenstate which isn't the ground state if disorder is extremely strong (and depending on the initial state you give).</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1045/disordered-heisenberg-dynamics-localized-systems-itensor?show=1046#a1046Wed, 08 Aug 2018 17:54:16 +0000Answered: I am wondering if it's possible to set the on site operator "N_up,i", or two operators on the same site.
http://itensor.org/support/1025/wondering-possible-site-operator-n_up-operators-same-site?show=1042#a1042
<p>Thanks for the question Chenrong - it's good to keep an eye on these things and glad it's working well now. </p>
<p>Yixuan - thanks for the answer also. Feel free in the future to post an official answer; the forum allows multiple answers as you can see, so it's a good way for people to contribute.</p>
<p>Miles</p>
http://itensor.org/support/1025/wondering-possible-site-operator-n_up-operators-same-site?show=1042#a1042Fri, 27 Jul 2018 15:33:32 +0000Answered: Concatenate two Tensors
http://itensor.org/support/1039/concatenate-two-tensors?show=1040#a1040
<p>Hi Ze-Pei,<br>
Good question. Unfortunately this feature is missing in ITensor currently. We have a practice of not adding features until there is a clear use case, but I think the case you describe definitely justifies adding this feature.</p>
<p>So if you can wait, I will try to add it as soon as I can. Hopefully within a week's time but we'll see.</p>
<p>For the ITensor class, adding this feature should not be extremely hard if you feel like digging into the internals yourself, although it will be faster for me to do it of course. Basically, I plan to allocate a new storage for the concatenated ITensor, then use a "TensorRef" object which is a lower-level type of non-owning tensor to refer to this storage. The TensorRef class supports "tensor slicing" which lets one select only a specific sub-block of the tensor. Then one can straightforwardly copy another tensor whose size matches that sub-block into the sub-block. In this way, one can copy each of the two tensors to be concatenated into the new tensor's storage.</p>
<p>Anyway that's the plan and I hope to finish it soon, at least for the ITensor class. For IQTensors it will be more technical, but should also be possible.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1039/concatenate-two-tensors?show=1040#a1040Thu, 26 Jul 2018 04:06:38 +0000Answered: Many body operators in time evolution
http://itensor.org/support/1026/many-body-operators-in-time-evolution?show=1035#a1035
<p>Hi Tobias,<br>
Thanks for the question. The short answer is just that the toExpH function just doesn't support operators beyond two-site operators at the moment, even though the non-exponentiated part of AutoMPO does support it. This is a fixable feature, but I may not find time to fix it very soon. Since another user also asked about it recently, though, I'll try to prioritize adding it in.</p>
<p>But in the mean time, another approach to time evolving with arbitrary Hamiltonians is to use the "time step targeting" method which is very similar to the "TDVP" method of Haegeman and Verstraete. Here are two papers on the time-step targeting method:</p>
<p><a rel="nofollow" href="https://arxiv.org/abs/cond-mat/0502475">https://arxiv.org/abs/cond-mat/0502475</a></p>
<p><a rel="nofollow" href="https://arxiv.org/abs/1706.09537">https://arxiv.org/abs/1706.09537</a></p>
<p>We don't have this method implemented in ITensor, but ITensor would be very well suited for writing your own implementation. </p>
<p>Regarding more generalized Jordan-Wigner string, that's not something I could quickly add to AutoMPO. You are welcome to look at how fermion J-W string gets handled in AutoMPO and make your own modified version for your system, but instead of adding all of the different cases people might try on top of what is a rather temporary solution that we have currently, I am working instead to overhaul our approach to fermions and non-Abelian anyons. </p>
<p>The new approach I'm working on actually makes certain types of IQIndex objects anticommute (or commute up to a general phase factor) when in certain QN sectors. It will take until at least this fall for this feature to be put in, though, and no guarantee it will work as well as I'm hoping -</p>
<p>Miles</p>
http://itensor.org/support/1026/many-body-operators-in-time-evolution?show=1035#a1035Wed, 18 Jul 2018 16:20:46 +0000Answered: Entanglement entropy for a two-leg Heisenberg ladder
http://itensor.org/support/1028/entanglement-entropy-for-a-two-leg-heisenberg-ladder?show=1032#a1032
<p>Hi Jeffrey,<br>
Thanks for the question & for the easy to read code.</p>
<p>Your code looks good to me to start with. So if you are getting an answer that seems wrong, then I would look at two things:</p>
<ol>
<li><p>is your DMRG converged for all of the different Hamiltonians you consider? Some simple checks for convergence are (a) does the truncation error printed by DMRG for the last two sweeps reach a small value, where small means less than 1E-6 and ideally less than 1E-8 or even smaller? (b) does the energy not change appreciably in the last two or three sweeps? </p></li>
<li><p>when you compute the entanglement, try printing the eigenvalues. Are some of them funny looking? Like are there a lot which are very small or even negative? Not sure if this is really likely to happen, just chasing down all possible ways there could be an error.</p></li>
</ol>
<p>If you try those two things and still have the error, please comment below and we can keep discussing it.</p>
<p>Miles </p>
http://itensor.org/support/1028/entanglement-entropy-for-a-two-leg-heisenberg-ladder?show=1032#a1032Wed, 18 Jul 2018 15:49:05 +0000Answered: Sz_i - Sz_j Correlator at Different Times
http://itensor.org/support/1030/sz_i-sz_j-correlator-at-different-times?show=1031#a1031
<p>Hi jamarks,<br>
So you have the right idea, namely that you should apply @@S^z_j@@ to your MPS, then time evolve it, then measure @@S^z_i@@ after time evolving (and by measure, I mean compute @@S^z_i@@ "sandwiched" between your original state "0" on one side and your time-evolved state on the other side).</p>
<p>To apply @@S^z_j@@ to an MPS, all you need to do is this:</p>
<pre><code>psi.Aref(j) *= sites.op("Sz",j);
psi.Aref(j).noprime(Site);
</code></pre>
<p>The first line gets the @@S^z_j@@ operator from the site set "sites" and contracts it with the jth "A" tensor or MPS tensor of the MPS psi.</p>
<p>The second line removes the prime on the site index that results from the first line, since site operators have one unprimed index and one primed index by our library's convention.</p>
<p>Hope that helps!</p>
<p>Miles</p>
http://itensor.org/support/1030/sz_i-sz_j-correlator-at-different-times?show=1031#a1031Wed, 18 Jul 2018 15:42:58 +0000Answered: Creating SiteSets that represents three spin 1/2's
http://itensor.org/support/1013/creating-sitesets-that-represents-three-spin-1-2s?show=1022#a1022
<p>Please see the comment discussion above -</p>
<p>Specifically regarding the "QMixed" error, that's an error which occurs when trying to make an IQTensor (usually an operator returned from the .op method of a site set) which would violate the QN symmetry in the sense of not having a well defined QN "flux" (<a rel="nofollow" href="http://itensor.org/docs.cgi?page=book/block_sparse).">http://itensor.org/docs.cgi?page=book/block_sparse).</a> The purpose of QMixed storage is to "smuggle" an ITensor (non-QN-conserving) out of a function that only returns IQTensors. It's kind of an ugly workaround and we are planning to fix the design issue that led to it a different way in the future.</p>
<p>So then there are probably two things causing the error you're seeing:<br>
1. you are making an IQTensor (operator) which doesn't conserve the quantum numbers it needs to. For example, you are trying to make the operator Sx as an IQTensor in a context where total Sz is conserved (solution: use S+ and S- instead). <br>
2. you are working in a context where you aren't conserving any quantum numbers, in which case you need to convert the IQTensor with QMixed storage to a regular ITensor before using it.</p>
<p>If you're making a custom site set, please follow the pattern used to make operators such as Sz, S+, and S- in spinhalf.h for making most of your (QN conserving) operators, not the pattern for making operators such as Sx or Sy which are special cases.</p>
<p>Miles</p>
http://itensor.org/support/1013/creating-sitesets-that-represents-three-spin-1-2s?show=1022#a1022Fri, 13 Jul 2018 14:22:40 +0000Answered: How can I free the memory allocated for MPS?
http://itensor.org/support/1012/how-can-i-free-the-memory-allocated-for-mps?show=1020#a1020
<p>Hi Yilun,<br>
To officially answer your question, all that should be necessary to free the memory used by an MPS is to let it go out of scope and/or overwrite it with a new MPS (such as a default-constructed MPS, or any other operation which calls the destructor of the MPS and its member objects). </p>
<p>However, it's important to know that all ITensors use a copy-on-write system where multiple ITensors can share the same underlying memory when copied, until one of them needs to make a change to the shared data, at which point the data is copied so as to be unique to that tensor. So there can be cases where an object is destructed but the memory usage doesn't go down because another tensor is still pointing to that data. It should be leak-proof, though, in the sense that once all of the tensors sharing data go out of scope the memory is freed.</p>
<p>Please also see my comment above asking some more questions about your code and what you are seeing happen -</p>
<p>Miles</p>
http://itensor.org/support/1012/how-can-i-free-the-memory-allocated-for-mps?show=1020#a1020Fri, 13 Jul 2018 14:11:56 +0000Answered: Constructing MPO manually
http://itensor.org/support/1016/constructing-mpo-manually?show=1017#a1017
<p>Hi Yixuan,<br>
Yes, you can definitely create an exponential interaction with that pattern. Also, yes you can extend this trick to a ladder or two-chain system as you are thinking. You just have to be clever about blocking the MPO into different rows and columns so that the correct terms connect with each other on different legs of the ladder, and set the diagonal terms to 1 or else e^{-1} (or the appropriate base of your exponential) on alternating sites.</p>
<p>To get you started with making an MPO or IQMPO manually, have a look at the file Heisenberg.h in the sample/ folder under the ITensor source code directory. That file has a code pattern you can use to make arbitrary MPOs in a more manual way, by placing operators in different locations in each matrix as you wish.</p>
<p>Finally, once you think you have made your IQMPO correctly, a good way to test it is to prepare different product states |i> and |j> where, for example, |i> is the state with a single particle located on site i and |j> similar but for site j. Call these IQMPS psii and psij. Then calculate overlap(psii,H,psij) and it should give you the coefficient of the hopping term connecting site i to j in your Hamiltonian MPO. You can do similar things with two particles to get interaction matrix elements etc.</p>
<p>Miles</p>
http://itensor.org/support/1016/constructing-mpo-manually?show=1017#a1017Tue, 10 Jul 2018 22:37:27 +0000Answered: Read/Write tensors to HDF5 files
http://itensor.org/support/886/read-write-tensors-to-hdf5-files?show=1010#a1010
<p>So here's another piece of an answer: I wanted to write an ITensor of results to an hdf5 file for analysis in Julia. To save everybody else from having to re-invent this particular wheel, the code is in a <a rel="nofollow" href="https://gist.github.com/christopherdavidwhite/0eafbf88bc5171c2bb6071587af0359a">gist</a>. (Too long for the answer box.)</p>
<p>FWIW the code in the gist can take IQTensors---but it deals with them by flattening them down to ordinary ITensors.</p>
http://itensor.org/support/886/read-write-tensors-to-hdf5-files?show=1010#a1010Sat, 07 Jul 2018 00:47:51 +0000Answered: How do I control threading and indexing?
http://itensor.org/support/1006/how-do-i-control-threading-and-indexing?show=1007#a1007
<p>Hi, so I assume you mean the threading that's happening inside of BLAS dgemm? That's the only place that ITensor uses multi threading right now. If you want to force BLAS to be single threaded, it's sort of implementation dependent. Usually the way to do it is to set an environment variable such as export OMP<em>NUM</em>THREADS=1 which works for Apple vecLib / Accelerate and for MKL. (Also MKL recognizes MKL<em>NUM</em>THREADS.)</p>
<p>Regarding 1-indexing, no it's just how our interface works, so it can't be turned off. We are actually considering making a Julia version of ITensor at some point where everything, even low-level things, are 1-indexed and then the indexing will be more consistent throughout the high and low level parts of the library.</p>
<p>Miles</p>
http://itensor.org/support/1006/how-do-i-control-threading-and-indexing?show=1007#a1007Fri, 29 Jun 2018 22:31:12 +0000Answered: How to calculate 2-particle density matrix for the Hubbard Model when two indexes are equal?
http://itensor.org/support/998/calculate-particle-density-matrix-hubbard-model-indexes-equal?show=1005#a1005
<p>Well, after posting this problem I ended up solving it. I decided to keep the post here if other people do the same silly thing as me. Another reason to leave the post here is that people who want to make a similar calculation can see and even exchange ideas with me.</p>
<p>The calculation is right, but the order of the operators' application is wrong in the code. Simple error, but since the correlator is calculated starting from the lowest to the highest site index (usually), I did not realize that in the same site the application of operators is obviously in the anti lexicographic order. The order of application is like this:</p>
<p>$$<br>
\begin{align}<br>
=-\underbrace{\left(a_{i,\sigma_{i}}^{\dagger}F_{i}^{\sigma_{i}+\sigma_{k}}a_{k,\sigma_{k}}\right)}_{\leftarrow}\underbrace{\left(a_{j,\sigma_{j}}F_{j}^{\sigma_{j}+1}\right)}_{\leftarrow}\underbrace{\left(F_{j+1}\cdots F_{l-1}\right)}_{\rightarrow}\underbrace{\left(F_{l}^{\sigma_{l}}a_{l,\sigma_{l}}\right)}_{\leftarrow}.<br>
\end{align}<br>
$$</p>
http://itensor.org/support/998/calculate-particle-density-matrix-hubbard-model-indexes-equal?show=1005#a1005Fri, 29 Jun 2018 14:56:37 +0000Answered: Are spinless fermions just fermions with fixed spin?
http://itensor.org/support/1001/are-spinless-fermions-just-fermions-with-fixed-spin?show=1002#a1002
<p>Hi Jon,<br>
I think this is correct and will work, however, I'd advise just translating your code to use the Spinless site set. All that should involve for the most part is switching the site set names and then the names of certain operators, but otherwise the structure and logic of the code could be left intact and you wouldn't have to worry about any weird surprises -</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/1001/are-spinless-fermions-just-fermions-with-fixed-spin?show=1002#a1002Thu, 28 Jun 2018 16:05:53 +0000Answered: How to keep the quantum number fixed in time evolution
http://itensor.org/support/991/how-to-keep-the-quantum-number-fixed-in-time-evolution?show=992#a992
<p>Hi Yixuan,<br>
If you are using IQMPS and IQTensors with a site set that defines a particle number (such as the Hubbard site set) then the total electron number should be kept precisely the same in an automatic way by the IQTensor system. Which site set are you using to define the IQMPS and how are you constructing it?</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/991/how-to-keep-the-quantum-number-fixed-in-time-evolution?show=992#a992Wed, 13 Jun 2018 21:34:40 +0000Projection operator for the AKLT ground state
http://itensor.org/support/986/projection-operator-for-the-aklt-ground-state
<p>Dear forum,</p>
<p>I want to check if the ground state returned by DMRG is identical to the valence bond ground state of the AKLT model<br>
( <a rel="nofollow" href="https://en.wikipedia.org/wiki/AKLT_model">https://en.wikipedia.org/wiki/AKLT_model</a> ).</p>
<p>For this purpose, I need to project a pair of spin-1/2 particles on adjacent sites onto the spin-1 (or triplet) subspace using the projection operator as shown on the following link</p>
<p><a rel="nofollow" href="https://1drv.ms/u/s!ApS6tTYbSmDBjFXFmQdES0QnV7yw">https://1drv.ms/u/s!ApS6tTYbSmDBjFXFmQdES0QnV7yw</a></p>
<p>where the symbols “+”, “0” and “−” label the standard spin-1 basis states.</p>
<p>I have been able to construct the first and last terms of this operator using the pre-built operator “Proj” discussed on the webpage <a rel="nofollow" href="http://itensor.org/docs.cgi?page=classes/siteset">http://itensor.org/docs.cgi?page=classes/siteset</a> but I have not been able to construct the second term (the one with |0>). Could you please help me? Thanks in advance.</p>
<p>Regards,<br>
Niraj</p>
http://itensor.org/support/986/projection-operator-for-the-aklt-ground-stateMon, 11 Jun 2018 19:52:09 +0000Answered: Computing the spin-spin correlation function between site b and b+2.
http://itensor.org/support/983/computing-spin-spin-correlation-function-between-site-and?show=984#a984
<p>Hello, <br>
I believe the above method works only for a correlation between two adjacent sites. I would use the following method to calculate the correlation between any two sites:</p>
<p><a rel="nofollow" href="http://itensor.org/docs.cgi?page=tutorials/correlations">http://itensor.org/docs.cgi?page=tutorials/correlations</a></p>
<p>Regards,<br>
Niraj</p>
http://itensor.org/support/983/computing-spin-spin-correlation-function-between-site-and?show=984#a984Mon, 11 Jun 2018 16:30:48 +0000non-local correlated hopping term expressed as MPO
http://itensor.org/support/977/non-local-correlated-hopping-term-expressed-as-mpo
<p>For a Hubbard model with correlation hopping, the hopping term is</p>
<p>$$ <br>
H_0=-J\sum_{<i,j>}a_i^{\dagger} F_0(\hat{n}_i-\hat{n}_j)a_j <br>
$$</p>
<p>with </p>
<p>$$<br>
F_0(\hat{n}_i-\hat{n}_j)=J_0(\Omega(\hat{n}_i-\hat{n}_j))<br>
$$</p>
<p>here, @@J_0@@ is first-order Bessel function. SInce @@F_0@@ is non-linear, it is impossible to express @@ F_0 @@ as a product of two local operators on sites i and j, i.e.</p>
<p>$$ <br>
F_0(\hat{n}_i-\hat{n}_j) ?= O_i \cdot O_j <br>
$$</p>
<p>Then in this case, how can we perform DMRG as usual using ITensor ?</p>
http://itensor.org/support/977/non-local-correlated-hopping-term-expressed-as-mpoThu, 07 Jun 2018 15:58:43 +0000Answered: IQMPS singlet product state doesn't update quantum number
http://itensor.org/support/969/iqmps-singlet-product-state-doesnt-update-quantum-number?show=975#a975
<p>Hi, so the reason for the error message you're getting is that when you initialize the IQMPS from the InitState object "state", the corresponding constructor puts in dimension=1 "link" indices connecting each MPS tensor. The code below that which sets site 52 onwards to be a product of singlets doesn't connect with the link index coming off of the 51st site tensor. So to get a correctly structured MPS, you'll need to modify tensor number 51, or else set up the whole IQMPS in a different way.</p>
<p>I'm not sure why you got exactly the quantum number that was reported, but first you'll need to ensure that the MPS is properly formed before I'd trust the output of totalQN (which assumes a properly formed MPS).</p>
<p>Miles</p>
http://itensor.org/support/969/iqmps-singlet-product-state-doesnt-update-quantum-number?show=975#a975Fri, 01 Jun 2018 02:02:19 +0000Answered: Combine two SiteSets
http://itensor.org/support/970/combine-two-sitesets?show=974#a974
<p>Hi Josh,<br>
So the answer is that, for the time being, there is not an automatic way to do this unless the two site sets have identical quantum number types (so basically, no useful cases). The reason is that although the site set class design is quite flexible, the QN system is currently less flexible (for efficiency reasons). The QN system currently requires that all QNs throughout your code are globally the same, in terms of having the same number of active "slots" with identical modulus numbers in the same ordering. If you just took two of the site sets provided with ITensor and merged them, they'd have different quantum number definitions.</p>
<p>I've been thinking for a while that I should upgrade the QN system to include string descriptions of the different numbers inside the QN. Doing so ought to make it possible to do what you are asking.</p>
<p>For the meantime though, please just define a new type of site set that returns different site indices depending on the site number, but with the same kind of QN on each site, as in the example you linked.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/970/combine-two-sitesets?show=974#a974Tue, 29 May 2018 22:19:52 +0000Answered: tDMRG cplx error
http://itensor.org/support/971/tdmrg-cplx-error?show=972#a972
<p>Hi, so the reason for this error is that somehow an element of a tensor turned out to be complex even though a subroutine expected a real result. This isn't too surprising since you were doing real-time evolution, so complex numbers were involved. Then some subroutine multiplied (essentially) a complex number by its conjugate giving a real number ideally, but due to some floating point roundoff error gave a tiny imaginary part.</p>
<p>The code that triggered this error checks if the imaginary part is more than 1E-14 times smaller than the real part. Because the real part here was so small that check failed. So I'll put in a separate check that only runs this one if the imaginary part is larger than some reasonable value.</p>
<p>It's hard to get these things to be perfect in every case - thanks for reporting this.</p>
http://itensor.org/support/971/tdmrg-cplx-error?show=972#a972Fri, 25 May 2018 03:14:47 +0000Answered: install itensor on Linux
http://itensor.org/support/961/install-itensor-on-linux?show=967#a967
<p>To officially answer this question, the bug was fixed in the latest version of ITensor.</p>
http://itensor.org/support/961/install-itensor-on-linux?show=967#a967Fri, 11 May 2018 17:09:48 +0000Answered: How to do partial trace in a multi-component system
http://itensor.org/support/948/how-to-do-partial-trace-in-a-multi-component-system?show=957#a957
<p>Hi Junjie,<br>
So the most straightforward answer to your question is that you cannot efficiently measure this particular quantity from an MPS representation of the ground state. Sorry.</p>
<p>One way to see this is to think of your sites not as 3*N dimensional sites, but as separate sites for each of your sublevels. So this would be a representation of your problem having a unit cell, with the first site being sublevel -1, the second being sublevel 0, the third being sublevel +1, the fourth being sublevel -1, etc.</p>
<p>From this point of view, the entanglement you are asking for is like the entanglement of every third site, starting with site 2, relative to all the other sites. But as you probably know, the only entanglement "cut" which is efficient to obtain from an MPS is a left-right bipartition.</p>
<p>Ok that's the straightforward answer. The more complicated answer is that you may be able to obtain this quantity if you "swap" the sites or reorder them. So if you apply swap gates to move all of the sublevel 0 sites to the right of the sublevel +1 and -1 sites then it would be a left-right bipartition. But this is unlikely to scale well, so it's probably inefficient.</p>
<p>Another idea is that you could perform sampling to obtain the second Renyi entropy of the sublevel 0 site entanglement.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/948/how-to-do-partial-trace-in-a-multi-component-system?show=957#a957Wed, 09 May 2018 15:22:36 +0000Changing quantum numbers of site set between DMRG and Time-Evolution
http://itensor.org/support/950/changing-quantum-numbers-site-between-dmrg-time-evolution
<p>Hello everybody,</p>
<p>I am currently implementing a time-evolution proceeded by a 2site dmrg groundstate optimisation. For the groundstate search, I have 4 conserved quantum numbers, but the time-evolution may break up to 3 of these. I cannot just do my groundstate search with the single non-broken quantum number, as then I would start my evolution with a groundstate from the wrong subspace (i.e. I need the other quantum numbers for the dmrg to find the groundstate in one specific subspace).</p>
<p>The two “naive” ways of implementing this kind of setup is only using the single quantum number which is never broken and then either doing imaginary time-evolution starting from an initial state in the correct quantum number block (instead of 2 site optimisation to find the groundstate), or adding an energy penalty to the Hamiltonian (to stay in the correct subspace) and using 2 site optimisation.</p>
<p>Neither of these solutions have great appeal, because the groundstate search is less controllable. So I was wondering if someone has an idea how to effectively change the siteset between groundstate search and time-evolution from 4 down to less than 4 quantum numbers.</p>
<p>Or is there a way how to efficiently read through all my tensor components of my mps and copy them by hand into a new mps defined on the new siteset.</p>
<p>Any help would be appreciated.</p>
<p>Best wishes<br>
Johannes</p>
http://itensor.org/support/950/changing-quantum-numbers-site-between-dmrg-time-evolutionTue, 08 May 2018 16:22:43 +0000Answered: Utilizing GPU to Speed up the Calculation
http://itensor.org/support/944/utilizing-gpu-to-speed-up-the-calculation?show=945#a945
<p>Dear Yixuan,<br>
It might indeed be possible, but it is not something we have experimented with very much yet. I believe Steve White tried it at one point a few years ago, but found that with that generation of GPU and the method he was trying that the time spent moving memory to and from the GPU was a significant fraction of the computation time, such that there wasn't much gain. But it's something we are planning to investigate in the future. In the end, it might be very algorithm dependent.</p>
<p>Of course you are welcome to open up the code your self and try to add GPU support to various parts. If you try that and have some questions about the internals of the code I happy to answer them.</p>
<p>Miles</p>
http://itensor.org/support/944/utilizing-gpu-to-speed-up-the-calculation?show=945#a945Mon, 07 May 2018 18:13:11 +0000Answered: I wonder if the coefficient matrix should be antisymmetrical before I use Hubbard sites to calculate fermions
http://itensor.org/support/940/coefficient-antisymmetrical-hubbard-calculate-fermions?show=943#a943
<p>Hi Zhang,<br>
So I assume you are asking about the coefficients of terms that are summed to make a Hamiltonian? In that case, the key thing is that they are chosen so as to result in a Hermitian Hamiltonian. There is no requirement that the matrix of coefficients has to be antisymmetric per se, but it depends on the operators that this matrix of coefficients is weighting (in terms of whether it would result in a Hermitian Hamiltonian) so you would have to provide more information about the terms for me to say for sure.</p>
<p>Basically you define a Hamiltonian in ITensor just as you would for any other algorithm or in a theoretical / analytical study. </p>
<p>If it helps, please take a look at the sample code called "exthubbard.cc" in the sample/ folder under the main ITensor folder. </p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/940/coefficient-antisymmetrical-hubbard-calculate-fermions?show=943#a943Mon, 07 May 2018 15:00:23 +0000Answered: Hi, I was wondering how to calculate the full density matrix using MPS?
http://itensor.org/support/921/was-wondering-how-calculate-the-full-density-matrix-using-mps?show=934#a934
<p>Hi, so the answer to your question is that if you want matrix elements of the entire (pure state) density matrix, these are products of the amplitudes of the wavefunction itself. Amplitudes of MPS wavefunctions are efficient to compute: you just have to "clamp" all of the indices then multiply the resulting matrices. We don't have an automatic facility for this with ITensor but it's easy to do. Here is an example code.</p>
<p>Say we have an MPS "psi" on four S=1/2 sites (sites = SpinHalf(4)).</p>
<p>Then if we want the psi_{1212} amplitude (the up, down, up, down amplitude) for that wavefunction we can do:</p>
<pre><code>auto amp = psi.A(1)*setElt(sites(1)(1));
amp *= psi.A(2)*setElt(sites(2)(2));
amp *= psi.A(3)*setElt(sites(3)(1));
amp *= psi.A(4)*setElt(sites(4)(2));
Print(amp.real());
</code></pre>
<p>Here recall that "sites" is a site set object (a SpinHalf object in this example) that retrieves for us the site indices that the MPS uses. The setElt function is given an "IndexVal" (an index set t to a specific value) and makes an ITensor with a "1" entry for that index value and "0" entry otherwise. </p>
<p>I think if you write out the tensor diagram for the above code it should be apparent what it does, and you can generalize it to an MPS of size "N" by doing steps 2,3,..., N inside a for loop.</p>
<p>Let me know if you have more questions about it.</p>
<p>(Oh and you might want to do amp.cplx() if you expect the amplitude to be complex.)</p>
<p>Miles</p>
http://itensor.org/support/921/was-wondering-how-calculate-the-full-density-matrix-using-mps?show=934#a934Wed, 02 May 2018 21:17:15 +0000Typical weights for excited state calculations?
http://itensor.org/support/933/typical-weights-for-excited-state-calculations
<p>This is in regard to the method described here:</p>
<p><a rel="nofollow" href="http://itensor.org/docs.cgi?page=formulas/excited_dmrg">http://itensor.org/docs.cgi?page=formulas/excited_dmrg</a></p>
<p>I was just playing with this technique a bit and found it was almost useless until "Weight" was set to 10000 for a system with ground state energy 60. I first tried out a weight of 100, but this resulted in a wavefunction overlap of about 0.0001, which was (apparently) large for purposes of computing entanglement.</p>
<p>With a large weight of 10,000, the overlap was below the number of significant figures of the printf statement (I think 10 digits).</p>
<p>Is that typical? Should I go even higher for the weight?</p>
http://itensor.org/support/933/typical-weights-for-excited-state-calculationsWed, 02 May 2018 20:22:59 +0000Why does DMRG give different results for spin-1/2 and spin-1 cases?
http://itensor.org/support/931/why-does-dmrg-give-different-results-for-spin-and-spin-cases
<p>Dear forum,<br>
I have a 1D chain where half of the sites are singly occupied while the other half are vacant and double occupancy on any site is not allowed. I modeled this system with spin-1/2 and spin-1 site sets to compare my results. For both the cases, the values of the parameters in the Hamiltonian are such that the the ground state is expected to be antiferromagnetic, which is the superposition of the two Neel states |101010...> and |010101...>. </p>
<p>Spin-1/2 model: The spin operators are defined such that S^z |1> = +1 |1> and S^z |0> = -1 |0> where |1> = |spin up> refers to a singly occupied site while |0> = |spin down> refers to a vacant site. </p>
<p>Spin-1 model: The spin operators are defined such that S^z |2> = +1 |2>, S^z |1> = 0 |1> and S^z|0> = -1 |0> where |2> = |spin up>, |1> = |spin 0> and |0> = |spin down> refer to doubly occupied, singly occupied and vacant sites respectively. There is an onsite potential U with a value large enough to avoid double occupancy on any site. </p>
<p>Here are the results I obtained:</p>
<p>For spin-1/2, ITensor gives < S^z _ j > = +-1 alternating along the 1D chain while < S^z _ j S^z_(j+1) > = -1 for all j, where j is the site index. This implies that DMRG returns only one of the Neel states as the ground state. </p>
<p>For spin-1, ITensor gives < S^z _ j > = -0.5 and < S^z _ j S^z_(j+1) > = -0.25 for all j. This implies that the ground state returned by DMRG is a superposition of the two Neel states |101010...> and |010101...>. </p>
<p>Both the spin-1/2 and spin-1 cases seem to make sense, but while the former returns only one of the two states in the superposition, the latter seems to give an average. Could you please explain why DMRG works differently for the two cases?</p>
<p>Thanks in advance,<br>
Niraj</p>
http://itensor.org/support/931/why-does-dmrg-give-different-results-for-spin-and-spin-casesTue, 01 May 2018 15:25:31 +0000Answered: WriteM argument for idmrg
http://itensor.org/support/929/writem-argument-for-idmrg?show=930#a930
<p>Hi Ze-Pai,<br>
Basically I think the answer to your question is that WriteM is currently not intended to be used with the idmrg algorithm. This can certainly be fixed, but I would currently view this as not a supported feature. We should add it to the list of new features to add to ITensor.</p>
<p>One question back to you though: are you sure that you need idmrg for your project? Perhaps you could use finite DMRG just as well?</p>
<p>Finally, thanks a lot for looking into the code to diagnose the problem. Maybe it is a simple fix after all like you are suggesting. Do you want to test your fix out on your own code branch then submit a pull request if it does work?</p>
<p>Miles</p>
http://itensor.org/support/929/writem-argument-for-idmrg?show=930#a930Mon, 30 Apr 2018 22:34:42 +0000Answered: How to write MPS to disk
http://itensor.org/support/923/how-to-write-mps-to-disk?show=926#a926
<p>Hi Mateusz,<br>
First of all, to answer your questions 2 and 3, the page tutorials/MPS you reached had some incorrect information on it. I just updated that page to now have the correct information.</p>
<p>So the correct information about psi.A(j) is that it just provides read-only access to the MPS tensor at site j, without modifying that tensor in any way. If you do want to modify the tensor at site j you can call psi.Aref(j). Neither of these changes the MPS gauge. To move the MPS gauge center to some site i call psi.position(i);</p>
<p>Finally, about writing the tensor elements to a text file, there isn't a facility in ITensor right now to do this automatically. But you could write a short code yourself to do this. The main thing to know is that you will need a local copy of the MPS indices to access elements. To get these you can use the linkInd method.</p>
<p>So let's say you want to get the elements of the third MPS tensor psi.A(3). Here is some sample code for doing that:</p>
<pre><code>auto ll = linkInd(psi,2);
auto rl = linkInd(psi,3);
auto s = findtype(psi.A(3),Site);
Print(psi.A(3).real(ll(4),s(2),rl(7)));
</code></pre>
<p>The code above will give you the 4,2,7 element of the tensor A(3). You can get the sizes of each of the indices ll, rl, and s by calling <code>ll.m()</code>, <code>rl.m()</code> etc. and then looping over all of the values of the tensor and printing them to a file.</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/923/how-to-write-mps-to-disk?show=926#a926Sun, 29 Apr 2018 22:29:39 +0000Answered: Energy of infinite DMRG
http://itensor.org/support/914/energy-of-infinite-dmrg?show=916#a916
<p>Hi, good question so that line of the code which you quote is just subtracting off the energy of the system calculated for the last configuration, thinking of the last configuration as a finite-size system. (So using a "growing" picture of the idmrg algorithm.) The algorithm in the ITensor library doesn't use the more sophisticated Schur form argument you cited, although it might be equivalent to it in certain cases (not sure off hand, I'd have to check). </p>
<p>You could apply the code to along-range Hamiltonian by using an appropriate MPO, but you might find slow convergence given that the algorithm doesn't work with an infinite system from the outset, but grows a longer and longer finite-size system. So boundary effects might persist for a while depending on how long range the interaction is and what the correlation length of the system is. </p>
<p>Miles</p>
http://itensor.org/support/914/energy-of-infinite-dmrg?show=916#a916Sun, 29 Apr 2018 02:18:58 +0000Answered: How to get a reduced density matrix on more than 2 qubits?
http://itensor.org/support/904/how-to-get-a-reduced-density-matrix-on-more-than-2-qubits?show=908#a908
<p>Hi, so depending on which qubits you want the entanglement for from a general N-qubit wavefunction, it can range from being straightforward to very difficult and computationally expensive.</p>
<p>But a common type of entanglement which is very efficiently computable is the entanglement entropy of a left-right bipartition of a state represented by an MPS. So this means the entanglement between a region "A" which is sites 1,2,3,...,L and region B which is sites L+1,L+2,...,N for an MPS with N sites.</p>
<p>To obtain this entanglement entropy, please see the following sample code provided on the ITensor website (in the "code formulas" section):<br>
<a rel="nofollow" href="http://itensor.org/docs.cgi?page=formulas/entanglement_mps">http://itensor.org/docs.cgi?page=formulas/entanglement_mps</a></p>
<p>As you may know, even if your system isn't strictly 1D, you can still often get away with representing its wavefunction by an MPS and by choosing the ordering of the MPS sites appropriately (or changing the ordering using swap gates) you can get the entanglement entropy of all sorts of bipartitions. I used this approach in the following paper:<br>
<a rel="nofollow" href="https://arxiv.org/abs/1401.3504">https://arxiv.org/abs/1401.3504</a><br>
(see Fig. 4)</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/904/how-to-get-a-reduced-density-matrix-on-more-than-2-qubits?show=908#a908Tue, 24 Apr 2018 09:58:59 +0000Answered: Access to blocks
http://itensor.org/support/891/access-to-blocks?show=906#a906
<p>Hi Boris,<br>
Nice that you are looking into the ITensor internals. I think it should be very possible to make a wrapper around some of the ITensor functionality like you are thinking, but indeed these internal parts are not yet documented and not so obvious!</p>
<p>You correctly identified a part of the code which is making the new blocks for a new IQTensor. To explain some of what it's doing, Ustore is a QDense storage object, constructed from an IQIndexSet and a QN object. The QN object is a "zero" QN object = QN() so this says that Ustore will be set up to contain only those blocks which can be made from the IQIndexSet with a net QN flux of zero. So this just means blocks for which all of the quantum numbers of the various IQIndex sectors add up to zero (when weighted with the IQIndex arrows giving appropriate plus and minus signs).</p>
<p>Then, once the QDense storage object is allocated, the getBlock helper function (itensor/itdata/qutil.h) returns a "DataRange" object (itensor/tensor/types.h) which is conceptually just a pointer that knows the size of the memory it points to (in fact just a struct which is a pointer and a size_t, designed to aid with memory safety). </p>
<p>To explain getBlock, the arguments to it are the block indices of a particular block to be fetched, in this case B.i1 and n, which are passed as a std::array called uind. By block indices I mean like if uind = (m,n) then getBlock returns the DataRange pointer to the block corresponding to the m'th sector of the first IQIndex in Uis (=uI), and the n'th sector of the second IQIndex in Uis (=L). So these blocks are just the tensor blocks making up a block-sparse tensor.</p>
<p>If the returned DataRange object holds a nullptr (pU.data() == nullptr) then it means one has requested an invalid block (a block which is zero by the QN symmetry) so there is an assert checking for that erroneous case.</p>
<p>Finally, the DataRange object pU is used to construct a MatrixRef object. This is just a matrix "reference" or "view" (non-owning array with reference semantics) of the data pointed to by pU with appropriate row and column dimensions, namely the sizes of the IQIndex's uI and L making up Uis. Some manipulations are done on the resulting MatrixRef object, namely setting it to be the first L[n].m() columns of the matrix UU.</p>
<p>So the last two lines of that block of code (reduceCols and Uref &= UU) are the least applicable to your case, since they are some specific matrix related manipulations, and just a way of setting the values of the block appropriate for this case. More generally, one could loop over the elements of the data range pU and modify them like this:<br>
for(size_t i = 0; i < pU.size(); ++i)<br>
{<br>
pU[i] = ... ;<br>
}</p>
<p>But if you are curious to learn more about the operation Uref &= UU I could discuss that some more. The idea there is that the left-hand side is a MatrixRef, and the normal = assignment operation for MatrixRef's just defines a new MatrixRef, similar to assigning to a pointer which just makes it a different pointer. So to modify the elements actually <em>referenced</em> or pointed to by a MatrixRef, one uses the operator &= which can be read as "dereference and assign". The right-hand side is a regular matrix with value semantics, so in this case the elements pointed to by Uref get overwritten with the entries of UU. </p>
<p>Finally, you had asked for an example. I think the code you cited could already be seen as an example if you understand what each part is doing and if you replace the last two lines (reduceCols and Uref &= UU) by your own code that assigns the elements of the block (pointed to by pU) in whatever way is appropriate for your case.</p>
<p>To understand what operations are available with a DataRange (the type of the object pU) have a look at the definition of DataRange in itensor/tensor/types.h</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/891/access-to-blocks?show=906#a906Tue, 24 Apr 2018 09:48:42 +0000Answered: Issues with speed when linking ITensor through CMake
http://itensor.org/support/786/issues-with-speed-when-linking-itensor-through-cmake?show=905#a905
<p>The tensor flow library was not compiled to use SSE instructions.But these are available on your machine and can speed up CPU computations.Tensor flow programs typically run faster in GPU than CPU.So if your system has a NVIDIA GPU and you need to run perfomance critical applications,you should ultimately build and install this version.You can refer <a rel="nofollow" href="https://www.essayjaguar.com/">write my essay</a> to get a best guidelines and suggestion to write your essays. </p>
http://itensor.org/support/786/issues-with-speed-when-linking-itensor-through-cmake?show=905#a905Tue, 24 Apr 2018 09:04:23 +0000Answered: Eigenvalues of partially transposed tensor
http://itensor.org/support/885/eigenvalues-of-partially-transposed-tensor?show=902#a902
<p>Hi Yishai,<br>
Thanks for the kind words about ITensor. Also this is an interesting question. I agree the prime level manipulations could be better in ITensor. In a future version we (me and a new developer who was recently hired, more info to come) have been discussing more flexible ways to tag and manipulate indices.</p>
<p>But for now, there is a powerful index manipulation function you may not know about which I think will help in your case. It is a variant of the "mapprime" function and I made it to handle cases a lot like yours. The full documentation of it is on this page: <a rel="nofollow" href="http://itensor.org/docs.cgi?page=classes/indexset">http://itensor.org/docs.cgi?page=classes/indexset</a><br>
Look for the version of mapprime that takes a "VArgs" argument and read the description and check out the example.</p>
<p>But here is how you can use it: </p>
<p>E12.mapprime(j,0,1,j,1,0);</p>
<p>Here "j" needs to be replaced by the copy of the index you are transposing. I couldn't tell so easily from your example what it was but I think icl ?</p>
<p>What this function call does is, in words "map the prime level of index j having prime level 0 to 1, and simultaneously map the level of index j with level 1 to level 0". It's designed so that the order of the arguments you pass doesn't matter, other than that the arguments have to be in groups of three: (index, old prime level, new prime level). Also instead of a specific index you can put an IndexType. </p>
<p>Finally, for your sparse case, I would actually recommend just obtaining the numbers from the two different diagonal SVD tensors and putting them into a matrix in a loop then diagonalizing the matrix, or even working out by hand what the negativity is given the special sparse structure. It might not be too bad to code. But let me know if it's blocking you and I can see about defining a sparse*sparse product. Mainly I was trying to avoid defining that case because I didn't want to make it too easy for people to do things that were inefficient by accident.</p>
<p>Miles</p>
http://itensor.org/support/885/eigenvalues-of-partially-transposed-tensor?show=902#a902Tue, 24 Apr 2018 02:09:57 +0000Answered: std:bad_alloc when using overlap(psi_1, psi_2) to calculate the overlap between two MPS
http://itensor.org/support/897/bad_alloc-using-overlap-psi_1-psi_2-calculate-overlap-between?show=898#a898
<p>Hi,<br>
An MPS is defined on a sites object. But if you define the sites object inside the for-loop, then you have two different sites objects. Thus, calculating the overlap of two MPS defined on these two sites objects is like calculating the overlap of two vectors on different Hilbert spaces. You're not supposed to do it. I guess this kind of error wasn't expected by the developer, so there is no error message.<br>
On the other hand, when you define the sites object before the for-loop, you're using the same Hilbert space, and the overlap is well-defined.<br>
For this reason if you're doing the same model with different parameters you should probably define a single sites object and export it to each realization of the model, so that all your MPS will be on the same Hilbert space.<br>
Best,<br>
Yishai</p>
http://itensor.org/support/897/bad_alloc-using-overlap-psi_1-psi_2-calculate-overlap-between?show=898#a898Sun, 22 Apr 2018 13:47:27 +0000Answered: Time evolution of spinful fermions
http://itensor.org/support/892/time-evolution-of-spinful-fermions?show=893#a893
<p>Hi good question, we are working on a more automatic system to make working with fermions easier. However, it might be the end of this summer at best before it's put in and fully tested.</p>
<p>In the meantime, using swap gates with fermionic operators should work well as long as you define fermionic swap gates. As you may know, these are like usual swap gates, except they include a minus sign when the swap operation swaps two sites that are both in fermion-parity-odd states.</p>
<p>If you do proceed with this route, you could test your code by using the AutoMPO system to help you out, because AutoMPO does handle fermion signs automatically and the toExpH function lets you approximately exponentiate a Hamiltonian defined via AutoMPO. </p>
http://itensor.org/support/892/time-evolution-of-spinful-fermions?show=893#a893Fri, 13 Apr 2018 16:07:29 +0000Answered: Negative indices for lattice sites
http://itensor.org/support/874/negative-indices-for-lattice-sites?show=875#a875
<p>This isn't supported, since the numbering of the operators is meant to match the possible inputs to the site set object.</p>
<p>Let's say you define a site set object as:</p>
<pre><code>auto sites = SpinHalf(N);
</code></pre>
<p>Then sites(1) accesses the first index of the lattice, sites(2) the second, etc.</p>
<p>The AutoMPO class uses the site set to know how to construct the various operators defined for each site when making an MPO. So the numbering of the AutoMPO input needs to match that of the site set.</p>
http://itensor.org/support/874/negative-indices-for-lattice-sites?show=875#a875Tue, 10 Apr 2018 03:33:51 +0000Answered: Time-envolving an IQMPS with Trotter Gates
http://itensor.org/support/872/time-envolving-an-iqmps-with-trotter-gates?show=873#a873
<p>Hi, so for the Trotter bug, I think you already have a bug when you try to add different tensors into hterm with different numbers of indices. First you are adding two site operators (four-index tensors) then you are adding single site operators (two-index tensors). In debug mode this should immediately give an error, though perhaps you were running an optimized build in which case the error could happen somewhat later in the code.</p>
<p>So I'd suggest just doing an outer product of your single-site operators with identity operators, like this:</p>
<pre><code> hterm += 0.5*sites.op("Nupdn", b)*sites.op("Id",b+1);
</code></pre>
<p>Regarding the use of exactApplyMPO, it is a function that works for both MPS and IQMPS, and it shouldn't be turning anything into an MPS if you give it an IQMPS and an IQMPO. What arguments are you passing to it?</p>
<p>Best regards,<br>
Miles</p>
http://itensor.org/support/872/time-envolving-an-iqmps-with-trotter-gates?show=873#a873Mon, 09 Apr 2018 23:36:53 +0000