I was basing on this tutorial:
https://itensor.org/docs.cgi?page=formulas/measure_mps
to implement my own Hamiltonian on a given graph. My code looks as follows:
#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=",true});
auto ampo = AutoMPO(sites);
// [Definition 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(state),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 |: ");
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);
//take an inner product
auto sxj = eltC(bra*Sxjop*ket);
println(j, " | ", sxj, " | ");
}
return 0;
}
When I run this code I get the following error message:
From line 173, file itdata/qdense.cc
Setting Tensor element non-zero would violate its symmetry.
I know that this problem was mentioned (e.g. here: http://itensor.org/support/1127/error-message-regarding-the-operator-sx2-spintwo-siteset), but the previous posts didn't mention problems while trying to use Sx
instead of Sx2
.
Moreover, when I modify the following lines:
[...]
auto sites = SpinOne(N,{"ConserveQNs=",true});
[...]
auto [en0,psi0] = dmrg(H,randomMPS(state),sweeps,{"Quiet=",true});
[...]
into:
[...]
auto sites = SpinOne(N,{"ConserveQNs=",false});
[...]
auto [en0,psi0] = dmrg(H,randomMPS(sites),sweeps,{"Quiet=",true});
[...]
everything works fine (but much slower). The change from state
to sites
in the second line of the example is necessary, or otherwise I get the error:
randomMPS(SiteSet) with QN conservation is ambiguous, use randomMPS(InitState) instead.
Do you have any idea, how to solve this problem?