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

UCCSD operator pool correction and integration in adapt simulator #65

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

Conversation

kvmto
Copy link
Collaborator

@kvmto kvmto commented Jan 30, 2025

UCCSD operator pool correction and integration in adapt simulator (Issue #28)

This PR fixes #28 .

Problem

Adapt VQE did not provide correct results. The problem could be the creation of the UCCSD operators pool.

Changes

Changes so far have been applied to:

  • The UCCSD operator pool 'generate' function.
  • The Testing of the UCCSD operator pool, cpp and py files.
  • Tested adap_vqe for final results.

Additional notes

Further testing is needed for making sure that adapt VQE works correctly, especially in terms of molecules.

@kvmto kvmto requested a review from amccaskey January 30, 2025 13:40
@amccaskey
Copy link
Collaborator

Let's add a test to test_adapt.cpp that mimics the checkSimpleAdapt but uses the uccsd operator instead of the spin_complement_gsd one. Note that you'll need to update the coefficients on the operators to make them imaginary, since we assume that in adapt_simulator.cpp (line 152).

@kvmto kvmto requested a review from amccaskey January 31, 2025 13:52
@bmhowe23
Copy link
Collaborator

I would recommend adding the phrase "fixes #28" or "resolves #28" to the description in order to automatically link this GitHub PR with the issue. If you do this, then when the PR is merged, the issue will automatically be closed.

Ref: https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

@bmhowe23
Copy link
Collaborator

Let's add a test to test_adapt.cpp that mimics the checkSimpleAdapt but uses the uccsd operator instead of the spin_complement_gsd one. Note that you'll need to update the coefficients on the operators to make them imaginary, since we assume that in adapt_simulator.cpp (line 152).

I think I'm missing something ... why we are updating the generic UCCSD operator pools from real to imaginary to accommodate a single assumption in adapt_simulator.cpp? Are any docs updates needed for this change?

@bmhowe23 bmhowe23 requested a review from marwafar January 31, 2025 23:12
@marwafar
Copy link
Collaborator

The uccsd operator pool is correct. However, it might not be a good idea to multiply the imaginary number "i" by the uccsd operator pool. It will not make it generic. We might use this uccsd operator pool with other algorithm such as GQE and we will need to modify this again. I would suggest multiply the imaginary number "i" somewhere within the adapt-vqe algorithm.

In addition, I would suggest to run the adapt-vqe for these two geometry with sto3g basis.

H 0.0 0.0 0.0
H 0.0 0.0 0.7474
Li  0.0  0.0  0.0
H   0.0  0.0  1.5 

We need to make sure that it work for something beyond the simple H2 molecule with 4 qubits and 3 operator pools.

annagrin and others added 4 commits February 3, 2025 20:07
### Fix some issues to allow compilation of `uccsd`

- Fix signed int overflow in `uccsd`
- allow specifying shots in `vqe`

Towards: NVIDIA/cuda-quantum#2357

---------

Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: kvmto <[email protected]>
@kvmto kvmto changed the title Fix issue 28 UCCSD operator pool correction and integration in Adapt Simulator Feb 3, 2025
@kvmto kvmto changed the title UCCSD operator pool correction and integration in Adapt Simulator UCCSD operator pool correction and integration in adapt simulator Feb 4, 2025
throw std::runtime_error("Invalid adapt input, operator pool is empty.");

std::vector<spin_op> pool =
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of making this copy, could you not retain the code that was there and just update the commutator creation to

std::complex<double> j = 1.; 
if (isImaginary) j = std::complex<double>{0.0, 1.0};
commutators.push_back(H * j * pool[i] - j * pool[i] * H); 

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In line 159 (auto op = pool[maxOpIdx];), the code selects the best operator and manipulates it. We could assume that each operator in the pool contains either only real or only imaginary coefficients, in which case we would only need to perform the check on the first item. Alternatively, if we can’t make that assumption, we would need to store the result of the check for each operator and provide it in line 159. The copy is just a proposal to accommodate different assumptions. I would be happy with either.

for (std::size_t q = p + 1; q < numOccAlpha; q++)
for (std::size_t r = 0; r < numVirtAlpha - 1; r++)
for (std::size_t s = r + 1; s < numVirtAlpha; s++) {
for (int p = 0; p < numOccAlpha - 1; p++)
Copy link
Collaborator

Choose a reason for hiding this comment

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

aren't these changes from Anna's PR? do you need her changes duplicated here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't need the duplication.
I just fetched and rebased, not sure how it ended up in here... I am not sure how changes happened in between.
I can reset the commit if needed.

Comment on lines +1 to +9
#== == == == == == == == == == == == == == == == == == == == == == == == == == \
== == == == == == == == == == == == #
#Copyright(c) 2024 NVIDIA Corporation &Affiliates.#
#All rights reserved.#
# #
#This source code and the accompanying materials are made available under #
#the terms of the Apache License 2.0 which accompanies this distribution.#
#== == == == == == == == == == == == == == == == == == == == == == == == == == \
== == == == == == == == == == == == #
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the formatter went wild on this one. Did you accidentally run clang-format on this file?

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.

fix uccsd pool operator for the adapt-vqe
5 participants