From 52ffaaa9af5b4cdec3f718658a2226d13c69d6b8 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 30 Jul 2025 12:45:42 -0400 Subject: [PATCH] Fix deprecation warnings in test suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes deprecation warnings by updating the test suite to use the new Integrals.jl API: 1. Update `IntegralProblem(f, lb, ub, p)` to `IntegralProblem(f, (lb, ub), p)` - The domain should now be passed as a tuple (lb, ub) instead of separate arguments 2. Replace deprecated `batch` and `nout` keywords with new interfaces: - Replace `IntegralProblem(f, domain, batch=1000)` with `IntegralProblem(BatchIntegralFunction(f), domain)` - Replace `IntegralProblem(f, domain, nout=n)` with `IntegralProblem(IntegralFunction(f, zeros(n)), domain)` - For in-place batch functions, use proper prototype vectors (e.g., `zeros(0)` or `zeros(nout, 0)`) These changes eliminate all deprecation warnings from the test suite while maintaining full functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- test/gaussian_quadrature_tests.jl | 10 +++---- test/interface_tests.jl | 48 ++++++++++++++----------------- test/nested_ad_tests.jl | 8 +++--- test/quadrule_tests.jl | 10 +++---- 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/test/gaussian_quadrature_tests.jl b/test/gaussian_quadrature_tests.jl index ae93e327..6175ed2a 100644 --- a/test/gaussian_quadrature_tests.jl +++ b/test/gaussian_quadrature_tests.jl @@ -46,7 +46,7 @@ alg = GaussLegendre(nodes = nd, weights = wt, subintervals = 20) @test alg.subintervals == 20 f = (x, p) -> 5x + sin(x) - p * exp(x) -prob = IntegralProblem(f, -5, 3, 3.3) +prob = IntegralProblem(f, (-5, 3), 3.3) alg = GaussLegendre() sol = solve(prob, alg) @test isnothing(sol.chi) @@ -60,7 +60,7 @@ sol = solve(prob, alg) @test sol.u ≈ -exp(3) * 3.3 + 3.3 / exp(5) - 40 + cos(5) - cos(3) f = (x, p) -> exp(-x^2) -prob = IntegralProblem(f, 0.0, Inf) +prob = IntegralProblem(f, (0.0, Inf)) alg = GaussLegendre() sol = solve(prob, alg) @test sol.u ≈ sqrt(π) / 2 @@ -69,7 +69,7 @@ alg = GaussLegendre(subintervals = 1) alg = GaussLegendre(subintervals = 17) @test sol.u ≈ sqrt(π) / 2 -prob = IntegralProblem(f, -Inf, Inf) +prob = IntegralProblem(f, (-Inf, Inf)) alg = GaussLegendre() sol = solve(prob, alg) @test sol.u ≈ sqrt(π) @@ -78,7 +78,7 @@ alg = GaussLegendre(subintervals = 1) alg = GaussLegendre(subintervals = 17) @test sol.u ≈ sqrt(π) -prob = IntegralProblem(f, -Inf, 0.0) +prob = IntegralProblem(f, (-Inf, 0.0)) alg = GaussLegendre() sol = solve(prob, alg) @test sol.u ≈ sqrt(π) / 2 @@ -90,7 +90,7 @@ alg = GaussLegendre(subintervals = 17) # Make sure broadcasting correctly handles the argument p f = (x, p) -> 1 + x + x^p[1] - cos(x * p[2]) + exp(x) * p[3] p = [0.3, 1.3, -0.5] -prob = IntegralProblem(f, 2.0, 6.3, p) +prob = IntegralProblem(f, (2.0, 6.3), p) alg = GaussLegendre() sol = solve(prob, alg) @test sol.u ≈ -240.25235266303063249920743158729 diff --git a/test/interface_tests.jl b/test/interface_tests.jl index 8fd67ea7..8c9ac38c 100644 --- a/test/interface_tests.jl +++ b/test/interface_tests.jl @@ -103,7 +103,7 @@ end continue end for i in 1:length(integrands) - prob = IntegralProblem(integrands[i], lb, ub) + prob = IntegralProblem(integrands[i], (lb, ub)) @info "Alg = $(nameof(typeof(alg))), Integrand = $i, Dimension = $dim, Output Dimension = $nout" sol = @inferred solve(prob, alg, reltol = reltol, abstol = abstol) @test sol.alg == alg @@ -118,7 +118,7 @@ end for i in 1:length(integrands) for dim in 1:max_dim_test lb, ub = (ones(dim), 3ones(dim)) - prob = IntegralProblem(integrands[i], lb, ub) + prob = IntegralProblem(integrands[i], (lb, ub)) if dim > req.max_dim || dim < req.min_dim continue end @@ -137,7 +137,7 @@ end for i in 1:length(iip_integrands) for dim in 1:max_dim_test lb, ub = (ones(dim), 3ones(dim)) - prob = IntegralProblem(iip_integrands[i], lb, ub) + prob = IntegralProblem(iip_integrands[i], (lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_iip continue end @@ -159,7 +159,7 @@ end (dim, nout) = (1, 1) for (alg, req) in pairs(alg_req) for i in 1:length(integrands) - prob = IntegralProblem(batch_f(integrands[i]), lb, ub, batch = 1000) + prob = IntegralProblem(BatchIntegralFunction(batch_f(integrands[i])), (lb, ub)) if req.min_dim > 1 || !req.allows_batch continue end @@ -177,7 +177,7 @@ end for i in 1:length(integrands) for dim in 1:max_dim_test (lb, ub) = (ones(dim), 3ones(dim)) - prob = IntegralProblem(batch_f(integrands[i]), lb, ub, batch = 1000) + prob = IntegralProblem(BatchIntegralFunction(batch_f(integrands[i])), (lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_batch continue end @@ -200,7 +200,7 @@ end for i in 1:length(iip_integrands) for dim in 1:max_dim_test (lb, ub) = (ones(dim), 3ones(dim)) - prob = IntegralProblem(batch_iip_f(integrands[i]), lb, ub, batch = 1000) + prob = IntegralProblem(BatchIntegralFunction(batch_iip_f(integrands[i]), zeros(0)), (lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_batch || !req.allows_iip continue @@ -225,10 +225,10 @@ end for (alg, req) in pairs(alg_req) for i in 1:length(integrands_v) for nout in 1:max_nout_test - prob = IntegralProblem(let f = integrands_v[i], nout = nout - (x, p) -> f(x, p, nout) - end, lb, ub, - nout = nout) + integrand_f = let f = integrands_v[i], nout = nout + IntegralFunction((x, p) -> f(x, p, nout), zeros(nout)) + end + prob = IntegralProblem(integrand_f, (lb, ub)) if req.min_dim > 1 || req.nout < nout continue end @@ -254,10 +254,10 @@ end if dim > req.max_dim || dim < req.min_dim || req.nout < nout continue end - prob = IntegralProblem(let f = integrands_v[i], nout = nout - (x, p) -> f(x, p, nout) - end, lb, ub, - nout = nout) + integrand_f = let f = integrands_v[i], nout = nout + IntegralFunction((x, p) -> f(x, p, nout), zeros(nout)) + end + prob = IntegralProblem(integrand_f, (lb, ub)) @info "Alg = $(nameof(typeof(alg))), Integrand = $i, Dimension = $dim, Output Dimension = $nout" sol = @inferred solve(prob, alg, reltol = reltol, abstol = abstol) @test sol.alg == alg @@ -278,10 +278,10 @@ end for dim in 1:max_dim_test lb, ub = (ones(dim), 3ones(dim)) for nout in 1:max_nout_test - prob = IntegralProblem(let f = iip_integrands_v[i] - (dx, x, p) -> f(dx, x, p, nout) - end, - lb, ub, nout = nout) + integrand_f = let f = iip_integrands_v[i] + IntegralFunction((dx, x, p) -> f(dx, x, p, nout), zeros(nout)) + end + prob = IntegralProblem(integrand_f, (lb, ub)) if dim > req.max_dim || dim < req.min_dim || req.nout < nout || !req.allows_iip continue @@ -305,8 +305,7 @@ end (dim, nout) = (1, 2) for (alg, req) in pairs(alg_req) for i in 1:length(integrands_v) - prob = IntegralProblem(batch_f_v(integrands_v[i], nout), lb, ub, batch = 1000, - nout = nout) + prob = IntegralProblem(BatchIntegralFunction(batch_f_v(integrands_v[i], nout)), (lb, ub)) if req.min_dim > 1 || !req.allows_batch || req.nout < nout continue end @@ -324,9 +323,7 @@ end for i in 1:length(integrands_v) for dim in 1:max_dim_test (lb, ub) = (ones(dim), 3ones(dim)) - prob = IntegralProblem(batch_f_v(integrands_v[i], nout), lb, ub, - batch = 1000, - nout = nout) + prob = IntegralProblem(BatchIntegralFunction(batch_f_v(integrands_v[i], nout)), (lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_batch || req.nout < nout continue @@ -346,8 +343,7 @@ end for i in 1:length(iip_integrands_v) for dim in 1:max_dim_test (lb, ub) = (ones(dim), 3ones(dim)) - prob = IntegralProblem(batch_iip_f_v(integrands_v[i], nout), lb, ub, - batch = 10, nout = nout) + prob = IntegralProblem(BatchIntegralFunction(batch_iip_f_v(integrands_v[i], nout), zeros(nout, 0)), (lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_batch || !req.allows_iip || req.nout < nout continue @@ -381,7 +377,7 @@ end continue end for i in 1:length(integrands) - prob = IntegralProblem(integrands[i], lb, ub, p) + prob = IntegralProblem(integrands[i], (lb, ub), p) cache = init(prob, alg, reltol = reltol, abstol = abstol) @test solve!(cache).u≈exact_sol[i](dim, nout, lb, ub) rtol=1e-2 cache.lb = lb = 0.5 diff --git a/test/nested_ad_tests.jl b/test/nested_ad_tests.jl index 65840ea8..308faf7a 100644 --- a/test/nested_ad_tests.jl +++ b/test/nested_ad_tests.jl @@ -3,7 +3,7 @@ using Integrals, FiniteDiff, ForwardDiff, Cubature, Cuba, Zygote, Test my_parameters = [1.0, 2.0] my_function(x, p) = x^2 + p[1]^3 * x + p[2]^2 function my_integration(p) - my_problem = IntegralProblem(my_function, -1.0, 1.0, p) + my_problem = IntegralProblem(my_function, (-1.0, 1.0), p) # return solve(my_problem, HCubatureJL(), reltol=1e-3, abstol=1e-3) # Works return solve(my_problem, CubatureJLh(), reltol = 1e-3, abstol = 1e-3) # Errors end @@ -19,7 +19,7 @@ ub = 3ones(2) p = [1.5, 2.0] function testf(p) - prob = IntegralProblem(ff, lb, ub, p) + prob = IntegralProblem(ff, (lb, ub), p) sin(solve(prob, CubaCuhre(), reltol = 1e-6, abstol = 1e-6)[1]) end @@ -32,10 +32,10 @@ lb = 1.0 ub = 3.0 p = [2.0, 3.0, 4.0] _ff3 = BatchIntegralFunction(ff2) -prob = IntegralProblem(_ff3, lb, ub, p) +prob = IntegralProblem(_ff3, (lb, ub), p) function testf3(lb, ub, p; f = _ff3) - prob = IntegralProblem(_ff3, lb, ub, p) + prob = IntegralProblem(_ff3, (lb, ub), p) solve(prob, CubatureJLh(); reltol = 1e-3, abstol = 1e-3)[1] end diff --git a/test/quadrule_tests.jl b/test/quadrule_tests.jl index 8cbfe266..d96216bc 100644 --- a/test/quadrule_tests.jl +++ b/test/quadrule_tests.jl @@ -30,7 +30,7 @@ lb = -1.2 ub = 3.5 p = 2.0 -prob = IntegralProblem(f, lb, ub, p) +prob = IntegralProblem(f, (lb, ub), p) u = solve(prob, alg).u @test u≈exact_f(lb, ub, p) rtol=1e-3 @@ -49,7 +49,7 @@ lb = SVector(-1.2, -1.0) ub = SVector(3.5, 3.7) p = 1.2 -prob = IntegralProblem(f, lb, ub, p) +prob = IntegralProblem(f, (lb, ub), p) u = solve(prob, alg).u @test u≈exact_f(lb, ub, p) rtol=1e-3 @@ -64,7 +64,7 @@ lb = -Inf ub = Inf p = 1.0 -prob = IntegralProblem(g, lb, ub, p) +prob = IntegralProblem(g, (lb, ub), p) @test solve(prob, alg).u≈pi rtol=1e-4 @@ -78,7 +78,7 @@ lb = -Inf ub = Inf p = (1.0, 1.3) -prob = IntegralProblem(g2, lb, ub, p) +prob = IntegralProblem(g2, (lb, ub), p) @test solve(prob, alg).u≈[pi, pi] rtol=1e-4 @@ -87,7 +87,7 @@ prob = IntegralProblem(g2, lb, ub, p) using Zygote function testf(lb, ub, p, f = f) - prob = IntegralProblem(f, lb, ub, p) + prob = IntegralProblem(f, (lb, ub), p) solve(prob, QuadratureRule(trapz, n=200))[1] end