From 503441b0a958c1df50df0ee7cfc3bde4ea1b1865 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 20 Nov 2020 19:43:46 +0100 Subject: Support storing mkinmod compiled code as CFunc objects With automatic reloading in mkinfit and mkinpredict in case the DLL is not loaded and the original DLL path has been cleaned up. Depends on jranke/inline@974bdea04fcedfafaab231e6f359c88270b56cb9 See inline#13 --- man/mkinmod.Rd | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'man/mkinmod.Rd') diff --git a/man/mkinmod.Rd b/man/mkinmod.Rd index e5b1c8f3..f71ebfb3 100644 --- a/man/mkinmod.Rd +++ b/man/mkinmod.Rd @@ -9,9 +9,11 @@ mkinmod( ..., use_of_ff = "max", + name = NULL, speclist = NULL, quiet = FALSE, - verbose = FALSE + verbose = FALSE, + cf_dir = NULL ) \method{print}{mkinmod}(x, ...) @@ -40,6 +42,8 @@ formation fractions are always used (default). If "min", a minimum use of formation fractions is made, i.e. each pathway to a metabolite has its own rate constant.} +\item{name}{A name for the model. Should be a valid R object name.} + \item{speclist}{The specification of the observed variables and their submodel types and pathways can be given as a single list using this argument. Default is NULL.} @@ -49,6 +53,9 @@ argument. Default is NULL.} \item{verbose}{If \code{TRUE}, passed to \code{\link[inline:cfunction]{inline::cfunction()}} if applicable to give detailed information about the C function being built.} +\item{cf_dir}{Directory where CFunc objects should be saved. Specifying +'cf_dir' without specifying a 'name' for the object is an error.} + \item{x}{An \code{\link{mkinmod}} object.} \item{submodel}{Character vector of length one to specify the submodel type. @@ -113,7 +120,6 @@ For kinetic models with more than one observed variable, a symbolic solution of the system of differential equations is included in the resulting mkinmod object in some cases, speeding up the solution. -If a C compiler is found by \code{\link[pkgbuild:has_compiler]{pkgbuild::has_compiler()}} and there is more than one observed variable in the specification, C code is generated for evaluating the differential equations, compiled using \code{\link[inline:cfunction]{inline::cfunction()}} and added to the resulting mkinmod object. @@ -132,17 +138,17 @@ SFO <- mkinmod(parent = mkinsub("SFO")) SFO_SFO <- mkinmod( parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO")) +print(SFO_SFO) \dontrun{ -# Now supplying full names used for plotting + fit_sfo_sfo <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE, solution_type = "deSolve") + + # Now supplying full names used for plotting, and write to user defined location SFO_SFO.2 <- mkinmod( parent = mkinsub("SFO", "m1", full_name = "Test compound"), - m1 = mkinsub("SFO", full_name = "Metabolite M1")) - -# The above model used to be specified like this, before the advent of mkinsub() -SFO_SFO <- mkinmod( - parent = list(type = "SFO", to = "m1"), - m1 = list(type = "SFO")) + m1 = mkinsub("SFO", full_name = "Metabolite M1"), + name = "SFOSFO", cf_dir = tempdir()) +fit_sfo_sfo <- mkinfit(SFO_SFO.2, FOCUS_2006_D, quiet = TRUE, solution_type = "deSolve") # Show details of creating the C function SFO_SFO <- mkinmod( @@ -166,13 +172,6 @@ fit_DFOP_par_c <- mkinfit(m_synth_DFOP_par, quiet = TRUE) } - - m_synth_SFO_lin <- mkinmod(parent = list(type = "SFO", to = "M1"), - M1 = list(type = "SFO", to = "M2"), - M2 = list(type = "SFO"), use_of_ff = "max") - - print(m_synth_SFO_lin) - } \references{ FOCUS (2006) \dQuote{Guidance Document on Estimating Persistence -- cgit v1.2.1 From 1e3fd1bef2a0ec1c8b73fcfefdd62fd3463bc87c Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 27 Nov 2020 18:35:56 +0100 Subject: Improved way to have persistent DLLs for mkinmod Depends on inline >= 0.16.2 (including the bug fixes from eddelbuettel/inline#18), which provides 'moveDLL' to store the DLL for a compiled function in a safe place in case the argument 'dll_dir' is specified in the call to 'mkinmod'. Huge thanks to Dirk @eddelbuettel for his review and support for the work on the inline package. --- man/mkinmod.Rd | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'man/mkinmod.Rd') diff --git a/man/mkinmod.Rd b/man/mkinmod.Rd index f71ebfb3..77319aac 100644 --- a/man/mkinmod.Rd +++ b/man/mkinmod.Rd @@ -13,7 +13,9 @@ mkinmod( speclist = NULL, quiet = FALSE, verbose = FALSE, - cf_dir = NULL + dll_dir = NULL, + unload = FALSE, + overwrite = FALSE ) \method{print}{mkinmod}(x, ...) @@ -53,8 +55,16 @@ argument. Default is NULL.} \item{verbose}{If \code{TRUE}, passed to \code{\link[inline:cfunction]{inline::cfunction()}} if applicable to give detailed information about the C function being built.} -\item{cf_dir}{Directory where CFunc objects should be saved. Specifying -'cf_dir' without specifying a 'name' for the object is an error.} +\item{dll_dir}{Directory where an DLL object, if generated internally by +\code{\link[inline:cfunction]{inline::cfunction()}}, should be saved. The DLL will only be stored in a +permanent location for use in future sessions, if 'dll_dir' and 'name' +are specified.} + +\item{unload}{If a DLL from the target location in 'dll_dir' is already +loaded, should that be unloaded first?} + +\item{overwrite}{If a file exists at the target DLL location in 'dll_dir', +should this be overwritten?} \item{x}{An \code{\link{mkinmod}} object.} @@ -120,6 +130,7 @@ For kinetic models with more than one observed variable, a symbolic solution of the system of differential equations is included in the resulting mkinmod object in some cases, speeding up the solution. +If a C compiler is found by \code{\link[pkgbuild:has_compiler]{pkgbuild::has_compiler()}} and there is more than one observed variable in the specification, C code is generated for evaluating the differential equations, compiled using \code{\link[inline:cfunction]{inline::cfunction()}} and added to the resulting mkinmod object. @@ -143,12 +154,16 @@ print(SFO_SFO) \dontrun{ fit_sfo_sfo <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE, solution_type = "deSolve") - # Now supplying full names used for plotting, and write to user defined location + # Now supplying compound names used for plotting, and write to user defined location SFO_SFO.2 <- mkinmod( parent = mkinsub("SFO", "m1", full_name = "Test compound"), m1 = mkinsub("SFO", full_name = "Metabolite M1"), - name = "SFOSFO", cf_dir = tempdir()) -fit_sfo_sfo <- mkinfit(SFO_SFO.2, FOCUS_2006_D, quiet = TRUE, solution_type = "deSolve") + name = "SFO_SFO", dll_dir = "~/dll", unload = TRUE, overwrite = TRUE) +# Now we can save the model and restore it in a new session +saveRDS(SFO_SFO.2, file = "~/SFO_SFO.rds") +# Terminate the R session here if you would like to check, and then do +SFO_SFO.3 <- readRDS("~/SFO_SFO.rds") +fit_sfo_sfo <- mkinfit(SFO_SFO.3, FOCUS_2006_D, quiet = TRUE, solution_type = "deSolve") # Show details of creating the C function SFO_SFO <- mkinmod( -- cgit v1.2.1