Skip to content

Commit 11706ae

Browse files
committed
Docs updates
1 parent d6ed49f commit 11706ae

File tree

6 files changed

+81
-33
lines changed

6 files changed

+81
-33
lines changed

docs/compartments.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Compartments
22

3-
Within ngcsimlib, the global state serves as the backbone of any given model.
3+
Within NGC-Sim-Lib, the global state serves as the backbone of any given model.
44
This global state is essentially the culmination of all of the dynamic or changing parts of the model itself. Each
55
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`).
6+
is referred to as a `Compartment`.
77

88
## Practical Information
99

1010
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:
11+
of NGC-Sim-Lib's primary operation is behind-the-scenes bookkeeping. The two main points to note are:
1212
1. Each compartment holds a value and, thus, setting a compartment with `myCompartment = newValue` will not function as
1313
intended since this will overwrite the Python object, i.e., the compartment with `newValue`. Instead, it is
1414
important to make use of the `.set()` method to update the value stored inside a compartment so
@@ -20,7 +20,7 @@ of ngcsimlib's primary operation is behind-the-scenes bookkeeping. The two main
2020
## Technical Information
2121

2222
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.
23+
with in the broader scope of NGC-Sim-Lib and, furthermore, to explain how to leverage this information.
2424

2525
### How Data is Stored (Within a Model Context)
2626

@@ -38,7 +38,7 @@ components -- this is at the core of NGC-Learn's and NGC-Sim-Lib's "nodes-and-ca
3838
through the concept of "targeting,", which is, in essence, just the updating of the path stored within a compartment
3939
using the path of a different compartment. This means that, if the targeted compartment goes to retrieve the value
4040
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
41+
compartment is in this state -- where it is targeting another compartment -- it is set to read-only, which only means that
4242
it cannot modify a different compartment.
4343

4444

docs/compiling.md

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,98 @@
11
# Compiling
22

3-
The term "compiling" for ngcsimlib refers to automatic step that happens inside of a context that produces a transformed method for all of its components. This step is the most complicated part of the library and, in general, does not need to be touched or interacted with. Nevertheless, this section will cover all of the steps that the ngcsimlib compilation process does at a high level. This section contains advanced technical/developer-level information: there is an expectation that the reader has an understanding of Python abstract syntax trees (ASTs), globals (global variables), and how to dynamically compile Python code to run/execute.
3+
The term "compiling" for NGC-Sim-Lib refers to automatic step that happens
4+
inside of a context that produces a transformed method for all of its
5+
components. This step is the most complicated part of the library and, in
6+
general, does not need to be touched or interacted with. Nevertheless, this
7+
section will cover most of the steps that the NGC-Sim-Lib compilation process
8+
does at a high level. This section contains advanced technical/developer-level
9+
information: there is an expectation that the reader has an understanding of
10+
Python abstract syntax trees (ASTs), Python namespaces, and how to
11+
dynamically compile Python code and execute it.
412

513
## The Decorator
614

7-
In ngcsimlib, there is a decorator marked as `@compilable` which is used to add a flag to methods that the user wants to compile. On its own,this will not do anything; however, this decorator lets the parser distinguish between methods that should be compiled and methods that should be ignored (by the overall back-end compilation process).
15+
In NGC-Sim-Lib, there is a decorator marked as `@compilable` which is used to
16+
add a flag to methods that the user wants to compile. On its own, this will not
17+
do anything; however, this decorator lets the parser distinguish between methods
18+
that should be compiled and methods that should be ignored.
819

920
## The Step-by-Step NGC-Sim-Lib Parsing Process
1021

1122
The process starts by telling the parser to compile a specific object.
1223

1324
### Step 1: Compile Children
1425

15-
The first step to compile any object is to make sure that all of the "compilable" objects of the top level object are essentially compiled. As a result, ngcsimlib will loop through all of the whole objects and will compile each part that it finds that is flagged as compilable (via the decorators mentioned above) and is, furthermore, an instance of a class.
26+
The first step to compile any object is to make sure that all of the
27+
"compilable" objects of the top level object are compiled. As a
28+
result, NGC-Sim-Lib will loop through all of the whole object and will compile
29+
each part that it finds that is flagged as compilable (via the decorators
30+
mentioned above) and is, furthermore, an instance of a class.
1631

1732
### Step 2: Extract Methods to Compile
1833

19-
While the parser is looping through all of the parts of the top-level object, it is also extracting the methods on/embedded to the object that are flagged as compilable (with the decorator above). ngcsimlib stores them for later; however, this lets the parser know to only loop over the object once.
34+
While the parser is looping through all of the parts of the top-level object, it
35+
is also extracting the methods on/embedded to the object that are flagged as
36+
compilable (with the decorator above). NGC-Sim-Lib stores them for later;
37+
however, this lets the parser only loop over the object once.
2038

2139
### Step 3: Parse Each Method
2240

23-
As each method is its own entry-point into the compiler, this step will run for each method in the top-level object.
41+
As each method is its own entry-point into the transformer, this step will run
42+
for each method in the top-level object.
2443

2544
### Step 3a: Set up a Transformer
2645

27-
This step sets up a ContextTransformer, which further makes use of a NodeTransformer, and will convert methods from class methods (with the use of `self`), as well as other methods that need to be removed / ignored, into their more context-friendly counterparts.
46+
This step sets up a `ContextTransformer`, which further makes use of a
47+
`ast.NodeTransformer`, and will convert methods from class methods (with the use
48+
of `self`), as well as other methods that need to be removed / ignored, into
49+
their more context-friendly counterparts.
2850

2951
### Step 3b: Transform the Function
3052

31-
There are quite a few pieces of common Python that need to be transformed. This step happens with the overall goal of replacing all object-focused parts with a more global view. This means that a compartment's `.get` and `.set` calls are replaced with direct setting and getting from the global state, based on the compartment's target. This also means that all temporally constant values -- such as `batch_size` -- are moved into the globals space for that specific file and ultimately replaced with the naming convention of `object_path_constant`. One more key step that is performed is to ensure that there is no branching in the code. Specifically, if there is a branch, i.e., an if-statement, ngcsimlib will evaluate it and only keep the branch it will traverse down. This means that there cannot be any branch logic based on inputs or computed values (this is a common restriction for just-in-time compiling).
53+
There are quite a few pieces of common Python that need to be transformed. This
54+
step happens with the overall goal of replacing all object-focused parts with a
55+
more global view. This means that a compartment's `.get` and `.set` calls are
56+
replaced with direct setting and getting from the global state, based on the
57+
compartment's target. This also means that all temporally constant values --
58+
such as `batch_size` -- are moved into the globals space for that specific file
59+
and ultimately replaced with the naming convention of `object_path_constant`.
60+
One more key step that is performed is to ensure that there is no branching in
61+
the code. Specifically, if there is a branch, i.e., an if-statement, NGC-Sim-Lib
62+
will evaluate it and only keep the branch it will traverse down. This means that
63+
there cannot be any branch logic based on inputs or computed values (this is a
64+
common restriction for just-in-time compiling).
3265

3366
### Step 3c: Parse Sub-Methods
3467

35-
Since it is possible to have other class methods that are not marked as entry-points for compilation but still need to be compiled, as step 3b happens, ngcsimlib tracks all of the sub-methods required. Notably, this step goes through and repeats steps 3a and 3b for each of the (sub-)methods with a naming convention similar to the temporally constant values for each method.
68+
Since it is possible to have other class methods that are not marked as
69+
entry-points for compilation but still need to be compiled, as step 3b happens,
70+
NGC-Sim-Lib tracks all of the sub-methods required. Notably, this step goes
71+
through and repeats steps 3a and 3b for each of the (sub-)methods with a naming
72+
convention similar to the temporally constant values for each method.
3673

3774
### Step 3d: Compile the Abstract Syntax Tree (AST)
3875

39-
Once we have all of the namespace and globals needed to execute the properly-transformed method, the method is compiled with Python and finally executed.
76+
Once we have all of the namespace and globals needed to execute the
77+
properly-transformed method, the method is compiled with Python and finally
78+
executed.
4079

4180
### Step 3e: Binding
4281

43-
The final step per method is to bind each to their original method; this replaces each method with an object which, when called, will act like the normal, uncompiled version but has the addition of the `.compiled` attribute. This attribute contains all of the compiled information to be used later (for model / system simulation). This crucially allows for the end user to call `myComponent.myMethod.compiled()` and have it run. The exact type for a `compiled` value can be found in `ngcsimlib._src.parser.utils:CompiledMethod`.
82+
The final step per method is to bind each to their original method; this
83+
replaces each method with an object which, when called, will act like the
84+
normal, uncompiled version but has the addition of the `.compiled` attribute.
85+
This attribute contains all of the compiled information to be used later (for
86+
model / system simulation). This crucially allows for the end user to
87+
call `myComponent.myMethod.compiled()` and have it run. The exact type for
88+
a `compiled` value can be found
89+
in `ngcsimlib._src.parser.utils:CompiledMethod`.
4490

4591
### Step 4: Finishing Up / Final Processing
4692

47-
Some objects, such as the processes, entail additional steps to modify themselves or their compiled methods in order to align themselves with needed functionality. However, this operation/functionality is found within each class's expanded `compile` method and should be referred to by looking at those methods specifically.
93+
Some objects, such as the processes, entail additional steps to modify
94+
themselves or their compiled methods in order to align themselves with needed
95+
functionality. However, this operation/functionality is found within each
96+
class's expanded `compile` method and should be referred to by looking at those
97+
methods specifically.
4898

docs/components.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ when constructing a complete model of a dynmical system.
99
## Temporally Constant versus Dynamic Compartments
1010

1111
One important distinction that needs to be highlighted within a component is the
12-
difference between a temporally constant (or static) value and a dynamic (time-varying) compartment.
12+
difference between a temporally constant value and a dynamic (time-varying) compartment.
1313
Compartments themselves house values that change over time and, generally, they will have the
1414
type `ngcsimlib.Compartment`; note that compartments are to be used to track the internal values
1515
of a component. These internal values can be ones such inputs, decaying values, counters, etc.
1616
The second kind of values found within a component are known as temporally constant values; these
17-
are values (e.g., hyper-parameters, structural parameters, etc.) that will remain fixed / static
18-
with constructed model dynamical system. These types of values tend to include common configuration
17+
are values (e.g., hyper-parameters, structural parameters, etc.) that will remain fixed
18+
within constructed model dynamical system. These types of values tend to include common configuration
1919
and meta-parameter settings, such as matrix shapes and coefficients.
2020

2121
## Defining Compilable Methods
@@ -28,5 +28,5 @@ value, one must write out such a call as: `self.myCompartment.get()`. The only r
2828
that any method that is decorated <b>cannot</b> have a return value; values should be stored
2929
inside their respective compartments (by making an appeal to their respective set routine, i.e.,
3030
`self.myCompartment.set(value)`). In an external (compilation) step, outside of the developer's
31-
definition of a component, an ngcsimlib transformer will change/convert all of these (decorated)
32-
methods into ones that function with the rest of the ngcsimlib back-end.
31+
definition of a component, an NGC-Sim-Lib transformer will change/convert all of these (decorated)
32+
methods into ones that function with the rest of the NGC-Sim-Lib back-end.

docs/context.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Contexts
22

3-
Contexts, in ngcsimlib, are the top-level containers that hold everything used to
3+
Contexts, in NGC-Sim-Lib, are the top-level containers that hold everything used to
44
define a model / dynamical system. On their own, contexts have no runtime logic;
55
they rely on their internal processes and components to build a complete, working model.
66

77
## Defining a Context
88

9-
To define a context (`ngcsimlib.Context`), ngcsimlib leverages the `with` block; this
9+
To define a context (`ngcsimlib.Context`), NGC-Sim-Lib leverages the `with` block; this
1010
means that to create a new context, simply start with the statement
1111
`with Context("myContext") as ctx:` and a new context will be created.
1212
(<i>Important Note</i>: names are unique; if a context is created with the same name,
@@ -46,10 +46,8 @@ steps while inside the `with`-block of the process.
4646

4747
## Exiting the `with` block
4848

49-
When the context exits the `with`-block, it will re-compile the entire model. This
50-
means that compilation of all parts of the model that needed to be compiled before
51-
usage (such as the compiled methods of a process) needs to happen after the
52-
`with`-block is exited. Behind the scenes, this is calling `recompile` on the context
49+
When the context exits the `with`-block, it will re-compile the entire model.
50+
Behind the scenes, this is calling `recompile` on the context
5351
itself; it is possible to manually trigger the recompile step, but doing so can
5452
break certain connections (between components/compartments), so use this
5553
functionality sparingly.

docs/global_state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The Global State
22

3-
Since ngcsimlib is a simulation library focused on temporal models and dynamical
3+
Since NGC-Sim-Lib is a simulation library focused on temporal models and dynamical
44
systems, or models that change over time there, it is foundational that all models
55
(and their respective elements) have some concept of a "state". These states
66
might be comprised of a single value that changes/evolves or of a complex set of values
@@ -22,7 +22,7 @@ anything that is needed for your actual model.
2222

2323
### Adding New Fields to the Global State
2424

25-
If you are new to using ngcsimlib and looking for a way to add values to the
25+
If you are new to using NGC-Sim-Lib and looking for a way to add values to the
2626
global state directly and explicitly, stop for a moment and reconsider. Unless
2727
you know exactly what you are doing (i.e., doing core development), it is strongly
2828
advised to not manually add values to the global state; instead, work through the

docs/processes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Processes
22

3-
Processes in ngcsimlib offer a central way of defining a specific transition to be
3+
Processes in NGC-Sim-Lib offer a central way of defining a specific transition to be
44
taken within a given model (this effectively sets up the behavior of the state-machine
55
that defines the desired dynamical system one wants to simulate). In effect, processes
66
take in as many compilable methods as possible across any number of
@@ -27,14 +27,14 @@ myProcess >> myCompA.forward >> myCompB.forward >> myCompA.evolve >> myCompB.evo
2727
```
2828

2929
In both cases, this process will chain the four methods together into a single
30-
step, only updating the final state that all steps are to complete.
30+
step, only updating the final state after all steps are complete.
3131

3232
## Types of Processes
3333

3434
There are two types of processes: the above example would be with what is
3535
referred to as a `MethodProcess` -- these are used to chain together any
3636
compilable methods from any number of different components. The other second
37-
type of process, called a `JointProcess` in ngcsimlib, is used to chain
37+
type of process, called a `JointProcess` in NGC-Sim-Lib, is used to chain
3838
together entire processes.
3939
JointProcesses are especially useful if there are multiple method processes that
4040
need to be called but different orders of the processes are needed at different
@@ -85,6 +85,6 @@ iterations of the process. Note that the arguments are slightly different: first
8585
it now utilizes a `length` argument to indicate the number of rows being produced and,
8686
second, it features a `seed_generator` that is used to generate the seed of each row
8787
(for instance, to have only even seed values: `seed_generator = lambda x: 2 * x`); if
88-
the generator is `None` `seed_generator = lamda x: x` is used.
88+
the generator is `None`, then `seed_generator = lamda x: x` is used.
8989
After this, the same keyword arguments to define the needed parameters are used as in `pack_keywords`.
9090

0 commit comments

Comments
 (0)