psi.expectation_value("Sx")
tries to evaluate the expectation value \(\langle S^x_i\rangle\) on each site \(i\) of the MPS. If you called
psi.group_sites(k)
beforehand, the local sites i refer to
GroupedSite
, each containing k of the previous sites, and the "Sx" is no longer defined (on which of the k sites would it act on?).
However, the
GroupedSite
defines "Sx_0", "Sx_1", ... "Sx_{k-1}", if there was an operator "Sx" in the local sites before.
So one way to evaluate the expectation values is to call
Code: Select all
exp_vals = []
for i in range(k):
exp_vals.append(psi.expectation_value("Sx_"+str(k))
exp_vals_sorted = np.stack(exp_vals).T.flatten()
Alternatively, you can just split the grouped sites before evaluating the expectation values. Don't forget to do the splitting only a copy, if you still need the original `psi` (e.g. because you're running a TEBD or DMRG simulation):
Code: Select all
psi_ungrouped = psi.copy()
psi_ungrouped.group_split()
exp_vals_sorted = psi_ungrouped.exp_vals("Sx")
# ... and whatever other expectation values you want to evaluate ...