DifferentiableStateSpaceModels
Documentation for DifferentiableStateSpaceModels.
DifferentiableStateSpaceModels.ThreadLocalCache
DifferentiableStateSpaceModels.allocate_cache
DifferentiableStateSpaceModels.generate_perturbation
DifferentiableStateSpaceModels.get_threadsafe_cache
DifferentiableStateSpaceModels.@include_example_module
DifferentiableStateSpaceModels.ThreadLocalCache
— MethodThread-local caches, automatically generating new caches when required.
ThreadLocalCache(cache)
Examples
julia> caches = ThreadLocalCache(rand(5))
julia> caches() # get a local cache for the thread
DifferentiableStateSpaceModels.allocate_cache
— MethodHelper to allocate threadsafe cache objects consistent with any AbstractPerturbationModel
for use with generate_perturbation
.
Initializes with a cache for the current thread.
allocate_cache(m)
Examples
julia> cache = allocate_cache(m);
julia> sol = generate_perturbation(m; cache) # cache can be used in different threads
DifferentiableStateSpaceModels.generate_perturbation
— MethodSolve a model, optionally reusing a threadsafe cache.
generate_perturbation(m, p; p_f, cache, settings)
Details
Returns the solution
DifferentiableStateSpaceModels.get_threadsafe_cache
— FunctionGet a threadsafe cache instance, and determine if the current p
and p_f
match it.
NOTE: in the future there could be memoization of multiple caches, but right now there is one per thread.
get_threadsafe_cache(cache, m, p, p_f)
get_threadsafe_cache(cache, m, p, p_f, settings)
Examples
julia> cache = allocate_cache(m);
julia> c, hash_match_all, hash_match_ss, hash_match_perturbation = get_threadsafe_cache(cache, m, p, p_f)
DifferentiableStateSpaceModels.@include_example_module
— MacroReturn model from a stored module, creating as necessary . If the module is
- already included, it just returns the
Module
- saved to disk but not already included, it does
include
- not saved to disk, it saves it, includes it
The specification of a model_generator
has a sepcification like H, mod_vals = model_generator()
where H
is an MTK expression the mod_vals
can be splatted into the FirstOrderPerturbationModel
or SecondOrderPerturbationModel
constructor.
The name of the stored module
is the name of model_generator
function and the order.
Examples
julia> m = @include_example_module(Examples.rbc_observables_benchmark) # stores or loads `.function_cache/rbc_observables_1.jl`
julia> m = @include_example_module(Examples.rbc_observables_benchmark, 2) # second order, loads `.function_cache/rbc_observables_2.jl`