Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IntegralsArblibExt #199

Merged
merged 5 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"

[weakdeps]
Arblib = "fb37089c-8514-4489-9461-98f9c8763369"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Cuba = "8a292aeb-7a57-582c-b821-06e4c11590b1"
Cubature = "667455a9-e2ce-5579-9412-b964f529a492"
Expand All @@ -22,13 +23,15 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[extensions]
IntegralsArblibExt = "Arblib"
IntegralsCubaExt = "Cuba"
IntegralsCubatureExt = "Cubature"
IntegralsFastGaussQuadratureExt = "FastGaussQuadrature"
IntegralsForwardDiffExt = "ForwardDiff"
IntegralsZygoteExt = ["Zygote", "ChainRulesCore"]

[compat]
Arblib = "1"
ChainRulesCore = "0.10.7, 1"
CommonSolve = "0.2"
Cuba = "2"
Expand All @@ -47,6 +50,7 @@ Zygote = "0.4.22, 0.5, 0.6"
julia = "1.9"

[extras]
Arblib = "fb37089c-8514-4489-9461-98f9c8763369"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Cuba = "8a292aeb-7a57-582c-b821-06e4c11590b1"
Cubature = "667455a9-e2ce-5579-9412-b964f529a492"
Expand All @@ -62,4 +66,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["SciMLSensitivity", "StaticArrays", "FiniteDiff", "Pkg", "SafeTestsets", "Test", "Distributions", "ForwardDiff", "Zygote", "ChainRulesCore", "FastGaussQuadrature", "Cuba", "Cubature"]
test = ["Arblib", "SciMLSensitivity", "StaticArrays", "FiniteDiff", "Pkg", "SafeTestsets", "Test", "Distributions", "ForwardDiff", "Zygote", "ChainRulesCore", "FastGaussQuadrature", "Cuba", "Cubature"]
7 changes: 7 additions & 0 deletions docs/src/solvers/IntegralSolvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ The following algorithms are available:
- `CubaCuhre`: Cuhre from Cuba.jl. Requires `using Cuba`. Works only for `>1`-dimensional integrations.
- `GaussLegendre`: Uses Gauss-Legendre quadrature with nodes and weights from FastGaussQuadrature.jl.
- `QuadratureRule`: Accepts a user-defined function that returns nodes and weights.
- `ArblibJL`: real- and complex-valued univariate integration of holomorphic
and meromorphic functions from Arblib.jl. Requires `using Arblib`.

```@docs
QuadGKJL
HCubatureJL
VEGAS
CubaVegas
CubaSUAVE
CubaDivonne
CubaCuhre
GaussLegendre
QuadratureRule
ArblibJL
```
33 changes: 33 additions & 0 deletions ext/IntegralsArblibExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module IntegralsArblibExt

using Arblib
using Integrals

function Integrals.__solvebp_call(prob::IntegralProblem, alg::ArblibJL, sensealg, domain, p;
reltol = 1e-8, abstol = 1e-8, maxiters = nothing)

lb_, ub_ = domain
lb, ub = map(first, domain)
if !isone(length(lb_)) || !isone(length(ub_))
error("ArblibJL only accepts one-dimensional quadrature problems.")

Check warning on line 12 in ext/IntegralsArblibExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/IntegralsArblibExt.jl#L12

Added line #L12 was not covered by tests
end
@assert prob.f isa IntegralFunction

if isinplace(prob)
res = Acb(0)
y_ = similar(prob.f.integrand_prototype, typeof(res))
f_ = (y, x; kws...) -> Arblib.set!(y, only(prob.f(y_, x, p; kws...)))
val = Arblib.integrate!(f_, res, lb, ub, atol=abstol, rtol=reltol,
check_analytic=alg.check_analytic, take_prec=alg.take_prec,
warn_on_no_convergence=alg.warn_on_no_convergence, opts=alg.opts)
SciMLBase.build_solution(prob, alg, val, nothing, retcode = ReturnCode.Success)
else
f_ = (x; kws...) -> only(prob.f(x, p; kws...))
val = Arblib.integrate(f_, lb, ub, atol=abstol, rtol=reltol,
check_analytic=alg.check_analytic, take_prec=alg.take_prec,
warn_on_no_convergence=alg.warn_on_no_convergence, opts=alg.opts)
SciMLBase.build_solution(prob, alg, val, nothing, retcode = ReturnCode.Success)
end
end

end
1 change: 1 addition & 0 deletions src/Integrals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,6 @@ end
export QuadGKJL, HCubatureJL, VEGAS, GaussLegendre, QuadratureRule, TrapezoidalRule
export CubaVegas, CubaSUAVE, CubaDivonne, CubaCuhre
export CubatureJLh, CubatureJLp
export ArblibJL

end # module
26 changes: 26 additions & 0 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,29 @@ Defaults to `Cubature.INDIVIDUAL`, other options are
struct CubatureJLp <: AbstractCubatureJLAlgorithm
error_norm::Int32
end


"""
ArblibJL(; check_analytic=false, take_prec=false, warn_on_no_convergence=false, opts=C_NULL)

One-dimensional adaptive Gauss-Legendre integration using rigorous error bounds and
precision ball arithmetic. Generally this assumes the integrand is holomorphic or
meromorphic, which is the user's responsibility to verify. The result of the integral is not
guaranteed to satisfy the requested tolerances, however the result is guaranteed to be
within the error estimate.

[Arblib.jl](https://github.com/kalmarek/Arblib.jl) only supports integration of univariate
real- and complex-valued functions with both inplace and out-of-place forms. See their
documentation for additional details the algorithm arguments and on implementing
high-precision integrands. Additionally, the error estimate is included in the return value
of the integral, representing a ball.
"""
struct ArblibJL{O} <: SciMLBase.AbstractIntegralAlgorithm
check_analytic::Bool
take_prec::Bool
warn_on_no_convergence::Bool
opts::O
end
function ArblibJL(; check_analytic=false, take_prec=false, warn_on_no_convergence=false, opts=C_NULL)
return ArblibJL(check_analytic, take_prec, warn_on_no_convergence, opts)
end
7 changes: 4 additions & 3 deletions test/interface_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Integrals
using Cuba, Cubature
using Cuba, Cubature, Arblib
using Test

max_dim_test = 2
Expand All @@ -8,7 +8,7 @@ reltol = 1e-3
abstol = 1e-3

algs = [QuadGKJL, HCubatureJL, CubatureJLh, CubatureJLp, VEGAS, #CubaVegas,
CubaSUAVE, CubaDivonne, CubaCuhre]
CubaSUAVE, CubaDivonne, CubaCuhre, ArblibJL]

alg_req = Dict(QuadGKJL => (nout = 1, allows_batch = false, min_dim = 1, max_dim = 1,
allows_iip = false),
Expand All @@ -27,7 +27,8 @@ alg_req = Dict(QuadGKJL => (nout = 1, allows_batch = false, min_dim = 1, max_dim
CubaDivonne => (nout = Inf, allows_batch = true, min_dim = 2,
max_dim = Inf, allows_iip = true),
CubaCuhre => (nout = Inf, allows_batch = true, min_dim = 2, max_dim = Inf,
allows_iip = true))
allows_iip = true),
ArblibJL => (nout=1, allows_batch=false, min_dim=1, max_dim=1, allows_iip=true))

integrands = [
(x, p) -> 1.0,
Expand Down
Loading