Skip to content

Implement AlternativeSpinHamiltonian for Issue #179#186

Draft
smandal21-pixel wants to merge 10 commits intotheochem:mainfrom
smandal21-pixel:issue-179-spin-hamiltonians
Draft

Implement AlternativeSpinHamiltonian for Issue #179#186
smandal21-pixel wants to merge 10 commits intotheochem:mainfrom
smandal21-pixel:issue-179-spin-hamiltonians

Conversation

@smandal21-pixel
Copy link
Copy Markdown

@smandal21-pixel smandal21-pixel commented Mar 31, 2026

I have refactored the AlternativeSpinHamiltonian to inherit directly from HamHeisenberg. This allows the class to act as an adapter that maps custom spin topologies to the existing integral-based architecture, successfully avoiding dense Kronecker product constructions and leveraging the library's built-in fermion creation/annihilation operator mapping.

Changes include:

Updated AlternativeSpinHamiltonian to utilize HamHeisenberg for integral generation.

Added a new pytest suite in moha/test/test_alternative_spin.py to verify site connectivity and integral tensor shapes.

Ensured compatibility with downstream solvers by providing proper one-body and two-body integrals.

This is part of my GSoC 2026 application for Issue #179. All CI checks are passing.

@smandal21-pixel
Copy link
Copy Markdown
Author

Note for reviewers: I am aware this Draft PR slightly exceeds the recommended 3 commits / 50 lines of code limit mentioned in the contributing guidelines. The extra lines are entirely due to the inclusion of the required pytest suite to verify the Heisenberg energy levels. I have kept the core logic as minimal as possible.

@PaulWAyers PaulWAyers requested a review from RichRick1 April 21, 2026 18:30
Comment thread moha/hamiltonians.py
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to manually code spin operators, as we have introduced mapping from spin-operators to fermion creation/annihilation operators

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review and the guidance, @RichRick1! I completely understand. Since I was working from a ground-up approach, I missed that the spin-to-fermion mapping was already introduced.

I see the existing HamHeisenberg class in moha/hamiltonians.py. I will scrap my manual dense matrix generation and pivot to utilizing the built-in fermion creation/annihilation operators instead. Could you point me to the specific file/module where the spin-to-fermion mapping functions are stored so I can review them?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my previous message—I’ve just reviewed the newly updated docs/spin.rst and the HamHeisenberg / HamIsing classes. I see that the library is already set up to handle these as one-body and two-body integrals. I am currently refactoring my implementation to remove the manual dense matrix Kronecker products and instead utilize the alpha/beta fermion mapping to generate the integral equivalents. This will ensure full compatibility with the existing moha solvers.

@smandal21-pixel
Copy link
Copy Markdown
Author

Hi @RichRick1, I've pushed the final refactor. AlternativeSpinHamiltonian now inherits the fermion mapping directly from HamHeisenberg, fully bypassing the dense Kronecker products. I also resolved the merge conflicts and updated the test suite. All CI checks are passing green! Let me know if you need anything else before merging

@smandal21-pixel smandal21-pixel force-pushed the issue-179-spin-hamiltonians branch from ca729ae to 29128e5 Compare April 28, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants