Difference between revisions of "Numerus Simulation Architecture"

From Numerus
Jump to navigation Jump to search
Line 1: Line 1:
Numerus supports a multi-level architecture comprised of '''Simulators'''. The lowest level atomic simulator is called a '''Capsule''', and it is composed of simulation '''components''' (Stocks, Flows, etc.). '''Containers''' are component simulators that contain Capsule instances as elements.
Numerus supports a multi-level architecture comprised of '''Simulators'''. The lowest level atomic simulator is called a '''Capsule''', and it is composed of simulation '''components''' (Stocks, Flows, etc.). '''Containers''' are component simulators that contain Capsule instances as elements.


A Numerus model is called a '''project'''. At a minimum a project contains a top-level Capsule instance called '''main'''. The ''main'' Capsule will contain components, some of which may be Containers. Each Container contains 1 or more instances of some Capsule<ref>or Agent, Cell, or Node, which are extended versions of the Capsule for use with specific Containers</ref>. The contents of such a Capsule may contain its own Containers, and so we obtain a hierarchical structure, as described [[Modeling_in_Numerus#capsule|here]].  
A Numerus model is called a '''project'''. At a minimum a project contains a top-level Capsule instance called '''main'''. The ''main'' Capsule will contain components, some of which may be Containers. Each Container contains 1 or more instances of some Capsule<ref>or Agent, Cell, or Node, which are extended versions of the Capsule for use with specific Containers</ref>. Such a Capsule may include its own Containers among its components, and so we obtain a hierarchical structure, as described [[Modeling_in_Numerus#capsule|here]].  


==Simulators and Aggregators==
==Simulators and Aggregators==

Revision as of 18:36, 9 June 2018

Numerus supports a multi-level architecture comprised of Simulators. The lowest level atomic simulator is called a Capsule, and it is composed of simulation components (Stocks, Flows, etc.). Containers are component simulators that contain Capsule instances as elements.

A Numerus model is called a project. At a minimum a project contains a top-level Capsule instance called main. The main Capsule will contain components, some of which may be Containers. Each Container contains 1 or more instances of some Capsule[1]. Such a Capsule may include its own Containers among its components, and so we obtain a hierarchical structure, as described here.

Simulators and Aggregators

The simplest Container is the Chip, which wraps a Capsule for insertion as a component in a parent Capsule. Other containers are called aggregators since they bind together multiple Capsule elements in a specific topology. Currently there are 5 aggregators: CellMatrix, AgentVector, SimWorld, NodeNetwork and NetWorld. Each of these is described in detail elsewhere. The Capsule types used in each aggregator is an extension to the fundamental Capsule type which complements the topology introduced by that aggregator. For example, the contents of a CellMatrix are of a Cell type which is a Capsule that is aware of its row/column location.

Components and Scope

Every value-producing component (Stock, Term, Flow, etc.) is part of the architecture in two ways. First there is the component object itself which holds the machinery for producing its value, and then there is the value itself. So if a particular component pop is part of some Capsule, we might refer to pop either to obtain its current value (such references are almost always used in the equations defining the model); or we might need to obtain a reference to the component object to, say, look up an old value or access some parameter[2]. While the latter is uncommon, such situations occasionally arise.

Consequently, the unadorned reference pop is ambiguous: do we mean the object or the value? In order to make this precise we introduce the concept of scope. Each simulator (Capsule, AgemtVector, CellMatrix, etc.) has a scope object which is contained in its scope property. The scope is property list[3] mapping the names of all components in the Simulator to its current value. The scope also contains references to primitive operators (primops) and properties germane to that Simulator.

The scope also contains a special property, _cap_[4]. Thus if Y is the scope object for Simulator X, then Y._cap_ will produce X. Thus we have a way of going from Simulator to scope (using the "scope" property) and from scope to Simulator (using the "_cap_" property). This provides a means for retrieving either the component object or its value from any component in a Capsule.

Example: Assume Capsule C contains components a, b and c, with current values 10, 20 and 30, respectively. Let CS be the scope of C. Then

 C.scope == CS
 CS._cap_ == C
 CS.a == 10
 CS.b == 20
 CS.c == 30
 C.a == a
 C.b == b
 C.c == c
 CS._cap_.a == a
 CS._cap_.a.value() == 10

etc.

Scope and Formulas

The "connective tissue" that links the components in model is comprised of algebraic formulas or program code that computes the value of a component using the values of other components. A reference to a component in such a formula should represent its scope value rather than its component value. Thus we have the following rule:

Every equation, formula or algorithm used to compute the value of a component does so with respect to the scope of the Capsule instance containing that component.

So, for example, if we evaluate the formula 3*a+4 in the previous example, the result will be 34, since the value of a is obtained using the scope CS.

Scope and the Console

When Numerus is launched an interactive Javascript console is provided to facilitate interactions with the simulation. This console uses the scope of the main Capsule for evaluating expressions. Thus, if 3*a+4 is typed into console when the Capsule C is main, the result will again be 34.

Computing with Simulators

Much of the power of Numerus comes from its extended programming landscape. Numerus formulas may be extended algorithms that reference objects from various parts of the model. For example, using a Numerus primitive operator, a Cell in a CellMatrix may obtain a list of its neighbors; i.e. all other Cells that are within a given distance from that Cell. However, to be most useful this is not a list of the Cell objects, but rather a list of their scopes. This way the values of components in these neighbors can be readily accessed.[5]. This makes for a more natural programming style since component values are generally of greatest interest.

The descriptions of those primops that collect sets of Simulators are careful to point out that it is actually the scope objects of those Simulators that are being collected.

Notes

  1. or Agent, Cell, or Node, which are extended versions of the Capsule for use with specific Containers
  2. Given a component object c, its current value is obtained using c.value()
  3. A property list associates property names, which are strings, with values. For example, if P is a property list containing values for properties a, b, and c, then the notation P.a, P.b, and P.c is used to extract the property values from the list. Alternatively we could use P["a"], P["b"] and P["c"].
  4. in Nova 2 this was called Self
  5. Of course, the component object can be retrieved if needed using the _cap_ property