Two-spin correlator with quantum_LinearOperator
See original GitHub issueQuspin 0.3.0, Anaconda 64bit Windows, Python 3.6
Problem statement
I would like to create a two-spin correlator operator for calculating spin-spin correlations in a 1D Ising chain (simplest possible case) with nearest neighbour interactions only. (I know I can use classical spins ±1, but eventually I need to use this for quantum spins as well in more complicated lattice structure).
Suppose L = 6, the spin chain (periodic bc) looks like
- 0 - 1 - 2 - 3 - 4 - 5 -
and the following MWE:
from quspin.operators import hamiltonian, quantum_LinearOperator
from quspin.basis import spin_basis_1d
import numpy as np
NN_PAIRS = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 0)]
Jzz = [[1, i, j] for (i, j) in NN_PAIRS] # NN only, with pbc
static = [["zz", Jzz]]
basis = spin_basis_1d(6, S='1/2', pauli=True)
H = hamiltonian(static, [], basis=basis)
eigvals, eigvecs = H.eigh()
uu_coeff = [[1.0, 0, 4]] # want <s0 s4>
uu_op = quantum_LinearOperator(static_list=[['zz', uu_coeff]], basis=basis,
check_herm=False, check_symm=False)
# Below, for context only
ss_avg, Z = 0., 0.
kT = 0.04309
# shift eigenvalue spectrum to avoid negative E and large Z values; leaves thermal avg unchanged
eigvals -= eigvals.min()
for E_n, n in zip(eigvals, eigvecs):
ss_avg += np.dot(n.conj(), uu_op.matvec(n)) * np.exp(-E_n / kT)
Z += np.exp(-E_n / kT)
print(ss_avg/Z)
For context:
I’m generating uu_op
in order to calculate, for example, the (real-space) spin-spin correlation between spin 0 and spin 4, using the thermal average (n and E_n are eigenvecs and eigenvals of H respectively):
If my physics is right, this shouldn’t give 0 at the end (if you run my MWE).
So something’s clearly wrong, but first a question related to Quspin’s functionality:
I was inspecting the uu_op
(i.e., of the quantum_LinearOperator module) object properties and realized its static_list
is empty. Am I doing something wrong? I would’ve expected the static list would contain the list I passed in (uu_coeff
in MWE above), but it does not (see pic below). Whereas, the Hamiltonian H
contains the static list just fine.
(uu_op.static_list.__len__ = 0
)
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top GitHub Comments
Hi thatlittleboy,
I had a look at your QuSpin code, it seems fine to me.
quantum_LinearOperator
actually gives the correct result: to check this, I usedhamiltonian
to define the operator $s_0 s^4$, as follows:You should also modify the line where you compute the expectation value in the loop to
This produces the same result, which suggests that QuSpin is doing fine.
zip
function is looping over the wrong axis ofeigvecs
. If you instead dofor E_n, n in zip(eigvals, eigvecs.T):
everything works fine 😉
@ Phil:
i) indeed the
static_list
attribute is empty. I looked up thequantum_LinearOperator
source code, andstatic_list
should be declared within the scope of theif
statement inline 131
but it’s not. I would’ve put it in myself, but I don’t really get the meaning of thiselse
part of the statement (it seems completely unrelated to theif
-part). Can u have a look and maybe fix this in the dev branch?ii) just noticed that in the online documentation,
quantum_LinearOperator
is missing its class example. There was a typo with one of the letters being lowercase in the sphinx source code. I just fixed it and pushed this into dev_0.3.1 branch, but we may need to update the online doc right away for the benefit of the users?– marin
this is fixed in v. 0.3.1