-
Notifications
You must be signed in to change notification settings - Fork 19
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
VQE supports initialization by computer #263
Conversation
Note that on my machine, the newly added test takes about 20 seconds to run. |
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 have a few suggestions. Have a look and let me know what you think.
src/qforte/abc/algorithm.py
Outdated
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." |
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.
It is not clear to me how this message relates to the fast
keyword.
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.
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!
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.
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."
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.
Easy enough to fix. Are there issues with the new error message?
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.
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) |
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.
Is _refprep
still needed in this case?
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.
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.
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) |
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.
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?
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.
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.
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 have one minor suggestion for you to consider.
src/qforte/abc/algorithm.py
Outdated
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." |
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.
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."
Description
Addresses a major use case of #168 - VQE now allows the user to pass in a computer to initialize the state.
User Notes
Computer
.Checklist