On the itensor homepage, there is an example given to calculate the on-site magnetization.

```
for(int j = 1; j <= N; ++j)
{
//Make site j the MPS "orthogonality center"
psi.position(j);
//Measure magnetization
Real Szj = elt(psi(j)
* op(sites,"Sz",j)
* dag(prime(psi(j),"Site")));
println("Sz_",j," = ",Szj);
}
```

I'm interested in calculating the absolute value of the on-site magnetization. Just to be clear about what I mean, given a pure state @@\ket{\psi}@@ of dimension @@ d=2^N @@ and hilbert space H comprising of all possible spin configurations, I want to do the following.

```
absM = 0
for idx = 1:2^N
SumSz = 0
for spin_idx = 1:N
SumSz += H[idx][spin_idx] # spin value
end
absM += abs(SumSz)*|psi(idx)|^2
end
```

How do I do this in itensor given an MPS from a DMRG calculation?

As a side note, there is a related thread on measuring the magnetization-squared (which I will also need) here. But, this is all that I could find that it somewhat related to my question.

Thanks again for the help, and hope you guys are staying safe!