Make time evolution solvers compatible with automatic differentiation #311
+131
−53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
Thank you for contributing to
QuantumToolbox.jl
! Please make sure you have finished the following tasks before opening the PR.make test
.julia
formatted by running:make format
.docs/
folder) related to code changes were updated and able to build locally by running:make docs
.CHANGELOG.md
should 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
With this PR I change the structure of the time evolution solver in order to support automatic differentiation.
Thanks to the SciMLSensitivity.jl package, it is possible to compute the gradient of a differential equation. It is almost straightforward to do with ODE parameters as a
Vector
type, but it is not easy to implement when we have a complicated structure of the parameters as in the current case of the package, where we have many variables, progress bar, etc inside the params.The main change here is to introduce a new struct for the parameters, instead of using the current
NamedTuple
. In this way, thanks to SciMLStructures.jl, we can say which part of the structure is differentiable and which not.As a first step, I'm trying to simplify the structure of the
params
struct. This involves the creation of a custom struct to handle theODEProblem
generated by functions likesesolveProblem
. In this way, many variables can be removed fromparams
.Currently, there are some limitations on the type of the differentiable part of the
params
struct, and the only supported type is theVector
one. For example, theparams
kwarg in themesolve
has to be aVector
and not aNamedTuple
. See this issue for more information. Nonetheless, theNamedTuple
type is still supported in standard simulations, where the gradient is not needed.To Do:
ODEProblem
s generated by the solversSciMLStructures.jl
rules for the customparams
structsesolve
differentiablemesolve
differentiablemcsolve
differentiable (maybe in another PR?)