Proliferating matrix elements in `LocalOperator`s
Created by: attila-i-szabo
I have been trying to compute the expectation values of LocalOperator
s of the form Sx @ Sz
, where Sx
and Sz
are linear combinations of Pauli X and Z operators acting on all N lattice sites. Sx
connects each element of the Hilbert space to N others, and Sz
is diagonal, both of these work out with the output of get_conn
. However, their product ends up having N^2 non-unique connections:
N = 32
hi = nk.hilbert.Spin(0.5, N)
LC = np.ones(N)
Sx = nk.operator.LocalOperator(
hi, LC[:, None, None] * np.array([[0, 1], [1, 0]]), [[i] for i in range(N)]
)
Sz = nk.operator.LocalOperator(
hi, LC[:, None, None] * np.array([[1, 0], [0, -1]]), [[i] for i in range(N)]
)
x = np.sign(np.random.normal(size=N)) # a random vector of +/- 1
a, b = Sx.get_conn(x)
a.shape
>>> (32, 32)
a, b = Sz.get_conn(x)
a.shape
>>> (1,32)
a,b = (Sz@Sx).get_conn(x)
a.shape
>>> (1024, 32)
np.unique(a, axis=0).shape
>>> (32, 32)
and the same for Sx@Sz
.
Is there a way to force LocalOperator
to aggregate these matrix elements? I imagine something like this must be in place for the purely diagonal operators already...