Compile an odin model, yielding a dust_system_generator object.
Usage
odin(
expr,
...,
input_type = NULL,
quiet = NULL,
workdir = NULL,
debug = NULL,
skip_cache = FALSE,
compatibility = NULL,
check_bounds = NULL,
target = NULL
)Arguments
- expr
Odin code as the path to a file (a string), a character vector of code, or as an expression (typically within braces
{}).- ...
Unused, must be empty. This allows us to add and reorder remaining arguments at will, as all arguments must be specified by name, not position).
- input_type
An optional string describing the type of input for
expr- must be one offile,textorexpression. If given, this skips the type detection logic and odin will throw an error if the wrong type of input is given. Using this may be beneficial in programmatic environments.- quiet
Logical, indicating if compilation messages from
pkgbuildshould be displayed. Error messages will be displayed on compilation failure regardless of the value used. IfNULLis given, then we take the value fromDUST_QUIETif set, orFALSEotherwise.- workdir
Optional working directory to use. If
NULL, the behaviour depends on the existence of the environment variableDUST_WORKDIR_ROOT. If it is unset we use a session-specific temporary directory (generated bytempfile()). IfDUST_WORKDIR_ROOTis set, then we use a stable generated filename within this directory, which allows different sessions to effectively share a cache. If you pass a directory name here as a string, then we will use that directory to write all code, which allows you to inspect the generated code. Seevignette("details")for more information.- debug
Passed to pkgbuild::compile_dll, this will build a debug library. If
NULLis given, then we take the value fromDUST_DEBUGif set, orFALSEotherwise.- skip_cache
Logical, indicating if the cache of previously compiled systems should be skipped. If
TRUEthen your system will not be looked for in the cache, nor will it be added to the cache after compilation.- compatibility
Compatibility mode to use. Valid options are "warning", which updates code that can be fixed, with warnings, and "error", which will error. The option "silent" will silently rewrite code, but this is not recommended for general use as eventually the compatibility mode will be removed (this option is primarily intended for comparing output of odin1 and odin2 models against old code). The default,
NULL, currently corresponds towarning.- check_bounds
Control over static array bounds checking. This is enabled by default, but is prone to false positives, erroring where a read or write appears out of bounds but is actually ok. This argument exists to allow you to disable the check and compile the model anyway. Future versions may allow specific lines to be ignored, which will provide finer control and allow you to use the bits of the checks that are actually helpful. You can also pass
TRUEhere to mean "error" orFALSEto mean "disabled".- target
Compilation target. If provided, it must be one of
cpporjs. In future, we hope to supportcudato enable support compilation to run on NVIDIA GPUs. The default,NULL, falls back on the optionodin2.target, and if that is unset we currently selectcpp, but this is subject to change once the JavaScript support is complete.
Value
A dust_system_generator object, suitable for using with
dust functions (starting from dust2::dust_system_create)
Examples
if (FALSE) { # interactive()
# A random walk:
gen <- odin({
initial(x) <- 0
update(x) <- Normal(x, 1)
})
sys <- dust2::dust_system_create(gen, list(), n_particles = 10)
y <- dust2::dust_system_simulate(sys, 0:100)
matplot(t(y[1, , ]), type = "l", lty = 1, xlab = "Time", ylab = "Value")
}
