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
4 changes: 4 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
group:
- Core
- AD
- nopre
version:
- '1'
- 'lts'
Expand All @@ -29,6 +30,9 @@ jobs:
version: '1'
- group: AD
version: 'pre'
# nopre tests (JET) should not run on pre-release or LTS Julia versions
- group: nopre
version: 'pre'
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ LinearAlgebra = "1.10"
MCIntegration = "0.4.2"
MonteCarloIntegration = "0.2"
Mooncake = "0.4.184"
Pkg = "1.10"
QuadGK = "2.11"
Random = "1.10"
Reexport = "1.2"
Expand All @@ -63,6 +64,7 @@ julia = "1.10"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Arblib = "fb37089c-8514-4489-9461-98f9c8763369"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Cuba = "8a292aeb-7a57-582c-b821-06e4c11590b1"
Expand All @@ -80,4 +82,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Aqua", "Arblib", "StaticArrays", "FiniteDiff", "SafeTestsets", "Test", "Distributions", "ForwardDiff", "Zygote", "ChainRulesCore", "FastGaussQuadrature", "Cuba", "Cubature", "MCIntegration", "Mooncake", "ExplicitImports"]
test = ["Aqua", "Arblib", "StaticArrays", "FiniteDiff", "SafeTestsets", "Test", "Distributions", "ForwardDiff", "Zygote", "ChainRulesCore", "FastGaussQuadrature", "Cuba", "Cubature", "MCIntegration", "Mooncake", "ExplicitImports", "Pkg"]
7 changes: 6 additions & 1 deletion src/Integrals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ function scale_x(ub, lb, x)
return (ub .- lb) .* x .+ lb
end

# Type-stable check for real scalar values (handles both Number and 1-element arrays)
_is_real_scalar(y::Real) = true
_is_real_scalar(y::AbstractArray) = length(y) == 1 && eltype(y) <: Real
_is_real_scalar(y) = false

const allowedkeywords = (:maxiters, :abstol, :reltol)
const KWARGERROR_MESSAGE = """
Unrecognized keyword arguments found.
Expand Down Expand Up @@ -346,7 +351,7 @@ function __solvebp_call(
if f isa BatchIntegralFunction
@assert prod(size(y)[begin:(end - 1)]) == 1&&eltype(y) <: Real "VEGAS only supports Float64-valued scalar integrands"
else
@assert length(y) == 1&&eltype(y) <: Real "VEGAS only supports Float64-valued scalar integrands"
@assert _is_real_scalar(y) "VEGAS only supports Float64-valued scalar integrands"
end

ncalls = alg.ncalls
Expand Down
7 changes: 7 additions & 0 deletions test/nopre/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[deps]
Integrals = "de52edbc-65ea-441a-8357-d3a637375a31"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
JET = "0.9, 0.10, 0.11.3"
54 changes: 54 additions & 0 deletions test/nopre/jet_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Integrals
using JET
using Test

@testset "JET static analysis" begin
@testset "QuadGKJL" begin
f = (x, p) -> x^2
prob = IntegralProblem(f, (0.0, 1.0))
rep = @report_opt target_modules = (Integrals,) solve(prob, QuadGKJL())
@test length(JET.get_reports(rep)) == 0
end

@testset "HCubatureJL" begin
f = (x, p) -> x[1]^2 + x[2]^2
prob = IntegralProblem(f, ([0.0, 0.0], [1.0, 1.0]))
rep = @report_opt target_modules = (Integrals,) solve(prob, HCubatureJL())
@test length(JET.get_reports(rep)) == 0
end

@testset "SampledIntegralProblem with TrapezoidalRule" begin
x = range(0, 1, length = 100)
y = x .^ 2
prob = SampledIntegralProblem(y, x)
rep = @report_opt target_modules = (Integrals,) solve(prob, TrapezoidalRule())
@test length(JET.get_reports(rep)) == 0
end

@testset "SampledIntegralProblem with SimpsonsRule" begin
x = range(0, 1, length = 101)
y = x .^ 2
prob = SampledIntegralProblem(y, x)
rep = @report_opt target_modules = (Integrals,) solve(prob, SimpsonsRule())
@test length(JET.get_reports(rep)) == 0
end

@testset "Infinite bounds transformation" begin
f = (x, p) -> exp(-x^2)
prob = IntegralProblem(f, (0.0, Inf))
rep = @report_opt target_modules = (Integrals,) solve(prob, QuadGKJL())
@test length(JET.get_reports(rep)) == 0
end

@testset "VEGAS" begin
# VEGAS has some inherent type instability issues due to:
# 1. Captured variables in closures (necessary for in-place operations)
# 2. Runtime dispatch for integrand type checking
# We verify the number of issues is bounded and doesn't regress
f = (x, p) -> x^2
prob = IntegralProblem(f, (0.0, 1.0))
rep = @report_opt target_modules = (Integrals,) solve(prob, VEGAS())
# Allow up to 2 reports (captured variable + runtime dispatch for type check)
@test length(JET.get_reports(rep)) <= 2
end
end
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using Pkg
using SafeTestsets
using Test

const GROUP = get(ENV, "GROUP", "All")

function activate_nopre_env()
Pkg.activate("nopre")
Pkg.develop(PackageSpec(path = dirname(@__DIR__)))
return Pkg.instantiate()
end

if GROUP == "All" || GROUP == "Core"
@time @safetestset "Explicit Imports" include("explicit_imports_tests.jl")
@time @safetestset "Quality Assurance" include("qa.jl")
Expand All @@ -18,3 +25,8 @@ if GROUP == "All" || GROUP == "AD"
@time @safetestset "Derivative Tests" include("derivative_tests.jl")
@time @safetestset "Nested AD Tests" include("nested_ad_tests.jl")
end

if GROUP == "nopre"
activate_nopre_env()
@time @safetestset "JET Static Analysis" include("nopre/jet_tests.jl")
end