Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpinHam1D PBC #212

Open
gerardPlanella opened this issue Nov 22, 2023 · 2 comments
Open

SpinHam1D PBC #212

gerardPlanella opened this issue Nov 22, 2023 · 2 comments
Labels

Comments

@gerardPlanella
Copy link

gerardPlanella commented Nov 22, 2023

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

@jcmgray
Copy link
Owner

jcmgray commented Dec 1, 2023

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.

@gerardPlanella
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants