jcmgray / quimb

A python library for quantum information and many-body calculations including tensor networks.
http://quimb.readthedocs.io
Other
488 stars 108 forks source link

Issue with calculation of correlators #62

Closed yourball closed 4 years ago

yourball commented 4 years ago

Hi!

Thanks lot for the great package!

I have a following problem. When calculating off-diagonal Pauli correlator for tensor_1d.MatrixProductState states, e.g. Corr(X, Y) or Corr(Z, Y), I always get zero, no matter what state I choose.

Similarly, for some diagonal correlators I also get zero for a rather arbitrary state.
In the example below all correlators except of Corr(Z, Z) are evaluated to be zero.

I first noticed the problem when calculated off-diagonal correlators for TEBD evolution under a quite generic Hamiltonian.

Any ideas? Please see the code snippet below.

from quimb.gen.operators import pauli

psi = (.23-.5j)*MPS_computational_state('00') 
+ (1.2+1j)*MPS_computational_state('01')
+ (3.2-1.2j)*MPS_computational_state('10')
+ (4.3-1j)*MPS_computational_state('11')

psi = psi/np.sqrt(psi.H @ psi)

i, j = 0, 1
print(f'correlation XY: i={i}, j={j}', psi.correlation(pauli('X'), i, j, B=pauli('Y')))
print(f'correlation YZ: i={i}, j={j}', psi.correlation(pauli('Y'), i, j, B=pauli('Z')))
print(f'correlation XZ: i={i}, j={j}', psi.correlation(pauli('X'), i, j, B=pauli('Z')))
print(f'correlation XX: i={i}, j={j}', psi.correlation(pauli('X'), i, j, B=pauli('X')))
print(f'correlation YY: i={i}, j={j}', psi.correlation(pauli('Y'), i, j, B=pauli('Y')))
print(f'correlation ZZ: i={i}, j={j}', psi.correlation(pauli('Z'), i, j, B=pauli('Z')))
image
jcmgray commented 4 years ago

Thanks for the issue. There are two problems here:

  1. This piece of code doesn't do what you think it does:
    psi = (.23-.5j)*MPS_computational_state('00') 
    + (1.2+1j)*MPS_computational_state('01')
    + (3.2-1.2j)*MPS_computational_state('10')
    + (4.3-1j)*MPS_computational_state('11')

    Its like writing

    psi = 1
    +2
    +3
    +4

    meaning the psi is only the first line.

However that might just be a mistake in writing out the issue! Cos there's also a real bug that in the correlation function that the bra is not being conjugated, giving off results for complex states. I'll fix that now.

jcmgray commented 4 years ago

Second issue hopefully fixed with https://github.com/jcmgray/quimb/commit/aecb30a63cec6cf2becaf1bb283375e0e2b006b8 - let me know if not!

yourball commented 4 years ago

Yeah, indeed, you're right! I made a typo when typing expression for psi. However it is irrelevant for the second issue.

Yeah, commit aecb30a fixes everything. I'm glad I found it)