Page 1 of 1

Correlation function

Posted: 12 Apr 2025, 07:23
by mariocat
Hello all, I am trying to implemente the correlation function $$<b_{i}^\dagger b_{j}>-<b_{i}^\dagger><b_{j}>$$ (with \(i=4\) and \(j\) goes from 4 to 46) where the last number is the value of L in model_params like this:

Python: Select all

model=BoseHubbarModel(model_params)
init_state = ['1'] * model.lat.N_sites
psi = MPS.from_product_state(model.lat.mps_sites(), init_state, bc=model.lat.bc_MPS)
dmrg_params = {"trunc_params": {"chi_max": 150, "svd_min": 1.e-7}, 'max_sweeps': 10, "mixer": True}
info = dmrg.run(psi, model, dmrg_params)
#print("E =", info['E'])
ops = ['Bd'] * model.lat.N_sites
print(ops)
exp_values = psi.expectation_value(ops)
print("Expectation values:", exp_values)
opss=['B']*model.lat.N_sites
print(opss)
expp_values=psi.expectation_value(opss)
print(expp_values)
correlations = []
i = 4
for j in range(4, N+1):

  corr_val = psi.correlation_function("Bd", "B", sites1=[i], sites2=[j])[0, 0]

  expected_prod = exp_values[i] * expp_values[j]
  corrected_corr = np.absolute(corr_val - expected_prod)

  correlations.append(corrected_corr)
Am I doing anything wrong

Re: Correlation function

Posted: 16 Apr 2025, 12:11
by Johannes
why do you think you're doing something wrong? do you get error messages or "wrong" and unexpected results? If you want help, you should say that.

I guess you're suprised to see all the psi.expectation_value('B') and psi.expectation_value('Bd') being zero, even in the supposedly superfluid phase. That's because TeNPy is by default turning on charge conservation, which forces it to write states with fixed number of particles (as given in the initial state), which by definition have \(\braket{b_i}=0 = \braket{b^\dagger_i}\).

The loop over j is a bit redundant and inefficient (forcing the psi.correlation_function to re-calculate partial contractions it already did), but should give the "correct" expectation values as given in the MPS. If I see this correctly, it should be equivalent to

Python: Select all

exp_val_B = psi.expectation_value('B')  # this will all be zeros if you have charge conservation!
exp_val_Bd = psi.expectation_value('Bd')  # == np.conj(exp_val_B), so also zero...
corrs = psi.correlation_function('Bd', 'B', sites1=[4], sites2=range(5,psi.L))[0, :]
connected_corrs = corrs - exp_val_Bd[4] * exp_val_Bd[5:]
Here, I excluded j=4, since it is the special onsite case where the correlation function would just give \(\braket{n_i}\) (although the psi.correlation_function() can handle it correctly, I just want to make you think about what subtracting the disconnected part would mean here...).