|
| 1 | +struct IntegralCache{P, A, S, K, Tc} |
| 2 | + prob::P |
| 3 | + alg::A |
| 4 | + sensealg::S |
| 5 | + kwargs::K |
| 6 | + # cache for algorithm goes here (currently unused) |
| 7 | + cacheval::Tc |
| 8 | + isfresh::Bool |
| 9 | +end |
| 10 | + |
| 11 | +function SciMLBase.init(prob::IntegralProblem, |
| 12 | + alg::SciMLBase.AbstractIntegralAlgorithm; |
| 13 | + sensealg = ReCallVJP(ZygoteVJP()), |
| 14 | + do_inf_transformation = nothing, kwargs...) |
| 15 | + checkkwargs(kwargs...) |
| 16 | + prob = transformation_if_inf(prob, do_inf_transformation) |
| 17 | + cacheval = nothing |
| 18 | + isfresh = true |
| 19 | + |
| 20 | + IntegralCache{typeof(prob), |
| 21 | + typeof(alg), |
| 22 | + typeof(sensealg), |
| 23 | + typeof(kwargs), |
| 24 | + typeof(cacheval)}(prob, |
| 25 | + alg, |
| 26 | + sensealg, |
| 27 | + kwargs, |
| 28 | + cacheval, |
| 29 | + isfresh) |
| 30 | +end |
| 31 | + |
| 32 | +# Throw error if alg is not provided, as defaults are not implemented. |
| 33 | +function SciMLBase.solve(::IntegralProblem; kwargs...) |
| 34 | + checkkwargs(kwargs...) |
| 35 | + throw(ArgumentError(""" |
| 36 | +No integration algorithm `alg` was supplied as the second positional argument. |
| 37 | +Reccomended integration algorithms are: |
| 38 | +For scalar functions: QuadGKJL() |
| 39 | +For ≤ 8 dimensional vector functions: HCubatureJL() |
| 40 | +For > 8 dimensional vector functions: MonteCarloIntegration.vegas(f, st, en, kwargs...) |
| 41 | +See the docstrings of the different algorithms for more detail. |
| 42 | +""")) |
| 43 | +end |
| 44 | + |
| 45 | +""" |
| 46 | +```julia |
| 47 | +solve(prob::IntegralProblem, alg::SciMLBase.AbstractIntegralAlgorithm; kwargs...) |
| 48 | +``` |
| 49 | +
|
| 50 | +## Keyword Arguments |
| 51 | +
|
| 52 | +The arguments to `solve` are common across all of the quadrature methods. |
| 53 | +These common arguments are: |
| 54 | +
|
| 55 | + - `maxiters` (the maximum number of iterations) |
| 56 | + - `abstol` (absolute tolerance in changes of the objective value) |
| 57 | + - `reltol` (relative tolerance in changes of the objective value) |
| 58 | +""" |
| 59 | +function SciMLBase.solve(prob::IntegralProblem, |
| 60 | + alg::SciMLBase.AbstractIntegralAlgorithm; |
| 61 | + kwargs...) |
| 62 | + solve!(init(prob, alg; kwargs...)) |
| 63 | +end |
| 64 | + |
| 65 | +function SciMLBase.solve!(cache::IntegralCache) |
| 66 | + prob = cache.prob |
| 67 | + __solvebp(prob, cache.alg, cache.sensealg, prob.lb, prob.ub, prob.p; cache.kwargs...) |
| 68 | +end |
0 commit comments