Skip to content

Commit

Permalink
seed the VEGASMC rng
Browse files Browse the repository at this point in the history
  • Loading branch information
lxvm committed Jan 9, 2024
1 parent 1600f33 commit 7c0cc90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
9 changes: 4 additions & 5 deletions ext/IntegralsMCIntegrationExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module IntegralsMCIntegrationExt
using MCIntegration, Integrals

function Integrals.__solvebp_call(prob::IntegralProblem, alg::VEGASMC, sensealg, domain, p;
reltol = nothing, abstol = nothing, maxiters = 1000)
reltol = nothing, abstol = nothing, maxiters = 10)
lb, ub = domain
mid = vec(collect((lb + ub) / 2))
vars = Continuous(vec([tuple(a,b) for (a,b) in zip(lb, ub)]))
var = Continuous(vec([tuple(a,b) for (a,b) in zip(lb, ub)]))

if prob.f isa BatchIntegralFunction
error("VEGASMC doesn't support batching. See https://github.com/numericalEFT/MCIntegration.jl/issues/29")
Expand All @@ -33,9 +33,8 @@ function Integrals.__solvebp_call(prob::IntegralProblem, alg::VEGASMC, sensealg,
end
end
dof = ones(Int, length(f0)) # each composite Continuous var gets 1 dof
res = integrate(f_, inplace=isinplace(prob), var=vars, dof=dof, solver=:vegasmc,
neval=alg.neval, niter=min(maxiters,alg.niter), block=alg.block, adapt=alg.adapt,
gamma=alg.gamma, verbose=alg.verbose, debug=alg.debug, type=eltype(f0), print=-2)
res = integrate(f_; var, dof, inplace=isinplace(prob), type=eltype(f0),
solver=:vegasmc, niter=maxiters, verbose=-2, print=-2, alg.kws...)
out, err, chi = if f0 isa Number
map(only, (res.mean, res.stdev, res.chi2))
else
Expand Down
20 changes: 9 additions & 11 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,16 @@ function ArblibJL(; check_analytic=false, take_prec=false, warn_on_no_convergenc
end

"""
VEGASMC(; neval=10^4, niter=20, block=16, adapt=true, gamma=1.0, verbose=-2, debug=false)
VEGASMC(; kws...)
Markov-chain based Vegas algorithm from MCIntegration.jl
Refer to
[`MCIntegration.integrate`](https://numericaleft.github.io/MCIntegration.jl/dev/lib/montecarlo/#MCIntegration.integrate-Tuple{Function})
for documentation on the keywords, which are passed directly to the solver with a set of
defaults that works for conforming integrands.
"""
struct VEGASMC <: SciMLBase.AbstractIntegralAlgorithm
neval::Int
niter::Int
block::Int
adapt::Bool
gamma::Float64
verbose::Int
debug::Bool
struct VEGASMC{K<:NamedTuple} <: SciMLBase.AbstractIntegralAlgorithm
kws::K
end
VEGASMC(; neval=10^4, niter=20, block=16, adapt=true, gamma=1.0, verbose=-2, debug=false) =
VEGASMC(neval, niter, block, adapt, gamma, verbose, debug)
VEGASMC(; kws...) = VEGASMC(NamedTuple(kws))

Check warning on line 387 in src/algorithms.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms.jl#L387

Added line #L387 was not covered by tests
2 changes: 1 addition & 1 deletion test/interface_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ alg_req = Dict(
max_dim = Inf, allows_iip = true),
# VEGAS() => (nout = 1, allows_batch = true, min_dim = 2, max_dim = Inf,
# allows_iip = true),
VEGASMC() => (nout = Inf, allows_batch = false, min_dim = 1, max_dim = Inf,
VEGASMC(seed=42) => (nout = Inf, allows_batch = false, min_dim = 1, max_dim = Inf,
allows_iip = true),
CubatureJLh() => (nout = Inf, allows_batch = true, min_dim = 1,
max_dim = Inf, allows_iip = true),
Expand Down

0 comments on commit 7c0cc90

Please sign in to comment.