https://github.com/sciml/diffeqcallbacks.jl
A library of useful callbacks for hybrid scientific machine learning (SciML) with augmented differential equation solvers
https://github.com/sciml/diffeqcallbacks.jl
callback dae dde differential-equations julia neural-ode ode scientific-machine-learning sciml sde
Last synced: 2 months ago
JSON representation
A library of useful callbacks for hybrid scientific machine learning (SciML) with augmented differential equation solvers
- Host: GitHub
- URL: https://github.com/sciml/diffeqcallbacks.jl
- Owner: SciML
- License: other
- Created: 2017-01-06T08:17:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-07-27T02:48:53.000Z (2 months ago)
- Last Synced: 2025-07-27T05:22:05.650Z (2 months ago)
- Topics: callback, dae, dde, differential-equations, julia, neural-ode, ode, scientific-machine-learning, sciml, sde
- Language: Julia
- Homepage: https://docs.sciml.ai/DiffEqCallbacks/stable/
- Size: 3.55 GB
- Stars: 99
- Watchers: 3
- Forks: 52
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Citation: CITATION.bib
Awesome Lists containing this project
README
# DiffEqCallbacks.jl: Prebuilt Callbacks for extending the solvers of DifferentialEquations.jl
[](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
[](https://docs.sciml.ai/DiffEqCallbacks/stable/)[](https://codecov.io/gh/SciML/DiffEqCallbacks.jl)
[](https://github.com/SciML/DiffEqCallbacks.jl/actions?query=workflow%3ACI)[](https://github.com/SciML/ColPrac)
[](https://github.com/SciML/SciMLStyle)[DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/) has an expressive callback system
which allows for customizable transformations of the solver behavior. DiffEqCallbacks.jl
is a library of pre-built callbacks which makes it easy to transform the solver into a
domain-specific simulation tool.## Tutorials and Documentation
For information on using the package,
[see the stable documentation](https://docs.sciml.ai/DiffEqCallbacks/stable/). Use the
[in-development documentation](https://docs.sciml.ai/DiffEqCallbacks/dev/) for the version of
the documentation, which contains the unreleased features.## Manifold Projection Example
Here we solve the harmonic oscillator:
```julia
using OrdinaryDiffEqu0 = ones(2)
function f(du, u, p, t)
du[1] = u[2]
du[2] = -u[1]
end
prob = ODEProblem(f, u0, (0.0, 100.0))
```However, this problem is supposed to conserve energy, and thus we define our manifold
to conserve the sum of squares:```julia
function g(resid, u, p, t)
resid[1] = u[2]^2 + u[1]^2 - 2
end
```To build the callback, we call
```julia
using DiffEqCallbacks, ADTypes
cb = ManifoldProjection(g, autodiff = AutoForwardDiff(), resid_prototype = zeros(1))
```Using this callback, the Runge-Kutta method `Vern7` conserves energy. Note that the
standard saving occurs after the step and before the callback, and thus we set
`save_everystep=false` to turn off all standard saving and let the callback
save after the projection is applied.```julia
using Test
sol = solve(prob, Vern7(), save_everystep = false, callback = cb)
@test sol[end][1]^2 + sol[end][2]^2 ≈ 2
```