Skip to content
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
19 changes: 19 additions & 0 deletions docs/src/basics/solve.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ solve(::IntegralProblem, ::SciMLBase.AbstractIntegralAlgorithm)
solve(::SampledIntegralProblem, ::SciMLBase.AbstractIntegralAlgorithm)
```

## Default tolerances

`QuadGKJL`, `HCubatureJL`, `CubatureJLh`, `CubatureJLp`, and
`HAdaptiveIntegrationJL` default to `abstol = 0` and `reltol = 1e-8`. With
`abstol = 0` the solvers control the integral residual through the relative
tolerance alone, so a small integral is not treated as converged just because its
residual is below a fixed absolute floor.

For integrands dominated by cancellation — large positive and negative
contributions that nearly cancel, such as the zero integral of `sin(2πx)` on
`[0, 1]` — a zero `abstol` can drive the solver to refine until it exhausts
`maxiters` without satisfying the relative bound. In that case pass a positive,
problem-scaled `abstol`, for example proportional to the magnitude of the
integrand times the domain volume:

```julia
sol = solve(prob, QuadGKJL(); abstol = 1e-8)
```

## Related SciML interface utilities

`init`, `solve!`, `isinplace`, `remake`, and `ReturnCode` are SciMLBase interface
Expand Down
10 changes: 9 additions & 1 deletion src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,15 @@ The arguments to `solve` are common across all of the quadrature methods.
These common arguments are:
- `maxiters`: Maximum number of algorithm iterations or backend evaluations.
- `abstol`: Absolute tolerance for the integral residual/error estimate.
- `abstol`: Absolute tolerance for the integral residual/error estimate. The default
is `0` for `QuadGKJL()`, `HCubatureJL()`, `CubatureJLh()`, `CubatureJLp()`, and
`HAdaptiveIntegrationJL()`, so small integrals are not swamped by a nonzero floor
and the residual is controlled by `reltol` alone. For integrands dominated by
cancellation (large positive and negative contributions that nearly cancel), a
zero `abstol` can force the solver to refine until an unachievable relative
bound is met and the effort budget is exhausted; pass a positive, problem-scaled
`abstol` (for example proportional to the magnitude of the integrand and the
domain volume) in that case.
- `reltol`: Relative tolerance for the integral residual/error estimate.
- `verbose`: Verbosity control via [`IntegralVerbosity`](@ref). Defaults to
`IntegralVerbosity()`.
Expand Down
21 changes: 19 additions & 2 deletions test/interface_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Integrals
using Cuba, Cubature, Arblib, FastGaussQuadrature, FastTanhSinhQuadrature, MCIntegration
using Cuba, Cubature, Arblib, FastGaussQuadrature, FastTanhSinhQuadrature, MCIntegration, HAdaptiveIntegration
using Test

max_dim_test = 2
Expand Down Expand Up @@ -552,7 +552,7 @@ end
# exact value of the integral over (0, 2en)
exact = (-151 + 101 * sqrt(101)) / 7.5e11

for alg in (QuadGKJL(), HCubatureJL(), CubatureJLh())
for alg in (QuadGKJL(), HCubatureJL(), CubatureJLh(), HAdaptiveIntegrationJL())
scaled = solve(IntegralProblem((x, p) -> g(x), (0.0, 2en)), alg).u
@test scaled ≈ exact rtol = 1.0e-6
# scaling the integrand has to scale the integral
Expand All @@ -562,3 +562,20 @@ end
end
end
end

# CubatureJLp is not in the loop above: its p-adaptive rules return 0.0 on the
# narrow-support spike there at any budget, while on smooth integrands the
# default abstol = 0 keeps this small analytic integral resolved.
@testset "smooth small integral with default abstol" begin
f = (x, p) -> 1.0e-9 * exp(x)
exact = 1.0e-9 * (exp(1.0) - 1.0)
for alg in (CubatureJLp(), HAdaptiveIntegrationJL())
scaled = solve(IntegralProblem(f, (0.0, 1.0)), alg).u
@test scaled ≈ exact rtol = 1.0e-6
# scaling the integrand has to scale the integral
for n in (100.0, 1.0e6)
full = solve(IntegralProblem((x, p) -> n * f(x, p), (0.0, 1.0)), alg).u
@test n * scaled ≈ full rtol = 1.0e-6
end
end
end
Loading