|
1 | 1 | # Compartments |
2 | 2 |
|
3 | | -Inside ngcsimlib there is the global state as the backbone of any given model. |
4 | | -This global state is the culmination of all the dynamic or changing parts of the |
5 | | -model. Each value that builds this state is stored in a special container that |
6 | | -helps track these changes known as a Compartment. |
| 3 | +Within ngcsimlib, the global state serves as the backbone of any given model. |
| 4 | +This global state is essentially the culmination of all of the dynamic or changing parts of the model itself. Each |
| 5 | +value that builds this state is stored within a special "container" that helps track these changes over time -- this |
| 6 | +is referred to as a "compartment" (`Compartment`). |
7 | 7 |
|
8 | 8 | ## Practical Information |
9 | 9 |
|
10 | | -Practically when working with compartments there are a few simple things to keep |
11 | | -in mind and the rest is all behind the scenes bookkeeping. The first piece to |
12 | | -keep in mind is that each compartment holds a value and thus setting a |
13 | | -compartment with `myCompartment = newValue` will not function as intended as |
14 | | -this will overwrite the python object that is the compartment with `newValue`. |
15 | | -Instead, make use of the `.set()` method to update the value stored inside a |
16 | | -compartment so `myCompartment = newValue` becomes `myCompartment.set(newValue)`. |
17 | | -The second piece of information is that to retrieve a value from the compartment |
18 | | -use `myCompartment.get()`. These methods to get and set data inside a |
19 | | -compartment are the two main pieces to remember. |
20 | | - |
21 | | -## Technical information |
22 | | - |
23 | | -The follow sections are devoted to more technical information regarding how a |
24 | | -compartment functions in the broader scope of ngcsimlib and how to leverage that |
25 | | -information. |
26 | | - |
27 | | -### How data is stored |
28 | | - |
29 | | -The data stored inside a compartment is not actually stored inside a |
30 | | -compartment. Instead, it is stored inside the global state and each compartment |
31 | | -just holds the path or `key`, in the global state to pull a specific piece of |
32 | | -information. As such it is technically possible to manipulate the value of a |
33 | | -compartment without actually touching the compartment object created in a |
34 | | -component. By default, compartments have safeguards to prevent this from happening |
35 | | -accidentally but directly addressing the compartment in the global state has no |
36 | | -such safeguards. |
37 | | - |
38 | | -### What is targeting |
39 | | - |
40 | | -As discussed in the model building section there is a concept of wiring together |
41 | | -different compartments of different components. These wires are created through |
42 | | -the concept of targeting. In esscence targeting is just updating the path stored |
43 | | -in a compartment with the path of a different compartment. This means that if |
44 | | -the targeted compartment goes to retireve the value stored in it, it will |
45 | | -actually retrieve the value for the a different compartment. When a compartment |
46 | | -is in this state where it is targeted at another compartment it is set to read |
47 | | -only meaning that it can not modify a different compartment. |
| 10 | +Practically, when working with compartments, there are a few simple things to keep in mind despite the fact that most |
| 11 | +of ngcsimlib's primary operation is behind-the-scenes bookkeeping. The two main points to note are: |
| 12 | +1. Each compartment holds a value and, thus, setting a compartment with `myCompartment = newValue` will not function as |
| 13 | + intended since this will overwrite the Python object, i.e., the compartment with `newValue`. Instead, it is |
| 14 | + important to make use of the `.set()` method to update the value stored inside a compartment so |
| 15 | + `myCompartment = newValue` becomes `myCompartment.set(newValue)`. |
| 16 | +2. In order to retrieve a value from a compartment, use `myCompartment.get()`. These methods of getting and setting |
| 17 | + data inside a compartment are important to use when both working with and designing a multi-compartment component |
| 18 | + (i.e., `Component`). |
| 19 | + |
| 20 | +## Technical Information |
| 21 | + |
| 22 | +The follow sections are devoted to explication of more technical information regarding how a compartment functions |
| 23 | +with in the broader scope of ngcsimlib and, furthermore, to explain how to leverage this information. |
| 24 | + |
| 25 | +### How Data is Stored (Within a Model Context) |
| 26 | + |
| 27 | +The data stored inside of a compartment is not actually physically stored within a compartment. Instead, it is stored |
| 28 | +inside of the global state and each compartment effectively holds the path or `key` to the right spot in the global |
| 29 | +state, allowing it to pull out a specific piece of information. As such, it is technically possible to manipulate the |
| 30 | +value of a compartment without actually touching the compartment object itself within any given component. By default, |
| 31 | +compartments have in-built safeguards in order to prevent this from happening accidentally; however, directly addressing |
| 32 | +the compartment within the global state directly has no such safeguards. |
| 33 | + |
| 34 | +### What is "Targeting"? |
| 35 | + |
| 36 | +As discussed in the model building section, there is notion of "wiring" together different compartments of different |
| 37 | +components -- this is at the core of NGC-Learn's and NGC-Sim-Lib's "nodes-and-cables system". These wires are created |
| 38 | +through the concept of "targeting,", which is, in essence, just the updating of the path stored within a compartment |
| 39 | +using the path of a different compartment. This means that, if the targeted compartment goes to retrieve the value |
| 40 | +stored within it, it will actually retrieve the value of a different compartment (as dictated by the target). When a |
| 41 | +compartment is in this state -- where it is targeting another compartment -- it is set to read, which only means that |
| 42 | +it cannot modify a different compartment. |
48 | 43 |
|
49 | 44 |
|
0 commit comments