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

Refactoring and debugging of Jordan Wigner transform (Issue #67) #82

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kvmto
Copy link
Collaborator

@kvmto kvmto commented Feb 10, 2025

This PR fixes #67.

Problem

The Jordan Wigner transform did not work correctly, in fact it generated hamiltonians with wrong coefficients or terms.

Changes

Changes so far have been applied to:

Rewritten from scratch jordan_wigner.cpp.
Added tests.
The original code from which the cpp version is created is https://github.com/quantumlib/OpenFermion/blob/v1.6.1/src/openfermion/transforms/opconversions/jordan_wigner.py#L128

Additional notes

The PR is not done yet! It requires more tests and a second look to the implementation.
The code has not been linted since much more changes are needed.

Findings

The implementation for molecule H4 now has correct energy values but higher number of terms compared to the python version.
Molecules like LiH do not achieve the correct energy values.

@kvmto kvmto requested review from amccaskey and bmhowe23 February 10, 2025 13:47
bmhowe23 and others added 4 commits February 10, 2025 23:16
Co-authored-by: Alex McCaskey <[email protected]>
I, Ben Howe <[email protected]>, hereby add my Signed-off-by to this commit: 6ae55b2

Signed-off-by: Ben Howe <[email protected]>
Signed-off-by: Ben Howe <[email protected]>
Comment on lines 38 to 39
# op = solvers.jordan_wigner(molecule.hpg, molecule.hpqrs, )
cudaq1_eig = np.min(np.linalg.eigvals(molecule.hamiltonian.to_matrix()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

@wsttiger @amccaskey I assume this test needs to be updated? It looks like the code changes to jordan_wigner.cpp aren't being tested until the op = solvers.jordan_wigner line is uncommented?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just pushed a draft candidate test update, but I would be happy to revert/change it if others have any other suggestions.

Also - I suspect we should move this new test into the existing libs/solvers/python/tests/test_molecule.py test file. Any objections?

assert op == molecule.hamiltonian
assert of_hamiltonian == molecule.hamiltonian

# FIXME - why do we need to call eigvals again if we can just assert the equality checks above?
Copy link
Collaborator

Choose a reason for hiding this comment

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

FIXME - why do we need to call eigvals again if we can just assert the equality checks above?
Ahh, this is probably why:
https://github.com/bmhowe23/cuda-quantum/blob/20e5869901c69c0bbbac074cc468e1b398ce136e/runtime/cudaq/spin_op.h#L276-L278

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.

Incorrect coefficients in Jordan-Wigner Transform
3 participants