Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
minor fixes
  • Loading branch information
Joeperdefloep committed Mar 24, 2021
commit 67842cadd75a6702aec708b9e518e079b751eedd
42 changes: 13 additions & 29 deletions xsimlab/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,21 @@ def _sort_processes(self):

return ordered

def _get_inout_in_dicts(self):
def _strict_order_check(self):
"""
prepares dictionaries for _strict_order_check
returns:
inout_dict : {key:{p1_name,p2_name}}
in_dict : {key:{p3_name,p4_name}}
IMPORTANT: _sort_processes should be run first
checks if all inout variables and corresponding in variables are explicitly set in the dependencies
Out variables always come first, since the get_process_dependencies checks for that.
A well-behaved graph looks like:
```
inout1->inout2
^ \ ^ \
/ \ / \
in in in
```
needs to be run after _sort_processes
"""
# create dictionaries with all inout variables and input variables
inout_dict = {} # dict of {key:{p1_name,p2_name}} for inout variables
# TODO: improve this: the aim is to create a {key:{p1,p2,p3}} dict,
# where p1,p2,p3 are process names that have the key var as inout, resp. in vars
Expand All @@ -544,38 +552,14 @@ def _get_inout_in_dicts(self):
inout_dict[od_key].add(p_name)

in_dict = {key: set() for key in inout_dict}
print(self._processes_obj.items(), in_dict)
for p_name, p_obj in self._processes_obj.items():
print("now adding: ", p_name)
for var in filter_variables(p_obj, intent=VarIntent.IN).values():
state_key, od_key = self._get_var_key(p_name, var)
print("state key: ", state_key, "od key: ", od_key)
if state_key in in_dict:
in_dict[state_key].add(p_name)
if od_key in in_dict:
in_dict[od_key].add(p_name)

print("io dict: ", inout_dict, "in dict: ", in_dict)
return inout_dict, in_dict
# end TODO

def _strict_order_check(self):
"""
IMPORTANT: _sort_processes should be run first
checks if all inout variables and corresponding in variables are explicitly set in the dependencies
Out variables always come first, since the get_process_dependencies checks for that.
A well-behaved graph looks like:
```
inout1->inout2
^ \ ^ \
/ \ / \
in in in
```
needs to be run after _sort_processes
"""
# create dictionaries with all inout variables and input variables
inout_dict, in_dict = self._get_inout_in_dicts()

# filter out variables that do not need to be checked (without inputs):
# inout_dict = {k: v for k, v in inout_dict.items() if k in in_dict}

Expand Down
18 changes: 9 additions & 9 deletions xsimlab/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ class In1:
)

def test_strict_check_multiple_vars_in_process(self):
# in|->|io|->|in|->|io|
# | |in|->|io|->|in|
# in|->|io|->|in|->|io| - foo variable
# | |in|->|io|->|in| - bar variable
@xs.process
class Out:
foo = xs.on_demand()
Expand Down Expand Up @@ -323,15 +323,15 @@ class BarInFooInout:
xs.Model(
{
"out": Out,
"f_i_b_io": FooInBarInout,
"f_io_b_i": FooInoutBarIn,
"f_i": FooIn,
"b_i_f_io": BarInFooInout,
"foo_in_bar_inout": FooInBarInout,
"foo_inout_bar_in": FooInoutBarIn,
"foo_in": FooIn,
"boo_in_foo_inout": BarInFooInout,
},
custom_dependencies={
"b_i_f_io": "f_i_b_io",
"f_i_b_io": "f_io_b_i",
"f_io_b_i": "f_i",
"boo_in_foo_inout": "foo_in_bar_inout",
"foo_in_bar_inout": "foo_inout_bar_in",
"foo_inout_bar_in": "foo_in",
},
strict_order_check=True,
)
Expand Down