Working with submodels : Plug-and-play modularity

Plug-and-play modularity using submodels

"Plug-and-play" modularity means the ability to replace one module in a model with another, without having to specify how the module's inputs and outputs link up with the rest of the model. This requires that the modules to be swapped share the same interface to the rest of the model.

In Simile, a module is a submodel. There is a mechanism for replacing one submodel with another: simply open a separate window for the submodel, and use the File: Open command to load a new submodel. However, this by itself does not automatically remake all the links between variables in the submodel and those in the rest of the model.

In order to have plug-and-play modularity, we need to specify the interface between a submodel and the rest of the model. This means stating which variable in the submodel is linked to which variable in the main model, and the nature (dimensions, units) of the two variables. This specification is saved in a separate interface specification file, and can be loaded when we create a new submodel, in order to re-make all the linkages.

Demonstration of plug-and-play modularity

  • Step 1: Build a model with submodels
  • Step 2: Save one of the submodels as a separate model
  • Step 3: Save the interface specification
  • Step 4: Clear the submodel
  • Step 5: Load an alternative version of the submodel
  • Step 6: Load the interface specification file

In: Contents >> Working with submodels

Working with submodels : Plug-and-play modularity : Step 1



Step 1: Build a model with submodels

Next Step >>

In this simple example, we make a model of the interaction between plant
growth and soil water. We use a submodel for each component. Note that
at this stage we do not actually need to use submodels: they merely serve
to show the main functional components of this model.

Next Step >>

In: Contents >> Working with submodels >> Plug-and-play modularity

Working with submodels : Plug-and-play modularity : Step 2

Step 2: Save the submodel as a separate Simile model

Next Step >>

We first open up a separate window for the soil submodel by double-clicking on its boundary.

We now select the "Save as..." command from the submodel window's File menu (not the menu for the main model window).

Next Step >>

In: Contents >> Working with submodels >> Plug-and-play modularity

Working with submodels : Plug-and-play modularity : Step 3



Step 3: Save the interface specification


Next Step >>

We save the interface specification for the interface between the soil
water submodel and the rest of the model, using the "Save Interface"
command from the "Model" menu of the submodel window.


Next Step >>

In: Contents >> Working with submodels >> Plug-and-play modularity

Working with submodels : Plug-and-play modularity : Step 4



Step 4: Clear the submodel


Next Step >>

We clear the submodel, by selecting File: New from the submodel window's
menu.


Next Step >>

In: Contents >> Working with submodels >> Plug-and-play modularity

Working with submodels : Plug-and-play modularity : Step 5

Step 5: Load an alternative version of the submodel

<< Previous Step Next Step >>

We now load an alternative version of the submodel.

This new submodel also has a variable called "Soil water" (though in this case it is a Simile variable, not a compartment), and a flow called "transpiration". Note also that this submodel is structurally different from the first submodel: all that matters for plug-and-playability is that the two models have the same interfacing variables: the rest of their structure is irrelevant.

At this stage, the linkages are not re-made. The Soil submodel contains an unsatisfied input parameter "Plant biomass", while the main model contains an unsatisfied input parameter called "Soil water". These undefined elements are shown in red.

Next Step >>

In: Contents >> Working with submodels >> Plug-and-play modularity

Working with submodels : Plug-and-play modularity : Step 6



Step 6: Load the interface specification file

We select an interface specification file using the "Load interface"
command from the "Model" menu of the submodel window (again, not the main
model window).

Now, Simile automatically re-makes the linkages between the submodel and
the rest of the model.

Finally, we can close the submodel window, since it is not required any
more. We now have the new model!

In: Contents >> Working with submodels >> Plug-and-play modularity