Skip to content

Commit

Permalink
Merge branch 'master' into qqy/sdefunction
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas authored Sep 22, 2023
2 parents cf4c46f + 600fd4c commit 3d3515f
Show file tree
Hide file tree
Showing 11 changed files with 539 additions and 175 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
- {user: SciML, repo: StochasticDelayDiffEq.jl, group: All}
- {user: SciML, repo: SimpleNonlinearSolve.jl, group: All}
- {user: SciML, repo: SimpleDiffEq.jl, group: All}
- {user: SciML, repo: SciMLSensitivity.jl, group: Core1}
- {user: SciML, repo: SciMLSensitivity.jl, group: Core2}
- {user: SciML, repo: SciMLSensitivity.jl, group: Core3}
- {user: SciML, repo: SciMLSensitivity.jl, group: Core4}
- {user: SciML, repo: SciMLSensitivity.jl, group: Core5}

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SciMLBase"
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
authors = ["Chris Rackauckas <[email protected]> and contributors"]
version = "1.97.1"
version = "2.0.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand All @@ -12,6 +12,7 @@ ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down Expand Up @@ -45,6 +46,7 @@ CommonSolve = "0.2.4"
ConstructionBase = "1"
DocStringExtensions = "0.8, 0.9"
EnumX = "1"
FillArrays = "1.6"
FunctionWrappersWrappers = "0.1.3"
IteratorInterfaceExtensions = "^0.1, ^1"
PrecompileTools = "1"
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@
SciMLBase.jl is the core interface definition of the SciML ecosystem. It is a
low dependency library made to be depended on by the downstream libraries to
supply the common interface and allow for interexchange of mathematical problems.

## v2.0 Breaking Changes

The breaking changes in v2.0 are:

* `IntegralProblem` has moved to an interface with `IntegralFunction` and `BatchedIntegralFunction` which requires specifying `prototype`s for the values to be modified
instead of `nout` and `batch`. https://github.com/SciML/SciMLBase.jl/pull/497
* `ODEProblem` was made temporarily into a `mutable struct` to allow for EnzymeRules support. Using the mutation throws a warning that this is only experimental and should not be relied on.
https://github.com/SciML/SciMLBase.jl/pull/501
* `BVProblem` now has a new interface for `TwoPointBVProblem` which splits the bc terms for the two sides, forcing a true two-point BVProblem to allow for further specializations and to allow
for wrapping Fortran solvers in the interface. https://github.com/SciML/SciMLBase.jl/pull/477
* `SDEProblem` constructor was changed to remove an anti-pattern which required passing the diffusion function `g` twice, i.e. `SDEProblem(SDEFunction(f,g),g, ...)`.
Now this is simply `SDEProblem(SDEFunction(f,g),...)`. https://github.com/SciML/SciMLBase.jl/pull/489
20 changes: 15 additions & 5 deletions src/SciMLBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import TruncatedStacktraces
import ADTypes: AbstractADType
import ChainRulesCore
import ZygoteRules: @adjoint
import FillArrays

using Reexport
using SciMLOperators
Expand Down Expand Up @@ -588,6 +589,14 @@ abstract type AbstractDiffEqFunction{iip} <:
"""
$(TYPEDEF)
Base for types defining integrand functions.
"""
abstract type AbstractIntegralFunction{iip} <:
AbstractSciMLFunction{iip} end

"""
$(TYPEDEF)
Base for types defining optimization functions.
"""
abstract type AbstractOptimizationFunction{iip} <: AbstractSciMLFunction{iip} end
Expand Down Expand Up @@ -658,7 +667,9 @@ function specialization(::Union{ODEFunction{iip, specialize},
RODEFunction{iip, specialize},
NonlinearFunction{iip, specialize},
OptimizationFunction{iip, specialize},
BVPFunction{iip, specialize}}) where {iip,
BVPFunction{iip, specialize},
IntegralFunction{iip, specialize},
BatchIntegralFunction{iip, specialize}}) where {iip,
specialize}
specialize
end
Expand Down Expand Up @@ -760,9 +771,7 @@ export solve, solve!, init, discretize, symbolic_discretize

export LinearProblem,
NonlinearProblem, IntervalNonlinearProblem,
IntegralProblem, OptimizationProblem

export IntegralProblem
IntegralProblem, SampledIntegralProblem, OptimizationProblem

export DiscreteProblem, ImplicitDiscreteProblem
export SteadyStateProblem, SteadyStateSolution
Expand All @@ -788,7 +797,8 @@ export remake

export ODEFunction, DiscreteFunction, ImplicitDiscreteFunction, SplitFunction, DAEFunction,
DDEFunction, SDEFunction, SplitSDEFunction, RODEFunction, SDDEFunction,
IncrementingODEFunction, NonlinearFunction, IntervalNonlinearFunction, BVPFunction
IncrementingODEFunction, NonlinearFunction, IntervalNonlinearFunction, BVPFunction,
IntegralFunction, BatchIntegralFunction

export OptimizationFunction

Expand Down
128 changes: 100 additions & 28 deletions src/problems/basic_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,25 +334,17 @@ which are `Number`s or `AbstractVector`s with the same geometry as `u`.
### Constructors
IntegralProblem{iip}(f,lb,ub,p=NullParameters();
nout=1, batch = 0, kwargs...)
```
IntegralProblem(f,domain,p=NullParameters(); kwargs...)
IntegralProblem(f,lb,ub,p=NullParameters(); kwargs...)
```
- f: the integrand, `y = f(u,p)` for out-of-place or `f(y,u,p)` for in-place.
- f: the integrand, callable function `y = f(u,p)` for out-of-place (default) or an
`IntegralFunction` or `BatchIntegralFunction` for inplace and batching optimizations.
- domain: an object representing an integration domain, i.e. the tuple `(lb, ub)`.
- lb: Either a number or vector of lower bounds.
- ub: Either a number or vector of upper bounds.
- p: The parameters associated with the problem.
- nout: The output size of the function f. Defaults to 1, i.e., a scalar valued function.
If `nout > 1` f is a vector valued function .
- batch: The preferred number of points to batch. This allows user-side parallelization
of the integrand. If `batch == 0` no batching is performed.
If `batch > 0` both `u` and `y` get an additional dimension added to it.
This means that:
if `f` is a multi variable function each `u[:,i]` is a different point to evaluate `f` at,
if `f` is a single variable function each `u[i]` is a different point to evaluate `f` at,
if `f` is a vector valued function each `y[:,i]` is the evaluation of `f` at a different point,
if `f` is a scalar valued function `y[i]` is the evaluation of `f` at a different point.
Note that batch is a suggestion for the number of points,
and it is not necessarily true that batch is the same as batchsize in all algorithms.
- kwargs: Keyword arguments copied to the solvers.
Additionally, we can supply iip like IntegralProblem{iip}(...) as true or false to declare at
Expand All @@ -362,35 +354,115 @@ compile time whether the integrator function is in-place.
The fields match the names of the constructor arguments.
"""
struct IntegralProblem{isinplace, P, F, B, K} <: AbstractIntegralProblem{isinplace}
struct IntegralProblem{isinplace, P, F, T, K} <: AbstractIntegralProblem{isinplace}
f::F
lb::B
ub::B
nout::Int
domain::T
p::P
batch::Int
kwargs::K
@add_kwonly function IntegralProblem{iip}(f, lb, ub, p = NullParameters();
nout = 1,
batch = 0, kwargs...) where {iip}
@assert typeof(lb)==typeof(ub) "Type of lower and upper bound must match"
@add_kwonly function IntegralProblem{iip}(f::AbstractIntegralFunction{iip}, domain,
p = NullParameters();
kwargs...) where {iip}
warn_paramtype(p)
new{iip, typeof(p), typeof(f), typeof(lb), typeof(kwargs)}(f, lb, ub, nout, p,
batch, kwargs)
new{iip, typeof(p), typeof(f), typeof(domain), typeof(kwargs)}(f,
domain, p, kwargs)
end
end

TruncatedStacktraces.@truncate_stacktrace IntegralProblem 1 4

function IntegralProblem(f, lb, ub, args...; kwargs...)
IntegralProblem{isinplace(f, 3)}(f, lb, ub, args...; kwargs...)
function IntegralProblem(f::AbstractIntegralFunction,
domain,
p = NullParameters();
kwargs...)
IntegralProblem{isinplace(f)}(f, domain, p; kwargs...)
end

function IntegralProblem(f::AbstractIntegralFunction,
lb::B,
ub::B,
p = NullParameters();
kwargs...) where {B}
IntegralProblem(f, (lb, ub), p; kwargs...)
end

function IntegralProblem(f, args...; nout = nothing, batch = nothing, kwargs...)
if nout !== nothing || batch !== nothing
@warn "`nout` and `batch` keywords are deprecated in favor of inplace `IntegralFunction`s or `BatchIntegralFunction`s. See the updated Integrals.jl documentation for details."
end

max_batch = batch === nothing ? 0 : batch
g = if isinplace(f, 3)
output_prototype = Vector{Float64}(undef, nout === nothing ? 1 : nout)
if max_batch == 0
IntegralFunction(f, output_prototype)
else
BatchIntegralFunction(f, output_prototype, max_batch=max_batch)
end
else
if max_batch == 0
IntegralFunction(f)
else
BatchIntegralFunction(f, max_batch=max_batch)
end
end
IntegralProblem(g, args...; kwargs...)
end

struct QuadratureProblem end
@deprecate QuadratureProblem(args...; kwargs...) IntegralProblem(args...; kwargs...)

@doc doc"""
Defines a integral problem over pre-sampled data.
Documentation Page: https://docs.sciml.ai/Integrals/stable/
## Mathematical Specification of a data Integral Problem
Sampled integral problems are defined as:
```math
\sum_i w_i y_i
```
where `y_i` are sampled values of the integrand, and `w_i` are weights
assigned by a quadrature rule, which depend on sampling points `x`.
## Problem Type
### Constructors
```
SampledIntegralProblem(y::AbstractArray, x::AbstractVector; dim=ndims(y), kwargs...)
```
- y: The sampled integrand, must be a subtype of `AbstractArray`.
It is assumed that the values of `y` along dimension `dim`
correspond to the integrand evaluated at sampling points `x`
- x: Sampling points, must be a subtype of `AbstractVector`.
- dim: Dimension along which to integrate. Defaults to the last dimension of `y`.
- kwargs: Keyword arguments copied to the solvers.
### Fields
The fields match the names of the constructor arguments.
"""
struct SampledIntegralProblem{Y, X, K} <: AbstractIntegralProblem{false}
y::Y
x::X
dim::Int
kwargs::K
@add_kwonly function SampledIntegralProblem(y::AbstractArray, x::AbstractVector;
dim = ndims(y),
kwargs...)
@assert dim<=ndims(y) "The integration dimension `dim` is larger than the number of dimensions of the integrand `y`"
@assert length(x)==size(y, dim) "The integrand `y` must have the same length as the sampling points `x` along the integrated dimension."
@assert axes(x, 1)==axes(y, dim) "The integrand `y` must obey the same indexing as the sampling points `x` along the integrated dimension."
new{typeof(y), typeof(x), typeof(kwargs)}(y, x, dim, kwargs)
end
end

TruncatedStacktraces.@truncate_stacktrace SampledIntegralProblem 1 4

@doc doc"""
Defines an optimization problem.
Documentation Page: https://docs.sciml.ai/Optimization/stable/API/optimization_problem/
Expand Down
Loading

0 comments on commit 3d3515f

Please sign in to comment.