https://github.com/juliaquantumcontrol/grapelinesearchanalysis.jl
Analyze and debug LBFGS linesearch behavior inside GRAPE
https://github.com/juliaquantumcontrol/grapelinesearchanalysis.jl
debugging-tool lbfgsb
Last synced: 7 months ago
JSON representation
Analyze and debug LBFGS linesearch behavior inside GRAPE
- Host: GitHub
- URL: https://github.com/juliaquantumcontrol/grapelinesearchanalysis.jl
- Owner: JuliaQuantumControl
- License: mit
- Created: 2021-10-24T15:46:28.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-21T19:10:08.000Z (over 1 year ago)
- Last Synced: 2024-05-22T05:05:47.759Z (over 1 year ago)
- Topics: debugging-tool, lbfgsb
- Language: Julia
- Homepage:
- Size: 270 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GRAPELinesearchAnalysis.jl
A package to analyze and debug LBFGS linesearch behavior inside [GRAPE.jl](https://github.com/JuliaQuantumControl/GRAPE.jl).
It works with either [Optim.jl](https://github.com/JuliaNLSolvers/Optim.jl)/[LBFGS](https://julianlsolvers.github.io/Optim.jl/stable/#algo/lbfgs/) or [LBFGSB.jl](https://github.com/Gnimuc/LBFGSB.jl) as a backend.
The package allows to explore how the value of the functional varies both in the direction of the gradient and in the search direction chosen by LBFGS for different step widths, around the step width α chosen by the optimizer
## Installation
The `GRAPELinesearchAnalysis` package is not registered. Thus, you can only install it from Github
## Usage
The package is designed to be used as a `callback` for a [GRAPE.jl](https://github.com/JuliaQuantumControl/GRAPE.jl) optimization. For example,
~~~
using GRAPELinesearchAnalysis
opt_result = optimize_grape(
problem,
callback=GRAPELinesearchAnalysis.plot_linesearch(
@__DIR__, samples=100, verbose=false, use_current_backend=false
),
)
~~~
will produce a set of images in the folder containing the script, one per iteration.
The plots are generated by temporarily switching to the [GR backend](https://docs.juliaplots.org/latest/backends/#[GR](https://github.com/jheinen/GR.jl)), unless `use_current_backend=true` is given. If `verbose=true`, is given, information about where the files are written will be printed to screen. The `samples` is the number of points to sample. Each points requires a full time propagation.
An exemplary generated plot will look like this:

This images analyzes the linesearch in a particular iteration of the optimization. The top panel shows the guess and the optimized pulse for that iteration. The second panel shows the gradient, which would be the update (up to a step width α determined by linesearch) in a first-order gradient ascent. The third panel shows the search direction determined by LBFGS, in comparison to the gradient. The LBFGS search direction is the gradient [scaled by the inverse of the approximate Hessian](https://julianlsolvers.github.io/Optim.jl/stable/#algo/lbfgs/).
The fourth panel shows how the value of the function would change in the direction of the gradient for different step width α.
Finally the bottom panel shows the same information for the LBFGS search direction, in comparison to the gradient. The initial value of the functional (α=0), i.e. J_T for the guess pulse, is indicated by a bullet in the bottom two panels. Also, the value of the functional and the step width α that was LBFGS actually chose are also indicated by a bullet in the bottom panel.