quimb icon indicating copy to clipboard operation
quimb copied to clipboard

SpinHam1D PBC

Open gerardPlanella opened this issue 2 years ago • 2 comments

What happened?

Hello,

How can you define a Hamiltonian for an MPS with PBC using the SpinHam1D class? If you try to do this you get the error:

`NotImplementedError Traceback (most recent call last) c:\Users\gerar\OneDrive\Documents\AI\QGNN\src\QGNN\baselines\beliefpropagation\tn_simple_update.ipynb Cell 9 line 6 62 # Add the interaction term and consider cyclic term 63 if J_ab != 0 and (abs(a - b) == 1 or (data[idx].pbc and (abs(a - b) == n[0] - 1))): ---> 64 ham_builder[a, b] += J_ab * 4, 'Z', 'Z' 65 ham_builder[b, a] += J_ab * 4, 'Z', 'Z' 70 ham_local_2 = ham_builder.build_mpo(n[0])

File ***\lib\site-packages\quimb\tensor\tensor_builder.py:3591, in SpinHam1D.getitem(self, sites) 3589 i, j = sorted(sites) 3590 if j - i != 1: -> 3591 raise NotImplementedError("Can only add nearest neighbour terms.") 3593 return _TermAdder(self.var_two_site_terms.get(sites, None), 2)

NotImplementedError: Can only add nearest neighbour terms.`

The problem comes from adding the interaction term from the first and last particle due to the PBC (in the library's code it checks for neighbors with the condition a - b != 1 while it should be abs(a - b) != 1 and (PBC and (abs(a - b) != NumParticles - 1)))). Is there a workaround? I need to instantiate my Hamiltonian with this class to create an MPO and thus use DRMG. The limitation with defining an MPO directly is the lack of fully customizable Hamiltonians.

What did you expect to happen?

No response

Minimal Complete Verifiable Example

No response

Relevant log output

No response

Anything else we need to know?

No response

Environment

Yes

gerardPlanella avatar Nov 22 '23 14:11 gerardPlanella

Is this using SpinHam1D(S=S, cyclic=True)? I guess currently it only handles translationally invariant hamiltonians, but could be modified quite easily.

It's might be a little more complicated than just removing that guard however, as PBC MPOs need special boundary conditions and can be a little hard to reason about.

jcmgray avatar Dec 01 '23 02:12 jcmgray

Exactly, I tried removing the guard to check if it worked but it is not that simple.

gerardPlanella avatar Dec 08 '23 08:12 gerardPlanella