https://github.com/juliaquantumcontrol/grape.jl
Gradient Ascent Pulse Engineering in Julia
https://github.com/juliaquantumcontrol/grape.jl
grape julia optimal-control quantum
Last synced: 11 days ago
JSON representation
Gradient Ascent Pulse Engineering in Julia
- Host: GitHub
- URL: https://github.com/juliaquantumcontrol/grape.jl
- Owner: JuliaQuantumControl
- License: mit
- Created: 2021-08-10T13:29:51.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-25T14:05:10.000Z (about 1 year ago)
- Last Synced: 2025-01-20T18:40:16.040Z (10 months ago)
- Topics: grape, julia, optimal-control, quantum
- Language: Julia
- Homepage: https://juliaquantumcontrol.github.io/GRAPE.jl/
- Size: 26.9 MB
- Stars: 10
- Watchers: 1
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GRAPE.jl
[](https://juliahub.com/ui/Packages/General/GRAPE)
[](https://juliaquantumcontrol.github.io/GRAPE.jl/)
[](https://juliaquantumcontrol.github.io/GRAPE.jl/dev)
[](https://joss.theoj.org/papers/25e7a240c129459ad160dd3fb9d009d8)
[](https://github.com/JuliaQuantumControl/GRAPE.jl/actions)
[](https://github.com/JuliaQuantumControl/GRAPE.jl/actions/workflows/REUSE.yml)
[](https://codecov.io/gh/JuliaQuantumControl/GRAPE.jl)
Implementation of GRadient Ascent Pulse Engineering (GRAPE)
## Installation
[As usual for a registered Julia package](https://docs.julialang.org/en/v1/stdlib/Pkg/), `GRAPE` can be installed by typing
```
] add GRAPE
```
in the Julia REPL.
## Usage Example
A minimal working example optimizing a state-to-state transition `|0⟩ → |1⟩` in a two-level quantum system:
```julia
using GRAPE
using QuantumPropagators: hamiltonian # data structure for `H = H₀ + ϵ(t) H₁`
using QuantumControl.Functionals: J_T_sm # square-modulus functional
using QuantumPropagators: ExpProp # propagation method: matrix exponentiation
ϵ(t) = 0.2 # guess pulse
H = hamiltonian([1 0; 0 -1], ([0 1; 1 0], ϵ)) # time-dependent Hamiltonian
ket_0, ket_1 = ComplexF64[1, 0], ComplexF64[0, 1] # basis states |0⟩, |1⟩
tlist = collect(range(0, 5, length=501)); # time grid; final time T = 5.0
# Optimization functionals depend on states |Ψ(T)⟩, described by a "trajectory"
traj = GRAPE.Trajectory(
initial_state = ket_0,
generator = H,
target_state = ket_1
);
result = GRAPE.optimize(
[traj], tlist;
prop_method = ExpProp, # suitable for small systems only!
J_T = J_T_sm, # J_T = 1 - |⟨Ψ(T)|1⟩|²
# without convergence check, stop after 5000 iterations
check_convergence=(res -> ((res.J_T < 1e-3) && "J_T < 10⁻³")),
)
ϵ_opt = result.optimized_controls[1]
# Or, using the QuantumControl API (recommended)
using QuantumControl: ControlProblem, optimize, @optimize_or_load
problem = ControlProblem(
[traj], tlist,
prop_method = ExpProp,
J_T = J_T_sm,
check_convergence=(res -> ((res.J_T < 1e-3) && "J_T < 10⁻³")),
)
result = optimize(problem; method=GRAPE)
# This dumps the optimization result in `tls_opt.jld2`
result = @optimize_or_load("tls_opt.jld2", problem; method = GRAPE)
```
See the [Tutorial](https://juliaquantumcontrol.github.io/GRAPE.jl/stable/tutorial/) and [Usage section](https://juliaquantumcontrol.github.io/GRAPE.jl/stable/usage/) in the documentation for more details.
## Documentation
The documentation of `GRAPE.jl` is available at .
## Contributing
See [`CONTRIBUTING.md`](https://github.com/JuliaQuantumControl/.github/blob/master/CONTRIBUTING.md#contributing-to-juliaquantumcontrol-packages) and the [organization development notes](https://github.com/JuliaQuantumControl#development).
[`QuantumControl.jl`]: https://github.com/JuliaQuantumControl/QuantumControl.jl#readme
[JuliaQuantumControl]: https://github.com/JuliaQuantumControl
## History
See the [`CHANGELOG.md`](CHANGELOG.md) and the [Release Notes](https://github.com/JuliaQuantumControl/GRAPE.jl/releases).
## License
The source code of this project is licensed under the [MIT License](LICENSE). The documentation is licensed under [Creative Commons (`CC-BY-4.0`)](https://creativecommons.org/licenses/by/4.0/deed.en). License information for all files is [automatically tracked](https://github.com/JuliaQuantumControl/GRAPE.jl/actions/workflows/REUSE.yml) according to [REUSE](https://reuse.software) and can be verified using the [`reuse` tool](https://github.com/fsfe/reuse-tool?tab=readme-ov-file#reuse), e.g., by running `reuse spdx`.