Templates and Instances for Large Models
1. What are Templates and Instances?
We often find physiological structures repeating a similar component, or consisting of many similar components, such as muscle tissue as an aggregate of many muscle cells and a neural network consisting of many similar neurons. To model such physiological systems, there should be a way to systematically deal with this repetition.
On PhysioDesigner, a template and instance framework can be helpful for such a situation. Once a template model is defined, it is possible to create multiple instances according to the template. Instances are not "copies" of the template. All properties of instances are inherited from the template, but each instance itself does not have concrete definitions of states and parameters. Hence, once a template property is changed, the change is immediately applied to all instances. It is not necessary to go through all instances to make similar changes on each of them. For example, let’s assume that there is a template of a regular-spiking neuron model, and one hundred instances forming a neural network. So this is a neural network model of regular-spiking neurons. If certain parameters are changed on the template so that the template behaves as a fast-spiking neuron, then the neural network composed of the instances now represents the network of fast-spiking neurons.
Naturally, there are times when we would like to give particular characteristics to several specific instances among many instances. In such a case, it is possible to modify the values of static-parameter type physical quantities and the initial values of state type physical quantities in individual instances. However, it is forbidden to modify, for example, equations of state type physical quantities, because if the definition of the dynamics of an instance is different from the template, the instance can no longer be considered as an "instance" of the template.
2. Create a template
First, it’s necessary to create a model composed of several modules, and it must be encapsulated. At the context menu that appears by right-clicking on the top capsule module, select "Template." A checkmark appears at the left side of the menu.
On the canvas, the label "Template" in the nesting diagram and "T" in the tree diagram appears on the modules. The "Template" and "T" labels are put on all modules below the capsule module.
The template appears on the Template List at the left side of the Canvas.
In the context menu that appears by right-clicking on the template module, the "Make instance modules" command is now clickable.
3. Create instances
To create instances, select "Make Instance Modules" in the context menu. A small window pops up.
Input the number of instances, and click the “OK” button. The instances are created and displayed on the canvas with a smaller symbol than the usual modules.
At first, all instances are displayed with one symbol in a collapsed style. A number in the symbol represents the number of instances. To expand it and show each of them, select "Expand" in the context menu.
The first time that the instance (collapsed) is expanded, the symbol changes as shown below. All instances are displayed overlapping each other.
Select "Sort" modules in the context menu that appears by right-clicking on the white background of the canvas,
All modules and instances are scattered as shown below.
You can remove instances with the usual procedure. .
Note that the instances are created under a parent module of the template. For example, if the template is a child of Module A, all instances are created under Module A.
4. Properties of template and instances
Functional edges between the template and other modules are considered to also exist between every instance and the module. For example, let’s span a functional edge from the template to a module, "Module A".
The functional edges from all instances to Module A are drawn on the canvas.
This is the same for functional edges with a different direction (coming into an out-port of the template from other modules).
When reverting the template to a normal functional-unit, and if there are instances of the template, all instances will be removed. A dialog pops up to ask if this is OK or not.
5. Edit instance
The names of instances are the same as the name of the template. However, it would be convenient to be able to distinguish one instance from the other. So for this purpose, a label can be set to each instance.
It is also possible to give each instance a certain degree of individuality. Values of static-parameter type physical quantities and initial value of state type physical quantities can be changed.
To do this, select "Edit Instance Module" in the context menu.
The following dialog pops up.
In the dialog, it is possible to edit the label of an instance, the values of static-parameters and the initial values of state type physical quantities. To edit values, double-click on the value column and the cell becomes an editable text box.
6. Semi-automatic creation of edges among instances
In a case where there are not many instances, it is possible to link edges among instances by manual operation. However, if there are a lot of instances such as 100, 1000 and more, it is practically impossible to do this. PhysioDesigner provides a way to semiautomatically link edges among instances.
One way is to create edges from a set of instances of a template to another set of instances of another template. It is necessary to define the number of instances from which edges start, and the number of instances to which one instance projects edges. Edge details (which in-port and out-port should be used) also need to be defined.
As an example, let’s assume that we have the following model.
There are two container modules named "Layer 1" and "Layer 2", including templates "MAT_RegularSpiking" and "HH_RegularSpiking", respectively. Each one includes 20 instances of each template. Configuration for the semiautomatic linking is set in a dialog opened by the menu "Tool > Auto-link among Many Instances".
The menu opens the following dialog.
In this dialog, one template must be selected at the origin side (origin of edges) and another template at the target side (target of edges). Then it is necessary to provide the number of instances from which edges start and the number of instances to which one instance projects edges. It is possible to define multiple edges to span between two instances.
For example, let’s assume that "10" is set for the number of instances at the origin side, and 5 for the target side.
10 instances among 20 are randomly selected at the origin side, and 5 instances at the target side are randomly selected for each of the 10 instances at the out-port side. The edges are created as follows.
The 10 instances that were selected randomly at the origin side project 5 edges. At the target side, the number of edges to receive is decided by chance for each instance. Since "Allow overlapping" was ticked in the configuration, some instances on the target side receive multiple edges.
If we use all 20 instances at the origin side and each of them projects only one edge to an instance at the target side,
instances in two sets are linked in a one-to-one manner. Notice that this time, "Allow overlapping" is unticked.
Similarly, it is also possible to link edges among the instances of a single template. Let’s consider an example model that includes only the instances of one template.
In the configuration for automatic linking, we will use all 20 instances as the origin of edges. Each of the instances projects three edges.
In this case, all instances project edges to three other randomly selected instances within the same set.