π§βπ«Using Model Parameters
Understanding how to define and use model parameters
Last updated
Understanding how to define and use model parameters
Last updated
Custom named parameters can be defined at the level of an entire model. Those can be used in blocks by referring to them by name rather than using literals (like 21.0
) when defining the value of a block parameter.
Model parameters should not be confused with simulation configuration parameters as documented in Using Simulation Configuration Settings
In the right pane of the model editor, you can find the βModel parametersβ section. This section is only visible when no block is selected.
Each parameter must have a name that is a valid Python identifier. In short, this means some_value
is accepted but A name
will be rejected because of the space. Two parameters may not have the same name.
The value of a parameter will be evaluated following Python syntax. It is possible to use simple expressions in the value fields. The packages math
and np
(numpy) are preloaded in the environment where parameters are evaluated.
Model parameters can be added via the +
button and removed via -
.
Model parameters can not depend from each other and the order in which they will be evaluated is undefined. Please refer to the below section on Initialization script
for an alternative.
Once defined at the model level, parameters can be referred to in the block parameter inputs fields.
It is not possible to use expressions in block parameter input fields.
See also Using Submodels. Submodels may define their own set of parameters that follow the same syntactic rules as model parameters.
The default value of a model parameter can be defined in the model editor, but it is often useful to run parameter sweeps over a model in order to find the optimal values for a given system. Parameters defined in the model editor can be overridden when running simulations from the notebook. This will not change the default values specified in the model editor.
For more information on how to run parameter sweeps from python, please refer to Using Python Notebooks.
As an alternative to the list of model parameters in the model editor, it is possible to write an initialization script in Python that computes various parameters and makes them available to the model compiler. This allows pre-computing various parameters with values that depend on each other and in a well defined order. To use an initialization script:
write a standalone Python script file using your favorite code editor
upload the file to the collimator project as a data file, its extension must be .py
select the file in the model settings under "Initialization script"
all the local and global variables defined in the script will be available from the block parameter input fields