Skip to content

Commit 2a3147a

Browse files
authored
Merge pull request #587 from ModECI/experimental
Addition of simple network example for testing conditions
2 parents b47d176 + 20d4bd2 commit 2a3147a

10 files changed

Lines changed: 216 additions & 16 deletions

File tree

‎.github/workflows/ci_test_all.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Test script
1+
name: CI test_all.sh script
22

33
on:
44
push:
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
python-version: [ "3.12"]
17+
python-version: [ "3.13" ]
1818
runs-on: [ubuntu-latest]
1919

2020
steps:

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,4 @@ examples/TensorFlow/Keras/keras_to_MDF
317317
/docs/sphinx/source/api/export_format/MDF/images/newton.png
318318
/docs/sphinx/source/api/export_format/MDF/images/newton_plot.png
319319
/examples/MDF/networks/Net_acyclical
320+
/examples/MDF/networks/Net_network2

‎examples/MDF/Simple.bson‎

0 Bytes
Binary file not shown.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"Net_network2": {
3+
"format": "ModECI MDF v0.4",
4+
"generating_application": "Python modeci-mdf v0.4.14",
5+
"graphs": {
6+
"Net_network2": {
7+
"nodes": {
8+
"A": {
9+
"input_ports": {
10+
"in_port_0": {
11+
"default_value": 5
12+
}
13+
},
14+
"parameters": {
15+
"total_inputs": {
16+
"value": "total_inputs + in_port_0"
17+
},
18+
"execute_count": {
19+
"value": "execute_count + 1"
20+
}
21+
},
22+
"output_ports": {
23+
"out_port_0": {
24+
"value": "total_inputs"
25+
}
26+
}
27+
},
28+
"B": {
29+
"input_ports": {
30+
"in_port_0": {}
31+
},
32+
"parameters": {
33+
"total_inputs": {
34+
"value": "total_inputs + in_port_0"
35+
},
36+
"execute_count": {
37+
"value": "execute_count + 1"
38+
}
39+
},
40+
"output_ports": {
41+
"out_port_0": {
42+
"value": "total_inputs"
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}
14.7 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Net_network2:
2+
format: ModECI MDF v0.4
3+
generating_application: Python modeci-mdf v0.4.14
4+
graphs:
5+
Net_network2:
6+
nodes:
7+
A:
8+
input_ports:
9+
in_port_0:
10+
default_value: 5
11+
parameters:
12+
total_inputs:
13+
value: total_inputs + in_port_0
14+
execute_count:
15+
value: execute_count + 1
16+
output_ports:
17+
out_port_0:
18+
value: total_inputs
19+
B:
20+
input_ports:
21+
in_port_0: {}
22+
parameters:
23+
total_inputs:
24+
value: total_inputs + in_port_0
25+
execute_count:
26+
value: execute_count + 1
27+
output_ports:
28+
out_port_0:
29+
value: total_inputs

‎examples/MDF/networks/network2.py‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
Example of ModECI MDF - Testing networks
3+
"""
4+
5+
from modeci_mdf.mdf import *
6+
import sys
7+
import os
8+
from modeci_mdf.utils import simple_connect
9+
10+
11+
def main(ref="network2"):
12+
13+
mod = Model(id="Net_%s" % ref)
14+
15+
mod_graph = Graph(id="Net_%s" % ref)
16+
mod.graphs.append(mod_graph)
17+
18+
for id in ["A", "B"]:
19+
20+
node = Node(id=id)
21+
22+
if id == "A":
23+
ip1 = InputPort(id="in_port_0", default_value=5)
24+
node.input_ports.append(ip1)
25+
26+
if id == "B":
27+
ip1 = InputPort(id="in_port_0")
28+
node.input_ports.append(ip1)
29+
30+
p1 = Parameter(id="total_inputs", value="total_inputs + in_port_0")
31+
node.parameters.append(p1)
32+
33+
p2 = Parameter(id="execute_count", value="execute_count + 1")
34+
node.parameters.append(p2)
35+
36+
op1 = OutputPort(id="out_port_0", value=p1.id)
37+
node.output_ports.append(op1)
38+
39+
mod_graph.nodes.append(node)
40+
41+
# simple_connect(mod_graph.get_node("A"), mod_graph.get_node("B"), mod_graph)
42+
# simple_connect(mod_graph.get_node("B"), mod_graph.get_node("A"), mod_graph)
43+
44+
new_file = mod.to_json_file("%s.json" % mod.id)
45+
new_file = mod.to_yaml_file("%s.yaml" % mod.id)
46+
47+
eg = None
48+
49+
if "-run" in sys.argv:
50+
verbose = True
51+
# verbose = False
52+
from modeci_mdf.utils import load_mdf, print_summary
53+
54+
from modeci_mdf.execution_engine import EvaluableGraph
55+
56+
eg = EvaluableGraph(mod_graph, verbose)
57+
dt = 1
58+
59+
duration = 2
60+
t = 0
61+
recorded = {}
62+
times = []
63+
ai = []
64+
bi = []
65+
at = []
66+
bt = []
67+
ao = []
68+
bo = []
69+
while t <= duration:
70+
times.append(t)
71+
print("====== Evaluating at t = %s ======" % (t))
72+
if t == 0:
73+
eg.evaluate() # replace with initialize?
74+
else:
75+
eg.evaluate(time_increment=dt)
76+
77+
ai.append(eg.enodes["A"].evaluable_parameters["execute_count"].curr_value)
78+
bi.append(eg.enodes["B"].evaluable_parameters["execute_count"].curr_value)
79+
at.append(eg.enodes["A"].evaluable_parameters["total_inputs"].curr_value)
80+
bt.append(eg.enodes["B"].evaluable_parameters["total_inputs"].curr_value)
81+
ao.append(eg.enodes["A"].evaluable_outputs["out_port_0"].curr_value)
82+
bo.append(eg.enodes["B"].evaluable_outputs["out_port_0"].curr_value)
83+
t += dt
84+
85+
if "-nogui" not in sys.argv:
86+
import matplotlib.pyplot as plt
87+
88+
plt.plot(times, ai, marker="x", label="A exe count")
89+
plt.plot(times, bi, label="B exe count")
90+
plt.plot(times, at, marker="D", label="A total_inputs")
91+
plt.plot(times, bt, label="B total_inputs")
92+
93+
plt.legend()
94+
plt.show()
95+
96+
if "-graph" in sys.argv:
97+
mod.to_graph_image(
98+
engine="dot",
99+
output_format="png",
100+
view_on_render=False,
101+
level=3,
102+
filename_root=mod_graph.id,
103+
only_warn_on_fail=(
104+
os.name == "nt"
105+
), # Makes sure test of this doesn't fail on Windows on GitHub Actions
106+
)
107+
108+
return mod_graph, eg
109+
110+
111+
if __name__ == "__main__":
112+
g, eg = main()
113+
114+
print("--------------------")
115+
print(g.to_yaml())
116+
print("--------------------")
117+
if eg is not None:
118+
for n in eg.enodes:
119+
enode = eg.enodes[n]
120+
print(enode)
121+
print([enode.evaluable_outputs for enode in eg.enodes.values()])
122+
else:
123+
print("No execution engine created. Run with: -run")

‎examples/PyTorch/PyTorch_MDF/benchmark_script/squeezenet1_1_benchmark.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
"model_name": "squeezenet1_1",
44
"model_type": "SqueezeNet",
5-
"pytorch_time": 0.0839,
5+
"pytorch_time": 0.07,
66
"pytorch_predictions": 10,
7-
"mdf_time": 4.4275,
7+
"mdf_time": 5.949,
88
"mdf_predictions": 10,
99
"node density": 66,
10-
"mdf : pytorch ratio": "52.79"
10+
"mdf : pytorch ratio": "84.98"
1111
}
1212
]

‎pyproject.toml‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ name = "modeci-mdf"
1111
dynamic = ["version"]
1212
description = "ModECI (Model Exchange and Convergence Initiative) Model Description Format"
1313
readme = "README.md"
14-
requires-python = ">=3.9"
14+
requires-python = ">=3.10"
1515
license = {text = "LGPLv3"}
1616
authors = [
1717
{name = "ModECI contributors", email = "p.gleeson@gmail.com"},
@@ -25,23 +25,21 @@ classifiers = [
2525
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
2626
"Natural Language :: English",
2727
"Operating System :: OS Independent",
28-
"Programming Language :: Python :: 3.8",
2928
"Topic :: Scientific/Engineering",
30-
"Intended Audience :: Science/Research",
3129
"Programming Language :: Python",
3230
"Programming Language :: Python :: 3",
3331
"Programming Language :: Python :: 3 :: Only",
3432
"Programming Language :: Python :: 3.10",
3533
"Programming Language :: Python :: 3.11",
3634
"Programming Language :: Python :: 3.12",
3735
"Programming Language :: Python :: 3.13",
38-
"Topic :: Scientific/Engineering",
3936
"Topic :: Software Development",
4037
"Typing :: Typed",
4138
]
4239
dependencies = [
4340
"graph_scheduler>=1.1.1",
4441
"numpy",
42+
"scipy",
4543
"matplotlib",
4644
"graphviz",
4745
"h5py",
@@ -92,7 +90,6 @@ optional = [
9290
"netron",
9391
"torch>=1.11.0",
9492
"torchvision",
95-
"h5py",
9693
]
9794

9895
all_except_psyneulink = [
@@ -144,9 +141,6 @@ exclude = ["tests", "examples"]
144141
[tool.setuptools.dynamic]
145142
version = {attr = "modeci_mdf.__version__"}
146143

147-
#[tool.setuptools_scm]
148-
#write_to = "src/modeci_mdf/version.py"
149-
150144
[tool.pytest.ini_options]
151145
junit_family = "xunit2"
152146
addopts = "--benchmark-disable -Wd --strict-markers"
@@ -156,7 +150,7 @@ required_plugins = ["pytest-benchmark"]
156150
markers = [
157151
"coremdf: marks tests which are core to the MDF specification",
158152
"actr: marks tests which require ACT-R to be installed.",
159-
"pytorch: marks test which require PyTorch to be installed.')",
153+
"pytorch: marks tests which require PyTorch to be installed.",
160154
"psyneulink: marks tests which require PsyNueLink to be installed.",
161155
"neuroml: marks tests which require NeuroML to be installed.",
162156
"tensorflow: marks tests which require TensorFlow to be installed.",
@@ -182,7 +176,7 @@ per-file-ignores = [
182176

183177
[tool.mypy]
184178
warn_unused_configs = true
185-
python_version = "3.6"
179+
python_version = "3.10"
186180
files = ["src"]
187181
disallow_any_generics = true
188182
disallow_subclassing_any = true

‎src/modeci_mdf/execution_engine.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,9 @@ def evaluate(
679679
)
680680
return self.curr_value
681681

682+
def __repr__(self):
683+
return f"EvaluableOutput({self.output_port.id} = {_val_info(self.curr_value)} )"
684+
682685

683686
class EvaluableInput:
684687
"""Evaluates input value at the :class:`~modeci_mdf.mdf.InputPort` of the node during MDF graph execution.
@@ -766,7 +769,7 @@ def evaluate(
766769
)
767770
)
768771

769-
self.curr_value = None
772+
self.curr_value = None # to be tested for conditions...
770773
return final_val
771774

772775

0 commit comments

Comments
 (0)