question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Two-spin correlator with quantum_LinearOperator

See original GitHub issue

Quspin 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):

chrome_2018-09-12_16-45-55

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.

pycharm64_2018-09-12_16-56-44

(uu_op.static_list.__len__ = 0)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
mgbukovcommented, Sep 13, 2018

Hi thatlittleboy,

I had a look at your QuSpin code, it seems fine to me.

  1. I think quantum_LinearOperator actually gives the correct result: to check this, I used hamiltonian to define the operator $s_0 s^4$, as follows:
uu_op = hamiltonian([['zz', uu_coeff]],[], basis=basis, check_herm=False, check_symm=False)

You should also modify the line where you compute the expectation value in the loop to

ss_avg += uu_op.expt_value(n) * np.exp(-E_n / kT)

This produces the same result, which suggests that QuSpin is doing fine.

  1. I then looked up your for-loop, and noticed that the zip function is looping over the wrong axis of eigvecs. If you instead do

for E_n, n in zip(eigvals, eigvecs.T):

everything works fine 😉

@ Phil:

i) indeed the static_list attribute is empty. I looked up the quantum_LinearOperator source code, and static_list should be declared within the scope of the if statement in line 131 but it’s not. I would’ve put it in myself, but I don’t really get the meaning of this else part of the statement (it seems completely unrelated to the if-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

0reactions
mgbukovcommented, Mar 1, 2019

this is fixed in v. 0.3.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamics of correlations in two-dimensional quantum spin ...
Dynamics of correlations in two-dimensional quantum spin models with long-range interactions: a phase-space Monte-Carlo study.
Read more >
Spin Operator and Entanglement in Quantum Field Theory
Two spin operators are extracted from the Noether current. The Wigner spin operator characterizes spin states at the rest frame of each fermion ......
Read more >
How to calculate two-operator correlation functions ... - ITensor
Hi! I am doing some simulations with conserved quantum numbers. I am interested in computing the two- .
Read more >
TWO-STATE SYSTEMS
Quantum theory of 2-state systems​​ We have seen that quantum mechanics can be portrayed as a theory in which • states are represented...
Read more >
Spin and Quantum Measurement - IF-UFRJ
The state of a quantum mechanical system is described mathematically by a normalized ket ψ that contains all the information we can know...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found