Reference
Mimi.@defcomp — Macro.defcomp(comp_name::Symbol, ex::Expr)Define a Mimi component comp_name with the expressions in ex. The following types of expressions are supported:
dimension_name = Index()# defines a dimensionparameter = Parameter(index = [dimension_name], units = "unit_name", default = default_value)# defines a parameter with optional argumentsvariable = Variable(index = [dimension_name], units = "unit_name")# defines a variable with optional argumentsinit(p, v, d)# defines an init function for the componentrun_timestep(p, v, d, t)# defines a run_timestep function for the component
Parses a @defcomp definition, converting it into a series of function calls that create the corresponding ComponentDef instance. At model build time, the ModelDef (including its ComponentDefs) will be converted to a runnable model.
Mimi.MarginalModel — Type.MarginalModelA Mimi Model whose results are obtained by subtracting results of one base Model from those of another marginal Modelthat has a difference ofdelta`.
Mimi.Model — Type.ModelA user-facing API containing a ModelInstance (mi) and a ModelDef (md). This Model can be created with the optional keyword argument number_type indicating the default type of number used for the ModelDef. If not specified the Model assumes a number_type of Float64.
Mimi.add_comp! — Function.add_comp!(md::ModelDef, comp_def::ComponentDef; first=nothing, last=nothing, before=nothing, after=nothing)Add the component indicated by comp_def to the model indcated by md. The component is added at the end of the list unless one of the keywords, first, last, before, after. If the comp_name differs from that in the comp_def, a copy of comp_def is made and assigned the new name.
add_comp!(md::ModelDef, comp_id::ComponentId; comp_name::Symbol=comp_id.comp_name,
first=nothing, last=nothing, before=nothing, after=nothing)Add the component indicated by comp_id to the model indicated by md. The component is added at the end of the list unless one of the keywords, first, last, before, after. If the comp_name differs from that in the comp_def, a copy of comp_def is made and assigned the new name.
add_comp!(mi::ModelInstance, ci::ComponentInstance)Add the component ci to the ModelInstance mi's list of components, and add the first and last of mi to the ends of the firsts and lasts lists of mi, respectively.
add_comp!(m::Model, comp_id::ComponentId; comp_name::Symbol=comp_id.comp_name;
first=nothing, last=nothing, before=nothing, after=nothing)Add the component indicated by comp_id to the model indicated by m. The component is added at the end of the list unless one of the keywords, first, last, before, after. If the comp_name differs from that in the comp_id, a copy of comp_id is made and assigned the new name.
Mimi.components — Function.components(mi::ModelInstance)Return an iterator on the components in model instance mi.
components(m::Model)Return an iterator on the components in model m.
Mimi.connect_param! — Function.connect_param!(md::ModelDef, comp_name::Symbol, param_name::Symbol, ext_param_name::Symbol)Connect a parameter param_name in the component comp_name of model md to the external parameter ext_param_name.
connect_param!(md::ModelDef, dst_comp_name::Symbol, dst_par_name::Symbol,
src_comp_name::Symbol, src_var_name::Symbol backup::Union{Nothing, Array}=nothing;
ignoreunits::Bool=false, offset::Int=0)Bind the parameter dst_par_name of one component dst_comp_name of model md to a variable src_var_name in another component src_comp_name of the same model using backup to provide default values and the ignoreunits flag to indicate the need to check match units between the two. The offset argument indicates the offset between the destination and the source ie. the value would be 1 if the destination component parameter should only be calculated for the second timestep and beyond.
connect_param!(md::ModelDef, dst::Pair{Symbol, Symbol}, src::Pair{Symbol, Symbol},
backup::Union{Nothing, Array}=nothing; ignoreunits::Bool=false, offset::Int=0)Bind the parameter dst[2] of one component dst[1] of model md to a variable src[2] in another component src[1] of the same model using backup to provide default values and the ignoreunits flag to indicate the need to check match units between the two. The offset argument indicates the offset between the destination and the source ie. the value would be 1 if the destination component parameter should only be calculated for the second timestep and beyond.
connect_param!(dst::ComponentReference, dst_name::Symbol, src::ComponentReference, src_name::Symbol)Connect two components as connect_param!(dst, dst_name, src, src_name).
connect_param!(dst::ComponentReference, src::ComponentReference, name::Symbol)Connect two components with the same name as connect_param!(dst, src, name).
connect_param!(m::Model, dst_comp_name::Symbol, dst_par_name::Symbol, src_comp_name::Symbol,
src_var_name::Symbol, backup::Union{Nothing, Array}=nothing; ignoreunits::Bool=false, offset::Int=0)Bind the parameter dst_par_name of one component dst_comp_name of model md to a variable src_var_name in another component src_comp_name of the same model using backup to provide default values and the ignoreunits flag to indicate the need to check match units between the two. The offset argument indicates the offset between the destination and the source ie. the value would be 1 if the destination component parameter should only be calculated for the second timestep and beyond.
connect_param!(m::Model, dst::Pair{Symbol, Symbol}, src::Pair{Symbol, Symbol}, backup::Array; ignoreunits::Bool=false)Bind the parameter dst[2] of one component dst[1] of model md to a variable src[2] in another component src[1] of the same model using backup to provide default values and the ignoreunits flag to indicate the need to check match units between the two. The offset argument indicates the offset between the destination and the source ie. the value would be 1 if the destination component parameter should only be calculated for the second timestep and beyond.
Mimi.create_marginal_model — Function.create_marginal_model(base::Model, delta::Float64=1.0)Create a MarginalModel where base is the baseline model and delta is the difference used to create the marginal model. Return the resulting MarginaModel which shares the internal ModelDef between the base and marginal.
Mimi.dim_count — Function.dim_count(md::ModelDef, name::Symbol)Return the size of index name in model definition md.
dim_count(mi::ModelInstance, dim_name::Symbol)Return the size of index dim_name in model instance mi.
dim_count(m::Model, dim_name::Symbol)Return the size of index dim_name in model m.
Mimi.dim_keys — Function.dim_keys(md::ModelDef, name::Symbol)Return keys for dimension name in model definition md.
dim_keys(mi::ModelInstance, dim_name::Symbol)Return keys for dimension dim_name in model instance mi.
dim_keys(m::Model, dim_name::Symbol)Return keys for dimension dim-name in model m.
Mimi.dim_key_dict — Function.dim_key_dict(md::ModelDef)Return a dict of dimension keys for all dimensions in model definition md.
dim_key_dict(mi::ModelInstance)Return a dict of dimension keys for all dimensions in model instance mi.
dim_key_dict(m::Model)Return a dict of dimension keys for all dimensions in model m.
Mimi.disconnect_param! — Function.disconnect_param!(md::ModelDef, comp_name::Symbol, param_name::Symbol)Remove any parameter connections for a given parameter param_name in a given component comp_name of model md.
disconnect_param!(m::Model, comp_name::Symbol, param_name::Symbol)Remove any parameter connections for a given parameter param_name in a given component comp_name of model m.
Mimi.explore — Function.explore(m::Model; title = "Electron")Produce a UI to explore the parameters and variables of Model m in a Window with title title.
explore(m::Model, comp_name::Symbol, datum_name::Symbol)Plot a specific datum_name (a variable or parameter) of Model m.
Mimi.generate_trials! — Function.generate_trials!(mcs::MonteCarloSimulation, trials::Int;
filename::String="", sampling::SamplingOptions=RANDOM)Generate the given number of trials for the given MonteCarloSimulation instance. Call this before running the MCS to pre-generate data to be used by all scenarios. Also enables saving of inputs or choosing a sampling method other than RANDOM. (Currently, only LHS and RANDOM are possible.)
Mimi.getdataframe — Function.getdataframe(m::Model, comp_name::Symbol, pairs::Pair{Symbol, Symbol}...)Return a DataFrame with values for the given variables or parameters of model m indicated by pairs, where each pair is of the form comp_name => item_name. If more than one pair is provided, all must refer to items with the same dimensions, which are used to join the respective item values.
getdataframe(m::Model, pair::Pair{Symbol, NTuple{N, Symbol}})Return a DataFrame with values for the given variables or parameters indicated by pairs, where each pair is of the form comp_name => item_name. If more than one pair is provided, all must refer to items with the same dimensions, which are used to join the respective item values.
getdataframe(m::Model, comp_name::Symbol, item_name::Symbol)Return the values for variable or parameter item_name in comp_name of model m as a DataFrame.
Mimi.gettime — Function.gettime(ts::FixedTimestep)Return the time (year) represented by Timestep ts
gettime(ts::VariableTimestep)Return the time (year) represented by Timestep ts
gettime(c::Clock)Return the current time of the timestep held by the c clock.
Mimi.get_param_value — Function.get_param_value(ci::ComponentInstance, name::Symbol)Return the value of parameter name in component ci.
Mimi.get_var_value — Function.get_var_value(ci::ComponentInstance, name::Symbol)Return the value of variable name in component ci.
Mimi.hasvalue — Function.hasvalue(arr::TimestepArray, ts::FixedTimestep)Return true or false, true if the TimestepArray arr contains the Timestep ts.
hasvalue(arr::TimestepArray, ts::VariableTimestep)Return true or false, true if the TimestepArray arr contains the Timestep ts.
hasvalue(arr::TimestepArray, ts::FixedTimestep, idxs::Int...)Return true or false, true if the TimestepArray arr contains the Timestep ts within indices idxs. Used when Array and Timestep have different FIRST, validating all dimensions.
hasvalue(arr::TimestepArray, ts::VariableTimestep, idxs::Int...)Return true or false, true if the TimestepArray arr contains the Timestep ts within indices idxs. Used when Array and Timestep different TIMES, validating all dimensions.
Mimi.is_first — Function.is_first(ts::AbstractTimestep)Return true or false, true if ts is the first timestep to be run.
Mimi.is_last — Function.is_last(ts::FixedTimestep)Return true or false, true if ts is the last timestep to be run.
is_last(ts::VariableTimestep)Return true or false, true if ts is the last timestep to be run. Note that you may run next_timestep on ts, as ths final timestep has not been run through yet.
Mimi.is_time — Function.is_time(ts::AbstractTimestep, t::Int)Return true or false, true if the current time (year) for ts is t
Mimi.is_timestep — Function.is_timestep(ts::AbstractTimestep, t::Int)Return true or false, true if ts timestep is step t.
Mimi.load_comps — Function.load_comps(dirname::String="./components")Call include() on all the files in the indicated directory dirname. This avoids having modelers create a long list of include() statements. Just put all the components in a directory.
Mimi.modeldef — Function.modeldef(mi)Return the ModelDef contained by ModelInstance mi.
modeldef(m)Return the ModelDef contained by Model m.
Mimi.name — Function.name(def::NamedDef) = def.nameReturn the name of def. Possible NamedDefs include DatumDef, and ComponentDef.
name(ci::ComponentInstance)Return the name of the component ci.
Mimi.new_comp — Function.new_comp(comp_id::ComponentId, verbose::Bool=true)Add an empty ComponentDef to the global component registry with the given comp_id. The empty ComponentDef must be populated with calls to addvariable, addparameter, etc.
Mimi.parameters — Function.parameters(comp_def::ComponentDef)Return a list of the parameter definitions for comp_def.
parameters(comp_id::ComponentDef)Return a list of the parameter definitions for comp_id.
parameters(mi::ModelInstance, comp_name::Symbol)Return the ComponentInstanceParameters for comp_name in ModelInstance 'mi'.
parameters(ci::ComponentInstance)Return an iterable over the parameters in ci.
parameters(m::Model, comp_name::Symbol)Return a list of the parameter definitions for comp_name in model m.
Mimi.plot_comp_graph — Function.plot_comp_graph(m::Model, filename::Union{Nothing, Symbol} = nothing)Plot the DAG of component connections within model m and save to filename. If no filename is given, plot will simply display.
Mimi.replace_comp! — Function.replace_comp!(md::ModelDef, comp_id::ComponentId, comp_name::Symbol=comp_id.comp_name;
first::NothingInt=nothing, last::NothingInt=nothing,
before::NothingSymbol=nothing, after::NothingSymbol=nothing,
reconnect::Bool=true)Replace the component with name comp_name in model definition md with the component comp_id using the same name. The component is added in the same position as the old component, unless one of the keywords before or after is specified. The component is added with the same first and last values, unless the keywords first or last are specified. Optional boolean argument reconnect with default value true indicates whether the existing parameter connections should be maintained in the new component.
replace_comp!(m::Model, comp_id::ComponentId, comp_name::Symbol=comp_id.comp_name;
first::NothingSymbol=nothing, last::NothingSymbol=nothing,
before::NothingSymbol=nothing, after::NothingSymbol=nothing,
reconnect::Bool=true)Replace the component with name comp_name in model m with the component comp_id using the same name. The component is added in the same position as the old component, unless one of the keywords before or after is specified. The component is added with the same first and last values, unless the keywords first or last are specified. Optional boolean argument reconnect with default value true indicates whether the existing parameter connections should be maintained in the new component.
Mimi.run_mcs — Function.run_mcs(mcs::MonteCarloSimulation,
trials::Union{Int, Vector{Int}, AbstractRange{Int}},
models_to_run::Int=length(mcs.models);
ntimesteps::Int=typemax(Int),
output_dir::Union{Nothing, AbstractString}=nothing,
pre_trial_func::Union{Nothing, Function}=nothing,
post_trial_func::Union{Nothing, Function}=nothing,
scenario_func::Union{Nothing, Function}=nothing,
scenario_placement::ScenarioLoopPlacement=OUTER,
scenario_args=nothing)Run the indicated the first trials, which indicates the number of trials to run starting from the first one. The first models_to_run associated models are run for ntimesteps, if specified, else to the maximum defined time period. Note that trial data are applied to all the associated models even when running only a portion of them.
If pre_trial_func or post_trial_func are defined, the designated functions are called just before or after (respectively) running a trial. The functions must have the signature:
fn(mcs::MonteCarloSimulation, trialnum::Int, ntimesteps::Int, tup::Tuple)where tup is a tuple of scenario arguments representing one element in the cross-product of all scenario value vectors. In situations in which you want the MCS loop to run only some of the models, the remainder of the runs can be handled using a pre_trial_func or post_trial_func.
If provided, scenario_args must be a Vector{Pair}, where each Pair is a symbol and a Vector of arbitrary values that will be meaningful to scenario_func, which must have the signature:
scenario_func(mcs::MonteCarloSimulation, tup::Tuple)By default, the scenario loop encloses the Monte Carlo loop, but the scenario loop can be placed inside the Monte Carlo loop by specifying scenario_placement=INNER. When INNER is specified, the scenario_func is called after any pre_trial_func but before the model is run.
Mimi.set_dimension! — Function.set_dimension!(md::ModelDef, name::Symbol, keys::Union{Int, Vector, Tuple, Range})Set the values of md dimension name to integers 1 through count, if keys is an integer; or to the values in the vector or range if keys is either of those types.
set_dimension!(m::Model, name::Symbol, keys::Union{Vector, Tuple, AbstractRange})Set the values of m dimension name to integers 1 through count, if keysis an integer; or to the values in the vector or range ifkeys`` is either of those types.
Mimi.set_leftover_params! — Function.set_leftover_params!(m::Model, parameters::Dict)Set all of the parameters in model m that don't have a value and are not connected to some other component to a value from a dictionary parameters. This method assumes the dictionary keys are strings that match the names of unset parameters in the model.
Mimi.set_models! — Function.set_models!(mcs::MonteCarloSimulation, m:Model)Set the model m to be used by the mcs MonteCarloSimulation.
set_models!(mcs::MonteCarloSimulation, mm::MarginalModel)Set the models to be used by the mcs MonteCarloSimulation to be mm.base and mm.marginal which make up the MarginalModel mm.
Mimi.set_param! — Function.set_param!(m::ModelDef, comp_name::Symbol, name::Symbol, value, dims=nothing)Set the parameter name of a component comp_name in a model m to a given value. The value can by a scalar, an array, or a NamedAray. Optional argument 'dims' is a list of the dimension names ofthe provided data, and will be used to check that they match the model's index labels.
set_param!(ref::ComponentReference, name::Symbol, value)Set a component parameter as set_param!(reference, name, value).
set_param!(m::Model, comp_name::Symbol, name::Symbol, value, dims=nothing)Set the parameter of a component comp_name in a model m to a given value. The value can by a scalar, an array, or a NamedAray. Optional argument 'dims' is a list of the dimension names of the provided data, and will be used to check that they match the model's index labels.
Mimi.variables — Function.variables(mi::ModelInstance, comp_name::Symbol)Return the ComponentInstanceVariables for comp_name in ModelInstance 'mi'.
variables(m::Model, comp_name::Symbol)Return a list of the variable definitions for comp_name in model m.
Mimi.update_param! — Function.update_param!(md::ModelDef, name::Symbol, value; update_timesteps = false)Update the value of an external model parameter in ModelDef md, referenced by name. Optional boolean argument update_timesteps with default value false indicates whether to update the time keys associated with the parameter values to match the model's time index.
update_param!(m::Model, name::Symbol, value; update_timesteps = false)Update the value of an external model parameter in model m, referenced by name. Optional boolean argument update_timesteps with default value false indicates whether to update the time keys associated with the parameter values to match the model's time index.
Mimi.update_params! — Function.update_params!(md::ModelDef, parameters::Dict{T, Any}; update_timesteps = false) where TFor each (k, v) in the provided parameters dictionary, update_param! is called to update the external parameter by name k to value v, with optional Boolean argument update_timesteps. Each key k must be a symbol or convert to a symbol matching the name of an external parameter that already exists in the model definition.
update_params!(m::Model, parameters::Dict{T, Any}; update_timesteps = false) where TFor each (k, v) in the provided parameters dictionary, update_param!` is called to update the external parameter by name k to value v, with optional Boolean argument update_timesteps. Each key k must be a symbol or convert to a symbol matching the name of an external parameter that already exists in the model definition.