Skip to content

Commit

Permalink
Make total fail a verbose exception error
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBrand1 committed Mar 7, 2024
1 parent 902d206 commit 67427fb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions EpiAware/src/inference-methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ of tries is reached.
- `mdl::DynamicPPL.Model`: The model to perform inference on.
- `max_tries`: The maximum number of tries to run the pathfinder algorithm. Default is
`Inf`.
- `nruns`: The number of times to run the `pathfinder` function.
- `kwargs...`: Additional keyword arguments passed to `pathfinder`.
# Returns
- `pfs`: The updated array of pathfinder objects.
"""
function _continue_manypathfinder!(pfs, mdl::DynamicPPL.Model; max_tries, kwargs...)
function _continue_manypathfinder!(pfs, mdl::DynamicPPL.Model; max_tries, nruns, kwargs...)
tryiter = 1
if all(pfs .== :fail)
@warn "All initial pathfinder runs failed, trying again for $max_tries tries."
Expand All @@ -53,8 +54,8 @@ function _continue_manypathfinder!(pfs, mdl::DynamicPPL.Model; max_tries, kwargs
tryiter += 1
end
if all(pfs .== :fail)
@warn "All pathfinder runs failed after $max_tries tries. Returning failed
pathfinder."
e = ErrorException("All pathfinder runs failed after $max_tries tries.")
throw(e)
end
return pfs
end
Expand Down Expand Up @@ -97,6 +98,6 @@ function manypathfinder(mdl::DynamicPPL.Model; nruns = 4, ndraws = 10,
nchains = 4, maxiters = 50, max_tries = 100, kwargs...)
ndraws = max(ndraws, nchains)
_run_manypathfinder(mdl; nruns, ndraws, maxiters, kwargs...) |>
pfs -> _continue_manypathfinder!(pfs, mdl; max_tries, kwargs...) |>
pfs -> _continue_manypathfinder!(pfs, mdl; max_tries, nruns, kwargs...) |>
pfs -> _get_best_elbo_pathfinder(pfs)
end

0 comments on commit 67427fb

Please sign in to comment.