Skip to content

Commit c7b31d5

Browse files
author
Alexander Ororbia
committed
cleaned/revised docs/final nudge to 1.0.0 -- these changes move to release now
1 parent cd3431a commit c7b31d5

File tree

13 files changed

+144
-97
lines changed

13 files changed

+144
-97
lines changed

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Core Team
88
William Gebhardt <[email protected]>
99
Alexander Ororbia <[email protected]>
1010

11+
Contributors
12+
Viet Dung Nguyen <[email protected]>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ maintained by the
2323

2424
<i>Setup:</i> Ensure that you have installed the following base dependencies in
2525
your system. Note that this library was developed and tested on
26-
Ubuntu 22.04.3 LTS. ngc-sim-lib requires: `Python (>=3.8)`.
26+
Ubuntu 22.04.3/5 LTS. ngc-sim-lib requires: `Python (>=3.10)`.
2727

2828
Once you have ensured that the appropriate Python is installed, you can then
2929
have the <code>ngcsimlib</code> package installed on your system using either

ngcsimlib/compartment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, initial_value=None, static=False, is_input=False,
3737
to note that building compartments outside of components may cause
3838
unexpected behavior as components interact with their compartments
3939
during construction to finish initializing them.
40+
4041
Args:
4142
initial_value: The initial value of the compartment. As a general
4243
practice it is a good idea to provide a value that is similar to
@@ -60,7 +61,7 @@ def __init__(self, initial_value=None, static=False, is_input=False,
6061
def _setup(self, current_component, key):
6162
"""
6263
Finishes initializing the compartment, called by the component that
63-
builds the compartment
64+
builds the compartment
6465
(Handled automatically)
6566
"""
6667
self.__add_connection = current_component.add_connection
@@ -72,6 +73,7 @@ def set(self, value):
7273
"""
7374
Sets the value of the compartment if it not static (Raises a runtime
7475
error)
76+
7577
Args:
7678
value: the new value to be set
7779
"""
@@ -124,7 +126,6 @@ def is_wired(self):
124126
"""
125127
Returns: if this compartment not marked as an input, or is marked and
126128
has an input
127-
128129
"""
129130
if not self.is_input:
130131
return True

ngcsimlib/compilers/process.py

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Process(object):
4040
"""
4141
def __init__(self, name):
4242
"""
43-
Creates and empty process using the provided name
43+
Creates an empty process using the provided name
44+
4445
Args:
4546
name: the name of the process (should be unique per context)
4647
"""
@@ -57,15 +58,16 @@ def __init__(self, name):
5758
@staticmethod
5859
def make_process(process_spec, custom_process_klass=None):
5960
"""
60-
Used the in the creation of a process from a json file. Under normal
61-
circumstances this is not normally called by the user.
61+
Used in the creation of a process from a json file. Under normal
62+
circumstances this is not normally to be called by the user.
6263
6364
Args:
6465
process_spec: the parsed json object to create a process from
65-
custom_process_klass: a custom subclass of a process to build
6666
67-
Returns: the created process
67+
custom_process_klass: a custom subclass of a process to build
6868
69+
Returns:
70+
the created process
6971
"""
7072
if custom_process_klass is None:
7173
custom_process_klass = Process
@@ -81,17 +83,20 @@ def make_process(process_spec, custom_process_klass=None):
8183
@property
8284
def pure(self):
8385
"""
84-
Returns: The current compile method for the process as a pure method
86+
Returns:
87+
the current compile method for the process as a pure method
8588
"""
8689
return self._method
8790

8891
def __rshift__(self, other):
8992
"""
90-
Added wrapper for the transition method
93+
Added wrapper for the transition method.
94+
9195
Args:
9296
other: the transition call for the transition method
9397
94-
Returns: the process for the use of chaining calls
98+
Returns:
99+
the process for the use of chaining calls
95100
"""
96101
return self.transition(other)
97102

@@ -101,10 +106,10 @@ def transition(self, transition_call):
101106
decorated by the @transition decorator.
102107
103108
Args:
104-
transition_call: Transition method to add to the process
105-
106-
Returns: the process for the use of chaining calls
109+
transition_call: transition method to add to the process
107110
111+
Returns:
112+
the process for the use of chaining calls
108113
"""
109114
self._calls.append({"path": transition_call.__self__.path, "key": transition_call.resolver_key})
110115
self._needed_contexts.add(infer_context(transition_call.__self__.path))
@@ -119,19 +124,19 @@ def execute(self, update_state=False, **kwargs):
119124
"""
120125
Executes the process using the current state of the model to run. This
121126
method has checks to ensure that the process has transitions added to it
122-
as well as that all the keyword arguments required by each of the
123-
transition call are in the provided keyword arguments. By default, this
127+
as well as if all of the keyword arguments required by each of the
128+
transition calls are in the provided keyword arguments. By default, this
124129
does not update the final state of the model but that can be toggled
125130
with the flag "update_state".
126131
127132
Args:
128-
update_state: Should this method update the final state of the model
129-
**kwargs: The required keyword arguments to execute the process
133+
update_state: should this method update the final state of the model?
130134
131-
Returns: the final state of the process regardless of the model is
132-
updated to reflect this. Will return null if either of the above checks
133-
fail
135+
**kwargs: the required keyword arguments to execute the process
134136
137+
Returns:
138+
The final state of the process regardless of the model is updated to
139+
reflect this. Will return null/None if either of the above checks fail
135140
"""
136141
if self._method is None:
137142
warn("Attempting to execute a process with no transition steps")
@@ -147,14 +152,15 @@ def execute(self, update_state=False, **kwargs):
147152

148153
def as_obj(self):
149154
"""
150-
Returns: Returns this process as an object to be used with json files
155+
Returns:
156+
Returns this process as an object to be used with json files
151157
"""
152158
return {"name": self.name, "class": self.__class__.__name__, "calls": self._calls}
153159

154160
def get_required_args(self):
155161
"""
156-
Returns: The needed arguments for all the transition calls in this
157-
process as a set
162+
Returns:
163+
The needed arguments for all the transition calls in this process as a set
158164
"""
159165
return self._needed_args
160166

@@ -164,14 +170,15 @@ def get_required_state(self, include_special_compartments=False):
164170
note that if this is going to be used as an argument to the pure method
165171
make sure that the "include_special_compartments" flag is set to True so
166172
that special compartments found in certain components are visible.
173+
167174
Args:
168175
include_special_compartments: A flag to show the compartments that
169-
denoted as special compartments by ngcsimlib (this is any
170-
compartment with * in their name, these are can only be created
171-
dynamically)
172-
173-
Returns: A subset of the model state based on the required compartments
176+
denoted as special compartments by ngcsimlib (this is any
177+
compartment with * in their name, these are can only be created
178+
dynamically)
174179
180+
Returns:
181+
A subset of the model state based on the required compartments
175182
"""
176183
compound_state = {}
177184
for context in self._needed_contexts:
@@ -181,38 +188,40 @@ def get_required_state(self, include_special_compartments=False):
181188
def updated_modified_state(self, state):
182189
"""
183190
Updates the model with the provided state. It is important to note that
184-
only values that are rquired for the execution of this process will be
185-
affected by this call. If all compartments need to be updated, view
186-
other options found in ngcsimlib.utils.
191+
only values that are required for the execution of this process will be
192+
affected by this call. If all of the compartments need to be updated, view
193+
other options found in `ngcsimlib.utils`.
194+
187195
Args:
188-
state: The state to update the model with
196+
state: the state to update the model with
189197
"""
190198
Set_Compartment_Batch({key: value for key, value in state.items() if key in self.get_required_state(include_special_compartments=True)})
191199

192200

193201
def transition(output_compartments, builder=False):
194202
"""
195-
The decorator to be paired with the Process call. This method does
203+
The decorator to be paired with the `Process` call. This method does
196204
everything that the now outdated resolver did to ensure backward
197-
compatability. This decorator expects to decorate a static method on a
198-
class.
205+
compatability. This decorator expects the user/developer to decorate a
206+
static method on a class.
199207
200-
Through normal patterns these decorated method will never be directly called
208+
Through normal patterns, these decorated method will never be directly called
201209
by the end user, but if they are for the purpose of debugging there are a
202-
few things to keep in mind. While the process compiler will automatically
210+
few things to keep in mind. The process compiler will automatically
203211
link values in the component to the different values to be passed into the
204212
method that does not exist if they are directly called. In addition, if the
205213
method is going to be called at a class level the first value passed into
206214
the method must be None to not mess up the internal decoration.
207-
Args:
208-
output_compartments: The string name of the output compartments the
209-
outputs of this method will be assigned to in the order they are output.
210-
builder: A boolean flag for if this method is a builder method for the
211-
compiler. A builder method is a method that returns the static method to
212-
use in the transition.
213-
214-
Returns: the wrapped method
215215
216+
Args:
217+
output_compartments: the string name of the output compartments the
218+
outputs of this method will be assigned to in the order they are output.
219+
builder: A boolean flag for if this method is a builder method for the
220+
compiler. A builder method is a method that returns the static method to
221+
use in the transition.
222+
223+
Returns:
224+
the wrapped method
216225
"""
217226
def _wrapper(f):
218227
@wraps(f)
@@ -238,4 +247,5 @@ def inner(self, *args, **kwargs):
238247
add_transition_meta(class_name, resolver_key,([], [], [], True))
239248

240249
return inner
241-
return _wrapper
250+
return _wrapper
251+

ngcsimlib/compilers/process_compiler/component_compiler.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
This file contains the methods used to compile methods for the use of Processes.
2+
This file contains the methods used to compile methods for the use of Process(es).
33
The general methodology behind this compiler is that if all transitions can be
4-
expressed as f(current_state, **kwargs) -> final_state they can then be composed
4+
expressed as f(current_state, **kwargs) -> final_state, then they can then be composed
55
together as f(g(current_state, **kwargs) **kwargs) -> final_state. While it is
6-
technically possible to use the compiler outside the process its intended use
7-
case is through the process and thus if error occur though other uses support
8-
may be minimal.
6+
technically possible to use the compiler outside the process, its intended use
7+
case is through the process and, thus, if errors occur through other uses, note
8+
that support may be minimal.
99
"""
1010

1111
from ngcsimlib.compilers.process_compiler.op_compiler import compile as op_compile
@@ -31,14 +31,15 @@ def _builder(transition_method_to_build):
3131
def compile(transition_method):
3232
"""
3333
This method is the main compile method for the process compiler. Unlike the
34-
legacy compiler this compiler is designed to be self-contained and output
34+
legacy compiler, this compiler is designed to be self-contained and output
3535
the methods that are composed together to make the process compiler function
36+
3637
Args:
3738
transition_method: a method usually component.method that has been
38-
decorated by the @transition decorator.
39+
decorated by the @transition decorator.
3940
40-
Returns: the pure compiled method of the form
41-
f(current_state, **kwargs) -> final_state)
41+
Returns:
42+
the pure compiled method of the form f(current_state, **kwargs) -> final_state)
4243
4344
"""
4445
composition = None
@@ -93,3 +94,4 @@ def compiled(current_state, **kwargs):
9394
composition = compose(composition, compiled)
9495

9596
return composition, needed_args
97+

ngcsimlib/compilers/process_compiler/op_compiler.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ def _make_lambda(s):
55

66
def compile(op):
77
"""
8-
compiles root operation down to a single method of
9-
f(current_state, **kwargs) -> final_state
8+
Compiles root operation down to a single method of
9+
f(current_state, **kwargs) -> final_state
1010
1111
Args:
1212
op: the operation to compile
1313
14-
Returns: the compiled operation
14+
Returns:
15+
the compiled operation
1516
"""
1617
arg_methods = []
1718
for s in op.sources:
@@ -29,4 +30,5 @@ def compiled(current_state, **kwargs):
2930
else:
3031
return val
3132

32-
return compiled
33+
return compiled
34+

ngcsimlib/compilers/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def wrap_command(command):
55
"""
66
Wraps the provided command to provide the state of all compartments as input
77
and saves the returned state to all compartments after running. Designed to
8-
be used with compiled commands
8+
be used with compiled commands.
99
1010
Args:
1111
command: the command to wrap
@@ -28,3 +28,4 @@ def compose(current_composition, next_method):
2828

2929
return lambda current_state, **kwargs: next_method(
3030
current_composition(current_state, **kwargs), **kwargs)
31+

ngcsimlib/component.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def validate(self):
5555
"""
5656
Validates that each compartment of the component is wired correctly
5757
58-
Returns: if it is valid
58+
Returns:
59+
if this component is valid
5960
"""
6061
valid = True
6162
for key, item in self.__dict__.items():
@@ -75,4 +76,4 @@ def validate(self):
7576
msg += f"\nCompartment Description:\t{_help}"
7677
warn(msg)
7778
valid = False
78-
return valid
79+
return valid

ngcsimlib/configManager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def init_config(path):
4141
"""
4242
Initializes the global configuration from the provided path
4343
(called automatically)
44+
4445
Args:
4546
path: path to config file
4647
"""

0 commit comments

Comments
 (0)