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

VQE supports initialization by computer #263

Merged

Conversation

JonathonMisiewicz
Copy link
Contributor

Description

Addresses a major use case of #168 - VQE now allows the user to pass in a computer to initialize the state.

User Notes

  • VQE now supports initializing the wavefunction with a Computer.

Checklist

  • Added/updated tests of new features
  • Ready to go!

@JonathonMisiewicz
Copy link
Contributor Author

Note that on my machine, the newly added test takes about 20 seconds to run.

Copy link
Contributor

@imagoulas imagoulas left a comment

Choose a reason for hiding this comment

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

I have a few suggestions. Have a look and let me know what you think.

raise ValueError("unitary_circ reference must be a Circuit.")
if not fast:
raise ValueError(
"User specified they want to simulate a quantum computer but not specify how to prepare the initial state. That's inconsistent."
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not clear to me how this message relates to the fast keyword.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If fast is off, the user has specified they want to simulate the full operations as if on a quantum computer. But by supplying a quantum computer, you're skipping a step: state preparation!

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps the word fast is not the best descriptor for what the code is doing. Of course, this is outside the scope of this PR.

I understand that you want to be precise, but what worries me is that this error message does not reference the fast keyword. The user might not be able to immediately understand what they did to cause this error. For example, in other places of the code, similar error messages read: "self._fast must be True for gradient measurement."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Easy enough to fix. Are there issues with the new error message?

Copy link
Contributor

Choose a reason for hiding this comment

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

The new error message is great! Feel free to merge.

raise ValueError("Class cannot be initialized with a computer.")

self._ref = system.hf_reference
self._refprep = build_refprep(self._ref)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is _refprep still needed in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe - it depends on what "this case" is.

If you want to use an excitation-based pool, it's needed. If you want to do PQE, it's needed. If you want to do moment corrections, it's needed. Otherwise, it isn't needed. Giving QForte the infrastructure to skip this step if not needed seemed beyond the scope of the PR.

Comment on lines +25 to +31
coeff_vec = np.zeros(2**nqubits)
coeff_vec[int("00001111", 2)] = 1
coeff_vec[int("00110011", 2)] = 0.2
coeff_vec[int("00111100", 2)] = 0.1
coeff_vec[int("11001100", 2)] = 0.04
coeff_vec /= np.linalg.norm(coeff_vec)
computer.set_coeff_vec(coeff_vec)
Copy link
Contributor

Choose a reason for hiding this comment

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

As an additional test, would it be possible to check that the initial guess energy agrees with the expectation value of the Hamiltonian with respect to the state generated by the computer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The initial guess energy isn't stored on the wavefunction. I could do it, but I'd need to hardcode that value of that initial guess energy.

Copy link
Contributor

@imagoulas imagoulas left a comment

Choose a reason for hiding this comment

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

I have one minor suggestion for you to consider.

raise ValueError("unitary_circ reference must be a Circuit.")
if not fast:
raise ValueError(
"User specified they want to simulate a quantum computer but not specify how to prepare the initial state. That's inconsistent."
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps the word fast is not the best descriptor for what the code is doing. Of course, this is outside the scope of this PR.

I understand that you want to be precise, but what worries me is that this error message does not reference the fast keyword. The user might not be able to immediately understand what they did to cause this error. For example, in other places of the code, similar error messages read: "self._fast must be True for gradient measurement."

@JonathonMisiewicz JonathonMisiewicz merged commit 243aa2d into evangelistalab:master May 28, 2024
1 check passed
@JonathonMisiewicz JonathonMisiewicz deleted the vqe_compute branch May 28, 2024 17:55
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