-
Notifications
You must be signed in to change notification settings - Fork 32
Introduce groundstate
#412
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #412 +/- ##
==========================================
+ Coverage 94.20% 94.25% +0.04%
==========================================
Files 46 46
Lines 2918 2924 +6
==========================================
+ Hits 2749 2756 +7
+ Misses 169 168 -1 ☔ View full report in Codecov by Sentry. |
| function groundstate( | ||
| A::QuantumObject{OpType}; | ||
| safe::Bool = true, | ||
| tol::Real = 1e-8, | ||
| kwargs..., | ||
| ) where {OpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}} | ||
| # TODO: support for sparse eigsolve | ||
| #if !sparse | ||
| result = eigen(A; kwargs...) | ||
| #else | ||
| # eigvals = safe ? 2 : 1 # number of eigenvalues to calculate | ||
| # result = eigsolve(A; eigvals = eigvals, tol = tol, kwargs...) | ||
| #end | ||
|
|
||
| # the tolarence should be less strick than the `tol` for the eigensolver | ||
| # so it's numerical errors are not seen as degenerate states. | ||
| evals = result.values | ||
| safe && (abs(evals[2] - evals[1]) < (10 * tol)) && @warn "Ground state may be degenerate." | ||
|
|
||
| return evals[1], QuantumObject(result.vectors[:, 1], _eigenvector_type(OpType), result.dimensions) |
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 would suggest to use eigenstates instead of eigen. In this way we can use all the internal kwargs, including also the sparse one.
In the case of sparse, it automatically finds the largest eigenvalue by the nature of the Arnoldi algorithm. However, this can be fixed by defining a sigma argument, which performs the shift-inverse procedure.
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.
That is why I didn't use the eigenstates
Because this function is only for calculating ground state. We should assign some of the keyword arguments, make it not adjustable from the users.
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.
What value should I set for sigma in eigsolve to make it search for the lowest eigenvalue first?
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.
Because this function is only for calculating ground state. We should assign some of the keyword arguments, make it not adjustable from the users.
What do you mean exactly? If we use eigenstates(A; kwargs...) we can forward all the kwargs to that, even the sparse = ... (which by default is false, so that we fall in this case). If the user specify sparse=true, then he/she is supposed to be more advanced, and should know that the shift-inverse method applies here. By doing so, they should also specify a sigma shift value. We can even write a note on that.
What value should I set for
sigmaineigsolveto make it search for the lowest eigenvalue first?
sigma should be a value smaller than the supposed ground state energy. Let say that you expect the ground state energy to me close to 0, then sigma=-0.1 is fine.
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.
So, in general, I should set sigma = -Inf ?
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.
No this won't work. This is problem dependent.
The user using sparse=true is supposed to be advanced to be able to set this value.
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.
Hmm
Ok
I would probably close this PR.
Seems like we cannot make it.
Checklist
Thank you for contributing to
QuantumToolbox.jl! Please make sure you have finished the following tasks before opening the PR.make test.juliaformatted by running:make format.docs/folder) related to code changes were updated and able to build locally by running:make docs.CHANGELOG.mdshould be updated (regarding to the code changes) and built by running:make changelog.Request for a review after you have completed all the tasks. If you have not finished them all, you can also open a Draft Pull Request to let the others know this on-going work.
Description
This PR introduce a new function:
groundstateto calculate the ground state eigenvalue and corresponding eigenvector.This function currently doesn't support
sparseeigsolve. Because it seems thatsparseeigsolve doesn't find the smallest eigenvalue first.