Skip to content

Commit

Permalink
improve 'stew' reporting of timing
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Jul 16, 2023
1 parent b218539 commit 5aacfa3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pomp
Type: Package
Title: Statistical Inference for Partially Observed Markov Processes
Version: 5.2.5.4
Date: 2023-07-12
Version: 5.3.1.0
Date: 2023-07-16
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="kingaa@umich.edu",comment=c(ORCID="0000-0001-6159-3207")),
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")) ,
person(given="Carles",family="Bretó",role="aut",comment=c(ORCID="0000-0003-4695-4902")),
Expand Down
21 changes: 9 additions & 12 deletions R/bake.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
##' @rdname bake
##' @include package.R
##' @concept reproducibility
##'
##' @author Aaron A. King
##' @details
##' On cooking shows, recipes requiring lengthy baking or stewing are prepared beforehand.
##' The \code{bake} and \code{stew} functions perform analogously:
Expand All @@ -29,12 +29,10 @@
##' By contrast, \code{stew} creates a local environment within which \code{expr} is evaluated; all objects in that environment are saved (by name) in \code{file}.
##' \code{bake} and \code{stew} also store information about the code executed, the dependencies, and the state of the random-number generator (if the latter is controlled) in the archive file.
##' Re-computation is triggered if any of these things change.
##'
##' @section Avoid using \sQuote{pomp} objects as dependencies:
##' Note that when a \sQuote{pomp} object is built with one or more \link[=Csnippet]{C snippets}, the resulting code is \dQuote{salted} with a random element to prevent collisions in parallel computations.
##' As a result, two such \sQuote{pomp} objects will never match perfectly, even if the codes and data used to construct them are identical.
##' Therefore, avoid using \sQuote{pomp} objects as dependencies in \code{bake} and \code{stew}.
##'
##' @param file Name of the archive file in which the result will be stored or retrieved, as appropriate.
##' For \code{bake}, this will contain a single object and hence be an RDS file (extension \sQuote{rds});
##' for \code{stew}, this will contain one or more named objects and hence be an RDA file (extension \sQuote{rda}).
Expand Down Expand Up @@ -63,17 +61,14 @@
##' If \code{TRUE}, the \dQuote{ingredients} of the calculation are returned as a list.
##' In the case of \code{bake}, this list is the \dQuote{ingredients} attribute of the returned object.
##' In the case of \code{stew}, this list is a hidden object named \dQuote{.ingredients}, located in the environment within which \code{stew} was called.
##'
##' @inheritParams base::eval
##'
##' @section Compatibility with older versions:
##' With \pkg{pomp} version 3.4.4.2, the behavior of \code{bake} and \code{stew} changed.
##' In particular, older versions did no dependency checking, and did not check to see whether \code{expr} had changed.
##' Accordingly, the archive files written by older versions have a format that is not compatible with the newer ones.
##' When an archive file in the old format is encountered, it will be updated to the new format, with a warning message.
##' \strong{Note that this will overwrite existing archive files!}
##' However, there will be no loss of information.
##'
##' @return \code{bake} returns the value of the evaluated expression \code{expr}.
##' Other objects created in the evaluation of \code{expr} are discarded along with the temporary, local environment created for the evaluation.
##'
Expand All @@ -92,8 +87,6 @@
##' \code{bake} stores this in the \dQuote{system.time} attribute of the archived \R object;
##' \code{stew} does so in a hidden variable named \code{.system.time}.
##' The timing is obtained using \code{\link{system.time}}.
##'
##' @author Aaron A. King
##'
##' @example examples/bake.R
##'
Expand Down Expand Up @@ -253,7 +246,7 @@ update_stew_archive <- function (
stew <- function (
file, expr,
seed = NULL, kind = NULL, normal.kind = NULL,
dependson = NULL, info = FALSE,
dependson = NULL, info = FALSE, timing = TRUE,
dir = getOption("pomp_archive_dir",getwd())
) {
expr <- substitute(expr)
Expand All @@ -265,6 +258,7 @@ stew <- function (
ep="stew"
)
info <- as.logical(info)
timing <- as.logical(timing)
file <- create_path(dir,file)
reload <- file.exists(file)
e <- new.env(parent=pf)
Expand Down Expand Up @@ -305,12 +299,15 @@ stew <- function (
e$.system.time <- tmg
save(list=objects(envir=e,all.names=TRUE),file=file,envir=e)
}
objlist <- objects(envir=e,all.names=info)
objlist <- objects(envir=e,all.names=FALSE)
for (obj in objlist) {
assign(obj,get(obj,envir=e),envir=pf)
}
if (!info) {
assign(".system.time",e$.systemtime,envir=pf)
if (info) {
assign(".ingredients",e$.ingredients,envir=pf)
}
if (timing) {
assign(".system.time",e$.system.time,envir=pf)
}
invisible(objlist)
}
Expand Down
4 changes: 4 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
_N_e_w_s _f_o_r _p_a_c_k_a_g_e '_p_o_m_p'

_C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _5._3._1:

• ‘stew’ now returns timing information by default.

_C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _5._2._5:

• The new option ‘on_load’ allows one to specify a C snippet
Expand Down
5 changes: 5 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
\name{NEWS}
\title{News for package `pomp'}
\section{Changes in \pkg{pomp} version 5.3.1}{
\itemize{
\item \code{stew} now returns timing information by default.
}
}
\section{Changes in \pkg{pomp} version 5.2.5}{
\itemize{
\item The new option \code{on_load} allows one to specify a C snippet that will be executed at the time the C snippet library is loaded.
Expand Down
1 change: 1 addition & 0 deletions man/bake.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5aacfa3

Please sign in to comment.