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

Make time evolution solvers compatible with automatic differentiation #311

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

albertomercurio
Copy link
Member

@albertomercurio albertomercurio commented Nov 14, 2024

Checklist

Thank you for contributing to QuantumToolbox.jl! Please make sure you have finished the following tasks before opening the PR.

  • Please read Contributing to QuantumToolbox.jl.
  • Any code changes were done in a way that does not break public API.
  • Appropriate tests were added and tested locally by running: make test.
  • Any code changes should be julia formatted by running: make format.
  • All documents (in docs/ folder) related to code changes were updated and able to build locally by running: make docs.
  • (If necessary) the 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 the ODEProblem generated by functions like sesolveProblem. In this way, many variables can be removed from params.

Currently, there are some limitations on the type of the differentiable part of the params struct, and the only supported type is the Vector one. For example, the params kwarg in the mesolve has to be a Vector and not a NamedTuple. See this issue for more information. Nonetheless, the NamedTuple type is still supported in standard simulations, where the gradient is not needed.

To Do:

  • Implement a custom struct for the ODE Parameters
  • Implement a custom struct for the ODEProblems generated by the solvers
  • Implement the SciMLStructures.jl rules for the custom params struct
  • Make sesolve differentiable
  • Make mesolve differentiable
  • Make mcsolve differentiable (maybe in another PR?)

@ytdHuang
Copy link
Member

ytdHuang commented Nov 15, 2024

I think for some of the parameters which must be used in all solvers (e.g., tlist and progress_bar, dims ...) can still be a independent field and put it in QuantumTimeEvoParameters.

In this case, we don't need to define QuantumTimeEvoProblem right ? Just also put them in QuantumTimeEvoParameters.

BTW, maybe call it TimeEvoParameters is also a good choice.

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