-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: kvmto <[email protected]>
Signed-off-by: kvmto <[email protected]>
libs/solvers/lib/operators/molecule/fermion_compilers/jordan_wigner.cpp
Outdated
Show resolved
Hide resolved
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]>
# op = solvers.jordan_wigner(molecule.hpg, molecule.hpqrs, ) | ||
cudaq1_eig = np.min(np.linalg.eigvals(molecule.hamiltonian.to_matrix())) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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
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.