Rimjhim Mittal
commited on
Commit
β’
08c0e58
1
Parent(s):
a1a1db6
adding files
Browse files- markdowns/arc_func.md +8 -0
- markdowns/css.md +2 -2
- markdowns/introduction.md +4 -4
- models/__pycache__/arc_functions.cpython-311.pyc +0 -0
- models/__pycache__/sine_approximator.cpython-311.pyc +0 -0
- models/arc_functions.py +85 -0
- models/main_graph.gv +16 -0
- models/main_graph.gv.png +0 -0
- models/sine_approximator.json +230 -0
- models/sine_approximator.onnx +0 -0
- models/sine_approximator.py +89 -0
- models/sine_approximator.yaml +153 -0
- models/sine_approximator_model +17 -0
- models/sine_approximator_model.png +0 -0
- models/sir_model +11 -0
- models/sir_model.png +0 -0
- pages/NLC.py +0 -107
- requirements.txt +2 -0
markdowns/arc_func.md
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# π Trigonometric Chain Model
|
2 |
+
|
3 |
+
This model demonstrates the built-in arcsin, arccos, and arctan functions within a MDF, illustrating the sequential processing and transformation of data through these trigonometric operations. By establishing a chain of nodes, each representing one of these functions, the model showcases how input data is modified and passed through the trigonometric functions to produce distinct outputs at each stage. The model consists of three primary nodes:
|
4 |
+
1. **arctan_node**: Applies the arctan function to the input value.
|
5 |
+
2. **arccos_node**: Receives the output from the arctan_node, applying the arccos function.
|
6 |
+
3. **arcsin_node**: Takes the output from the arccos_node to apply the arcsin function.
|
7 |
+
|
8 |
+
|
markdowns/css.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<style>
|
2 |
|
3 |
.stApp {
|
4 |
background-image: linear-gradient(to right, rgba(13, 19, 48, 1) 0%, rgba(30, 37, 88, 1) 50%, #084349 100%), url("https://dl.dropboxusercontent.com/scl/fi/vrlu5xm5uh7nj6tor97my/glow_bg-7-1.png?rlkey=raqq4j45y0ogyuvu4rgvjcc3a&dl=1");
|
@@ -22,4 +22,4 @@
|
|
22 |
|
23 |
/* Customizing the color of text and icons in the sidebar */
|
24 |
|
25 |
-
</style>
|
|
|
1 |
+
<!-- <style>
|
2 |
|
3 |
.stApp {
|
4 |
background-image: linear-gradient(to right, rgba(13, 19, 48, 1) 0%, rgba(30, 37, 88, 1) 50%, #084349 100%), url("https://dl.dropboxusercontent.com/scl/fi/vrlu5xm5uh7nj6tor97my/glow_bg-7-1.png?rlkey=raqq4j45y0ogyuvu4rgvjcc3a&dl=1");
|
|
|
22 |
|
23 |
/* Customizing the color of text and icons in the sidebar */
|
24 |
|
25 |
+
</style> -->
|
markdowns/introduction.md
CHANGED
@@ -3,7 +3,7 @@ Newton's Law of Cooling is expressed by the differential equation:
|
|
3 |
$$
|
4 |
\frac{dT}{dt} = -k(T - T_{\text{ambient}})
|
5 |
$$
|
6 |
-
The temperature of the object is denoted by $T
|
7 |
-
The ambient temperature is denoted by $T_{\text{ambient}}
|
8 |
-
The cooling coefficient is represented by $k
|
9 |
-
The rate of change of the temperature over time is given by $\frac{dT}{dt}$.
|
|
|
3 |
$$
|
4 |
\frac{dT}{dt} = -k(T - T_{\text{ambient}})
|
5 |
$$
|
6 |
+
- The temperature of the object is denoted by $T$,
|
7 |
+
- The ambient temperature is denoted by $T_{\text{ambient}}$,
|
8 |
+
- The cooling coefficient is represented by $k$,
|
9 |
+
- The rate of change of the temperature over time is given by $\frac{dT}{dt}$.
|
models/__pycache__/arc_functions.cpython-311.pyc
ADDED
Binary file (4.69 kB). View file
|
|
models/__pycache__/sine_approximator.cpython-311.pyc
ADDED
Binary file (6.28 kB). View file
|
|
models/arc_functions.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from modeci_mdf.mdf import Model, Graph, Node, Parameter, OutputPort, InputPort, Edge
|
2 |
+
from modeci_mdf.execution_engine import EvaluableGraph
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
import IPython
|
6 |
+
|
7 |
+
# Define the model creation function
|
8 |
+
def main(input_value=1.0, mode=None):
|
9 |
+
mod = Model(id="TrigFunctionsChain")
|
10 |
+
mod_graph = Graph(id="arc_functions")
|
11 |
+
mod.graphs.append(mod_graph)
|
12 |
+
|
13 |
+
# arctan_node
|
14 |
+
arctan_node = Node(id="arctan_node")
|
15 |
+
arctan_node.parameters.append(Parameter(id="input_value", value=input_value))
|
16 |
+
arctan_node.parameters.append(Parameter(id="arctan_result", function="arctan", args={"variable0": "input_value", "scale": 0.4}))
|
17 |
+
arctan_node.output_ports.append(OutputPort(id="output", value="arctan_result"))
|
18 |
+
mod_graph.nodes.append(arctan_node)
|
19 |
+
|
20 |
+
# arccos_node
|
21 |
+
arccos_node = Node(id="arccos_node")
|
22 |
+
arccos_node.input_ports.append(InputPort(id="input_from_arctan"))
|
23 |
+
arccos_node.parameters.append(Parameter(id="arccos_result", function="arccos", args={"variable0": "input_from_arctan", "scale": 0.3}))
|
24 |
+
arccos_node.output_ports.append(OutputPort(id="output", value="arccos_result"))
|
25 |
+
mod_graph.nodes.append(arccos_node)
|
26 |
+
|
27 |
+
# arcsin_node
|
28 |
+
arcsin_node = Node(id="arcsin_node")
|
29 |
+
arcsin_node.input_ports.append(InputPort(id="input_from_arccos"))
|
30 |
+
arcsin_node.parameters.append(Parameter(id="arcsin_result", function="arcsin", args={"variable0": "input_from_arccos", "scale": 0.2}))
|
31 |
+
arcsin_node.output_ports.append(OutputPort(id="output", value="arcsin_result"))
|
32 |
+
mod_graph.nodes.append(arcsin_node)
|
33 |
+
|
34 |
+
# Define connections
|
35 |
+
mod_graph.edges.append(
|
36 |
+
Edge(id="h", sender="arctan_node", sender_port="output", receiver="arccos_node", receiver_port="input_from_arctan")
|
37 |
+
)
|
38 |
+
mod_graph.edges.append(
|
39 |
+
Edge(id="i", sender="arccos_node", sender_port="output", receiver="arcsin_node", receiver_port="input_from_arccos")
|
40 |
+
)
|
41 |
+
|
42 |
+
|
43 |
+
if mode=="run":
|
44 |
+
eg = EvaluableGraph(mod_graph, verbose=False)
|
45 |
+
eg.evaluate()
|
46 |
+
|
47 |
+
return {
|
48 |
+
"arctan_node": eg.enodes["arctan_node"].evaluable_outputs["output"].curr_value,
|
49 |
+
"arccos_node": eg.enodes["arccos_node"].evaluable_outputs["output"].curr_value,
|
50 |
+
"arcsin_node": eg.enodes["arcsin_node"].evaluable_outputs["output"].curr_value,
|
51 |
+
}
|
52 |
+
elif mode=="graph":
|
53 |
+
|
54 |
+
mod.to_graph_image(
|
55 |
+
engine="dot",
|
56 |
+
output_format="png",
|
57 |
+
view_on_render=False,
|
58 |
+
level=3,
|
59 |
+
filename_root="sir_model",
|
60 |
+
is_horizontal=True
|
61 |
+
)
|
62 |
+
|
63 |
+
from IPython.display import Image
|
64 |
+
Image(filename="sir_model.png")
|
65 |
+
image_path = "sir_model.png"
|
66 |
+
return image_path
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
return mod_graph
|
71 |
+
|
72 |
+
if __name__ == "__main__":
|
73 |
+
if len(sys.argv) > 1:
|
74 |
+
# Assuming the second argument is the mode (e.g., '-run' or '-graph')
|
75 |
+
mode_arg = sys.argv[1]
|
76 |
+
if mode_arg == "-run":
|
77 |
+
main(mode="run")
|
78 |
+
elif mode_arg == "-graph":
|
79 |
+
main(mode="graph")
|
80 |
+
else:
|
81 |
+
print("Invalid argument. Please use '-run' or '-graph'.")
|
82 |
+
else:
|
83 |
+
print("No arguments provided. Please specify '-run' or '-graph'.")
|
84 |
+
|
85 |
+
|
models/main_graph.gv
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
digraph main_graph {
|
2 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
3 |
+
"/network/network.0/Gemm" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.0/Gemm</b></td></tr><tr><td><font color="#188855">input</font> (shape: (1, 1), type: float)</td></tr><tr><td><font color="#188855">network.0.weight</font> (shape: (64, 1), type: float)</td></tr><tr><td><font color="#188855">network.0.bias</font> (shape: (64,), type: float)</td></tr><tr><td><font color="#1666ff">alpha</font> = 1.0</td></tr><tr><td><font color="#1666ff">beta</font> = 1.0</td></tr><tr><td><font color="#1666ff">transB</font> = 1</td></tr><tr><td><font color="#1666ff">/network/network.0/Gemm</font> = <i>onnx::Gemm</i>(<font color="#188855">input</font>, <font color="#188855">network.0.weight</font>, <font color="#188855">network.0.bias</font>)</td></tr><tr><td><font color="#cc3355">_network_network.0_Gemm_output_0</font> = <font color="#1666ff">/network/network.0/Gemm</font> </td></tr></table>>]
|
4 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
5 |
+
"/network/network.1/Relu" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.1/Relu</b></td></tr><tr><td><font color="#188855">_network_network.0_Gemm_output_0</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#1666ff">/network/network.1/Relu</font> = <i>onnx::Relu</i>(<font color="#188855">_network_network.0_Gemm_output_0</font>)</td></tr><tr><td><font color="#cc3355">_network_network.1_Relu_output_0</font> = <font color="#1666ff">/network/network.1/Relu</font> </td></tr></table>>]
|
6 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
7 |
+
"/network/network.2/Gemm" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.2/Gemm</b></td></tr><tr><td><font color="#188855">_network_network.1_Relu_output_0</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#188855">network.2.weight</font> (shape: (64, 64), type: float)</td></tr><tr><td><font color="#188855">network.2.bias</font> (shape: (64,), type: float)</td></tr><tr><td><font color="#1666ff">alpha</font> = 1.0</td></tr><tr><td><font color="#1666ff">beta</font> = 1.0</td></tr><tr><td><font color="#1666ff">transB</font> = 1</td></tr><tr><td><font color="#1666ff">/network/network.2/Gemm</font> = <i>onnx::Gemm</i>(<font color="#188855">_network_network.1_Relu_output_0</font>, <font color="#188855">network.2.weight</font>, <font color="#188855">network.2.bias</font>)</td></tr><tr><td><font color="#cc3355">_network_network.2_Gemm_output_0</font> = <font color="#1666ff">/network/network.2/Gemm</font> </td></tr></table>>]
|
8 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
9 |
+
"/network/network.3/Relu" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.3/Relu</b></td></tr><tr><td><font color="#188855">_network_network.2_Gemm_output_0</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#1666ff">/network/network.3/Relu</font> = <i>onnx::Relu</i>(<font color="#188855">_network_network.2_Gemm_output_0</font>)</td></tr><tr><td><font color="#cc3355">_network_network.3_Relu_output_0</font> = <font color="#1666ff">/network/network.3/Relu</font> </td></tr></table>>]
|
10 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
11 |
+
"/network/network.4/Gemm" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.4/Gemm</b></td></tr><tr><td><font color="#188855">_network_network.3_Relu_output_0</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#188855">network.4.weight</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#188855">network.4.bias</font> (shape: (1,), type: float)</td></tr><tr><td><font color="#1666ff">alpha</font> = 1.0</td></tr><tr><td><font color="#1666ff">beta</font> = 1.0</td></tr><tr><td><font color="#1666ff">transB</font> = 1</td></tr><tr><td><font color="#1666ff">/network/network.4/Gemm</font> = <i>onnx::Gemm</i>(<font color="#188855">_network_network.3_Relu_output_0</font>, <font color="#188855">network.4.weight</font>, <font color="#188855">network.4.bias</font>)</td></tr><tr><td><font color="#cc3355">output</font> = <font color="#1666ff">/network/network.4/Gemm</font> </td></tr></table>>]
|
12 |
+
"/network/network.0/Gemm" -> "/network/network.1/Relu" [label=</network/network.0/Gemm._network_network.0_Gemm_output_0_/network/network.1/Relu._network_network.0_Gemm_output_0 (<font color="#cc3355">_network_network.0_Gemm_output_0</font> -> <font color="#188855">_network_network.0_Gemm_output_0</font>)> arrowhead=empty]
|
13 |
+
"/network/network.1/Relu" -> "/network/network.2/Gemm" [label=</network/network.1/Relu._network_network.1_Relu_output_0_/network/network.2/Gemm._network_network.1_Relu_output_0 (<font color="#cc3355">_network_network.1_Relu_output_0</font> -> <font color="#188855">_network_network.1_Relu_output_0</font>)> arrowhead=empty]
|
14 |
+
"/network/network.2/Gemm" -> "/network/network.3/Relu" [label=</network/network.2/Gemm._network_network.2_Gemm_output_0_/network/network.3/Relu._network_network.2_Gemm_output_0 (<font color="#cc3355">_network_network.2_Gemm_output_0</font> -> <font color="#188855">_network_network.2_Gemm_output_0</font>)> arrowhead=empty]
|
15 |
+
"/network/network.3/Relu" -> "/network/network.4/Gemm" [label=</network/network.3/Relu._network_network.3_Relu_output_0_/network/network.4/Gemm._network_network.3_Relu_output_0 (<font color="#cc3355">_network_network.3_Relu_output_0</font> -> <font color="#188855">_network_network.3_Relu_output_0</font>)> arrowhead=empty]
|
16 |
+
}
|
models/main_graph.gv.png
ADDED
models/sine_approximator.json
ADDED
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"ONNX Model": {
|
3 |
+
"format": "ModECI MDF v0.4",
|
4 |
+
"generating_application": "Python modeci-mdf v0.4.9",
|
5 |
+
"graphs": {
|
6 |
+
"main_graph": {
|
7 |
+
"nodes": {
|
8 |
+
"/network/network.0/Gemm": {
|
9 |
+
"input_ports": {
|
10 |
+
"input": {
|
11 |
+
"shape": [
|
12 |
+
1,
|
13 |
+
1
|
14 |
+
],
|
15 |
+
"type": "float"
|
16 |
+
},
|
17 |
+
"network.0.weight": {
|
18 |
+
"shape": [
|
19 |
+
64,
|
20 |
+
1
|
21 |
+
],
|
22 |
+
"type": "float"
|
23 |
+
},
|
24 |
+
"network.0.bias": {
|
25 |
+
"shape": [
|
26 |
+
64
|
27 |
+
],
|
28 |
+
"type": "float"
|
29 |
+
}
|
30 |
+
},
|
31 |
+
"parameters": {
|
32 |
+
"alpha": {
|
33 |
+
"value": 1.0
|
34 |
+
},
|
35 |
+
"beta": {
|
36 |
+
"value": 1.0
|
37 |
+
},
|
38 |
+
"transB": {
|
39 |
+
"value": 1
|
40 |
+
},
|
41 |
+
"/network/network.0/Gemm": {
|
42 |
+
"function": "onnx::Gemm",
|
43 |
+
"args": {
|
44 |
+
"A": "input",
|
45 |
+
"B": "network.0.weight",
|
46 |
+
"C": "network.0.bias"
|
47 |
+
}
|
48 |
+
}
|
49 |
+
},
|
50 |
+
"output_ports": {
|
51 |
+
"_network_network.0_Gemm_output_0": {
|
52 |
+
"value": "/network/network.0/Gemm"
|
53 |
+
}
|
54 |
+
}
|
55 |
+
},
|
56 |
+
"/network/network.1/Relu": {
|
57 |
+
"input_ports": {
|
58 |
+
"_network_network.0_Gemm_output_0": {
|
59 |
+
"shape": [
|
60 |
+
1,
|
61 |
+
64
|
62 |
+
],
|
63 |
+
"type": "float"
|
64 |
+
}
|
65 |
+
},
|
66 |
+
"parameters": {
|
67 |
+
"/network/network.1/Relu": {
|
68 |
+
"function": "onnx::Relu",
|
69 |
+
"args": {
|
70 |
+
"X": "_network_network.0_Gemm_output_0"
|
71 |
+
}
|
72 |
+
}
|
73 |
+
},
|
74 |
+
"output_ports": {
|
75 |
+
"_network_network.1_Relu_output_0": {
|
76 |
+
"value": "/network/network.1/Relu"
|
77 |
+
}
|
78 |
+
}
|
79 |
+
},
|
80 |
+
"/network/network.2/Gemm": {
|
81 |
+
"input_ports": {
|
82 |
+
"_network_network.1_Relu_output_0": {
|
83 |
+
"shape": [
|
84 |
+
1,
|
85 |
+
64
|
86 |
+
],
|
87 |
+
"type": "float"
|
88 |
+
},
|
89 |
+
"network.2.weight": {
|
90 |
+
"shape": [
|
91 |
+
64,
|
92 |
+
64
|
93 |
+
],
|
94 |
+
"type": "float"
|
95 |
+
},
|
96 |
+
"network.2.bias": {
|
97 |
+
"shape": [
|
98 |
+
64
|
99 |
+
],
|
100 |
+
"type": "float"
|
101 |
+
}
|
102 |
+
},
|
103 |
+
"parameters": {
|
104 |
+
"alpha": {
|
105 |
+
"value": 1.0
|
106 |
+
},
|
107 |
+
"beta": {
|
108 |
+
"value": 1.0
|
109 |
+
},
|
110 |
+
"transB": {
|
111 |
+
"value": 1
|
112 |
+
},
|
113 |
+
"/network/network.2/Gemm": {
|
114 |
+
"function": "onnx::Gemm",
|
115 |
+
"args": {
|
116 |
+
"A": "_network_network.1_Relu_output_0",
|
117 |
+
"B": "network.2.weight",
|
118 |
+
"C": "network.2.bias"
|
119 |
+
}
|
120 |
+
}
|
121 |
+
},
|
122 |
+
"output_ports": {
|
123 |
+
"_network_network.2_Gemm_output_0": {
|
124 |
+
"value": "/network/network.2/Gemm"
|
125 |
+
}
|
126 |
+
}
|
127 |
+
},
|
128 |
+
"/network/network.3/Relu": {
|
129 |
+
"input_ports": {
|
130 |
+
"_network_network.2_Gemm_output_0": {
|
131 |
+
"shape": [
|
132 |
+
1,
|
133 |
+
64
|
134 |
+
],
|
135 |
+
"type": "float"
|
136 |
+
}
|
137 |
+
},
|
138 |
+
"parameters": {
|
139 |
+
"/network/network.3/Relu": {
|
140 |
+
"function": "onnx::Relu",
|
141 |
+
"args": {
|
142 |
+
"X": "_network_network.2_Gemm_output_0"
|
143 |
+
}
|
144 |
+
}
|
145 |
+
},
|
146 |
+
"output_ports": {
|
147 |
+
"_network_network.3_Relu_output_0": {
|
148 |
+
"value": "/network/network.3/Relu"
|
149 |
+
}
|
150 |
+
}
|
151 |
+
},
|
152 |
+
"/network/network.4/Gemm": {
|
153 |
+
"input_ports": {
|
154 |
+
"_network_network.3_Relu_output_0": {
|
155 |
+
"shape": [
|
156 |
+
1,
|
157 |
+
64
|
158 |
+
],
|
159 |
+
"type": "float"
|
160 |
+
},
|
161 |
+
"network.4.weight": {
|
162 |
+
"shape": [
|
163 |
+
1,
|
164 |
+
64
|
165 |
+
],
|
166 |
+
"type": "float"
|
167 |
+
},
|
168 |
+
"network.4.bias": {
|
169 |
+
"shape": [
|
170 |
+
1
|
171 |
+
],
|
172 |
+
"type": "float"
|
173 |
+
}
|
174 |
+
},
|
175 |
+
"parameters": {
|
176 |
+
"alpha": {
|
177 |
+
"value": 1.0
|
178 |
+
},
|
179 |
+
"beta": {
|
180 |
+
"value": 1.0
|
181 |
+
},
|
182 |
+
"transB": {
|
183 |
+
"value": 1
|
184 |
+
},
|
185 |
+
"/network/network.4/Gemm": {
|
186 |
+
"function": "onnx::Gemm",
|
187 |
+
"args": {
|
188 |
+
"A": "_network_network.3_Relu_output_0",
|
189 |
+
"B": "network.4.weight",
|
190 |
+
"C": "network.4.bias"
|
191 |
+
}
|
192 |
+
}
|
193 |
+
},
|
194 |
+
"output_ports": {
|
195 |
+
"output": {
|
196 |
+
"value": "/network/network.4/Gemm"
|
197 |
+
}
|
198 |
+
}
|
199 |
+
}
|
200 |
+
},
|
201 |
+
"edges": {
|
202 |
+
"/network/network.0/Gemm._network_network.0_Gemm_output_0_/network/network.1/Relu._network_network.0_Gemm_output_0": {
|
203 |
+
"sender": "/network/network.0/Gemm",
|
204 |
+
"receiver": "/network/network.1/Relu",
|
205 |
+
"sender_port": "_network_network.0_Gemm_output_0",
|
206 |
+
"receiver_port": "_network_network.0_Gemm_output_0"
|
207 |
+
},
|
208 |
+
"/network/network.1/Relu._network_network.1_Relu_output_0_/network/network.2/Gemm._network_network.1_Relu_output_0": {
|
209 |
+
"sender": "/network/network.1/Relu",
|
210 |
+
"receiver": "/network/network.2/Gemm",
|
211 |
+
"sender_port": "_network_network.1_Relu_output_0",
|
212 |
+
"receiver_port": "_network_network.1_Relu_output_0"
|
213 |
+
},
|
214 |
+
"/network/network.2/Gemm._network_network.2_Gemm_output_0_/network/network.3/Relu._network_network.2_Gemm_output_0": {
|
215 |
+
"sender": "/network/network.2/Gemm",
|
216 |
+
"receiver": "/network/network.3/Relu",
|
217 |
+
"sender_port": "_network_network.2_Gemm_output_0",
|
218 |
+
"receiver_port": "_network_network.2_Gemm_output_0"
|
219 |
+
},
|
220 |
+
"/network/network.3/Relu._network_network.3_Relu_output_0_/network/network.4/Gemm._network_network.3_Relu_output_0": {
|
221 |
+
"sender": "/network/network.3/Relu",
|
222 |
+
"receiver": "/network/network.4/Gemm",
|
223 |
+
"sender_port": "_network_network.3_Relu_output_0",
|
224 |
+
"receiver_port": "_network_network.3_Relu_output_0"
|
225 |
+
}
|
226 |
+
}
|
227 |
+
}
|
228 |
+
}
|
229 |
+
}
|
230 |
+
}
|
models/sine_approximator.onnx
ADDED
Binary file (35.9 kB). View file
|
|
models/sine_approximator.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
import numpy as np
|
4 |
+
from modeci_mdf.interfaces.onnx import onnx_to_mdf
|
5 |
+
import streamlit as st
|
6 |
+
import onnx
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
|
9 |
+
class SineApproximator(nn.Module):
|
10 |
+
def __init__(self):
|
11 |
+
super(SineApproximator, self).__init__()
|
12 |
+
self.network = nn.Sequential(
|
13 |
+
nn.Linear(1, 64),
|
14 |
+
|
15 |
+
nn.ReLU(),
|
16 |
+
nn.Linear(64, 64),
|
17 |
+
nn.ReLU(),
|
18 |
+
nn.Linear(64, 1)
|
19 |
+
)
|
20 |
+
|
21 |
+
def forward(self, x):
|
22 |
+
return self.network(x)
|
23 |
+
|
24 |
+
def train_sine_model(model, epochs=1000, learning_rate=0.01):
|
25 |
+
X = torch.unsqueeze(torch.linspace(-np.pi, np.pi, 200), dim=1)
|
26 |
+
Y = torch.sin(X)
|
27 |
+
|
28 |
+
loss_func = nn.MSELoss()
|
29 |
+
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
|
30 |
+
|
31 |
+
for epoch in range(epochs):
|
32 |
+
prediction = model(X)
|
33 |
+
loss = loss_func(prediction, Y)
|
34 |
+
|
35 |
+
optimizer.zero_grad()
|
36 |
+
loss.backward()
|
37 |
+
optimizer.step()
|
38 |
+
|
39 |
+
if epoch % 100 == 0:
|
40 |
+
print(f'Epoch {epoch}, Loss {loss.item()}')
|
41 |
+
|
42 |
+
print("Training complete.")
|
43 |
+
|
44 |
+
def export_to_onnx(model):
|
45 |
+
dummy_input = torch.tensor([[0.0]]) # Example input to trace the model
|
46 |
+
torch.onnx.export(model, dummy_input, "sine_approximator.onnx", verbose=True,
|
47 |
+
input_names=["input"], output_names=["output"])
|
48 |
+
|
49 |
+
model = SineApproximator()
|
50 |
+
train_sine_model(model)
|
51 |
+
export_to_onnx(model)
|
52 |
+
|
53 |
+
def plot_sine_curve(model):
|
54 |
+
# Generate inputs and true sine values
|
55 |
+
x_values = torch.unsqueeze(torch.linspace(-np.pi, np.pi, 200), dim=1)
|
56 |
+
sine_values = torch.sin(x_values)
|
57 |
+
|
58 |
+
# Model predictions
|
59 |
+
with torch.no_grad(): # We don't need gradients for prediction
|
60 |
+
predicted_sine_values = model(x_values)
|
61 |
+
|
62 |
+
# Plotting
|
63 |
+
plt.figure(figsize=(10, 6))
|
64 |
+
plt.plot(x_values.numpy(), sine_values.numpy(), label='True Sine Curve')
|
65 |
+
plt.plot(x_values.numpy(), predicted_sine_values.numpy(), label='Model Approximation', linestyle='--')
|
66 |
+
plt.xlabel('Input Value')
|
67 |
+
plt.ylabel('Sine Value')
|
68 |
+
plt.title('Sine Function Approximation by Neural Network')
|
69 |
+
plt.legend()
|
70 |
+
plt.show()
|
71 |
+
|
72 |
+
|
73 |
+
verbose = True
|
74 |
+
|
75 |
+
# Load the ONNX model
|
76 |
+
onnx_model = onnx.load("sine_approximator.onnx")
|
77 |
+
|
78 |
+
# Convert to MDF
|
79 |
+
mdf_model = onnx_to_mdf(onnx_model)
|
80 |
+
|
81 |
+
# Optionally, save to JSON or YAML
|
82 |
+
mdf_model.to_json_file("sine_approximator.json")
|
83 |
+
mdf_model.to_yaml_file("sine_approximator.yaml")
|
84 |
+
mdf_model.to_graph_image(
|
85 |
+
engine="dot",
|
86 |
+
output_format="png",
|
87 |
+
)
|
88 |
+
plot_sine_curve(model)
|
89 |
+
print("Conversion to MDF complete. Files saved as sine_approximator.json and sine_approximator.yaml")
|
models/sine_approximator.yaml
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ONNX Model:
|
2 |
+
format: ModECI MDF v0.4
|
3 |
+
generating_application: Python modeci-mdf v0.4.9
|
4 |
+
graphs:
|
5 |
+
main_graph:
|
6 |
+
nodes:
|
7 |
+
/network/network.0/Gemm:
|
8 |
+
input_ports:
|
9 |
+
input:
|
10 |
+
shape:
|
11 |
+
- 1
|
12 |
+
- 1
|
13 |
+
type: float
|
14 |
+
network.0.weight:
|
15 |
+
shape:
|
16 |
+
- 64
|
17 |
+
- 1
|
18 |
+
type: float
|
19 |
+
network.0.bias:
|
20 |
+
shape:
|
21 |
+
- 64
|
22 |
+
type: float
|
23 |
+
parameters:
|
24 |
+
alpha:
|
25 |
+
value: 1.0
|
26 |
+
beta:
|
27 |
+
value: 1.0
|
28 |
+
transB:
|
29 |
+
value: 1
|
30 |
+
/network/network.0/Gemm:
|
31 |
+
function: onnx::Gemm
|
32 |
+
args:
|
33 |
+
A: input
|
34 |
+
B: network.0.weight
|
35 |
+
C: network.0.bias
|
36 |
+
output_ports:
|
37 |
+
_network_network.0_Gemm_output_0:
|
38 |
+
value: /network/network.0/Gemm
|
39 |
+
/network/network.1/Relu:
|
40 |
+
input_ports:
|
41 |
+
_network_network.0_Gemm_output_0:
|
42 |
+
shape:
|
43 |
+
- 1
|
44 |
+
- 64
|
45 |
+
type: float
|
46 |
+
parameters:
|
47 |
+
/network/network.1/Relu:
|
48 |
+
function: onnx::Relu
|
49 |
+
args:
|
50 |
+
X: _network_network.0_Gemm_output_0
|
51 |
+
output_ports:
|
52 |
+
_network_network.1_Relu_output_0:
|
53 |
+
value: /network/network.1/Relu
|
54 |
+
/network/network.2/Gemm:
|
55 |
+
input_ports:
|
56 |
+
_network_network.1_Relu_output_0:
|
57 |
+
shape:
|
58 |
+
- 1
|
59 |
+
- 64
|
60 |
+
type: float
|
61 |
+
network.2.weight:
|
62 |
+
shape:
|
63 |
+
- 64
|
64 |
+
- 64
|
65 |
+
type: float
|
66 |
+
network.2.bias:
|
67 |
+
shape:
|
68 |
+
- 64
|
69 |
+
type: float
|
70 |
+
parameters:
|
71 |
+
alpha:
|
72 |
+
value: 1.0
|
73 |
+
beta:
|
74 |
+
value: 1.0
|
75 |
+
transB:
|
76 |
+
value: 1
|
77 |
+
/network/network.2/Gemm:
|
78 |
+
function: onnx::Gemm
|
79 |
+
args:
|
80 |
+
A: _network_network.1_Relu_output_0
|
81 |
+
B: network.2.weight
|
82 |
+
C: network.2.bias
|
83 |
+
output_ports:
|
84 |
+
_network_network.2_Gemm_output_0:
|
85 |
+
value: /network/network.2/Gemm
|
86 |
+
/network/network.3/Relu:
|
87 |
+
input_ports:
|
88 |
+
_network_network.2_Gemm_output_0:
|
89 |
+
shape:
|
90 |
+
- 1
|
91 |
+
- 64
|
92 |
+
type: float
|
93 |
+
parameters:
|
94 |
+
/network/network.3/Relu:
|
95 |
+
function: onnx::Relu
|
96 |
+
args:
|
97 |
+
X: _network_network.2_Gemm_output_0
|
98 |
+
output_ports:
|
99 |
+
_network_network.3_Relu_output_0:
|
100 |
+
value: /network/network.3/Relu
|
101 |
+
/network/network.4/Gemm:
|
102 |
+
input_ports:
|
103 |
+
_network_network.3_Relu_output_0:
|
104 |
+
shape:
|
105 |
+
- 1
|
106 |
+
- 64
|
107 |
+
type: float
|
108 |
+
network.4.weight:
|
109 |
+
shape:
|
110 |
+
- 1
|
111 |
+
- 64
|
112 |
+
type: float
|
113 |
+
network.4.bias:
|
114 |
+
shape:
|
115 |
+
- 1
|
116 |
+
type: float
|
117 |
+
parameters:
|
118 |
+
alpha:
|
119 |
+
value: 1.0
|
120 |
+
beta:
|
121 |
+
value: 1.0
|
122 |
+
transB:
|
123 |
+
value: 1
|
124 |
+
/network/network.4/Gemm:
|
125 |
+
function: onnx::Gemm
|
126 |
+
args:
|
127 |
+
A: _network_network.3_Relu_output_0
|
128 |
+
B: network.4.weight
|
129 |
+
C: network.4.bias
|
130 |
+
output_ports:
|
131 |
+
output:
|
132 |
+
value: /network/network.4/Gemm
|
133 |
+
edges:
|
134 |
+
/network/network.0/Gemm._network_network.0_Gemm_output_0_/network/network.1/Relu._network_network.0_Gemm_output_0:
|
135 |
+
sender: /network/network.0/Gemm
|
136 |
+
receiver: /network/network.1/Relu
|
137 |
+
sender_port: _network_network.0_Gemm_output_0
|
138 |
+
receiver_port: _network_network.0_Gemm_output_0
|
139 |
+
/network/network.1/Relu._network_network.1_Relu_output_0_/network/network.2/Gemm._network_network.1_Relu_output_0:
|
140 |
+
sender: /network/network.1/Relu
|
141 |
+
receiver: /network/network.2/Gemm
|
142 |
+
sender_port: _network_network.1_Relu_output_0
|
143 |
+
receiver_port: _network_network.1_Relu_output_0
|
144 |
+
/network/network.2/Gemm._network_network.2_Gemm_output_0_/network/network.3/Relu._network_network.2_Gemm_output_0:
|
145 |
+
sender: /network/network.2/Gemm
|
146 |
+
receiver: /network/network.3/Relu
|
147 |
+
sender_port: _network_network.2_Gemm_output_0
|
148 |
+
receiver_port: _network_network.2_Gemm_output_0
|
149 |
+
/network/network.3/Relu._network_network.3_Relu_output_0_/network/network.4/Gemm._network_network.3_Relu_output_0:
|
150 |
+
sender: /network/network.3/Relu
|
151 |
+
receiver: /network/network.4/Gemm
|
152 |
+
sender_port: _network_network.3_Relu_output_0
|
153 |
+
receiver_port: _network_network.3_Relu_output_0
|
models/sine_approximator_model
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
digraph main_graph {
|
2 |
+
graph [rankdir=LR]
|
3 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
4 |
+
"/network/network.0/Gemm" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.0/Gemm</b></td></tr><tr><td><font color="#188855">input</font> (shape: (1, 1), type: float)</td></tr><tr><td><font color="#188855">network.0.weight</font> (shape: (64, 1), type: float)</td></tr><tr><td><font color="#188855">network.0.bias</font> (shape: (64,), type: float)</td></tr><tr><td><font color="#1666ff">alpha</font> = 1.0</td></tr><tr><td><font color="#1666ff">beta</font> = 1.0</td></tr><tr><td><font color="#1666ff">transB</font> = 1</td></tr><tr><td><font color="#1666ff">/network/network.0/Gemm</font> = <i>onnx::Gemm</i>(<font color="#188855">input</font>, <font color="#188855">network.0.weight</font>, <font color="#188855">network.0.bias</font>)</td></tr><tr><td><font color="#cc3355">_network_network.0_Gemm_output_0</font> = <font color="#1666ff">/network/network.0/Gemm</font> </td></tr></table>>]
|
5 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
6 |
+
"/network/network.1/Relu" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.1/Relu</b></td></tr><tr><td><font color="#188855">_network_network.0_Gemm_output_0</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#1666ff">/network/network.1/Relu</font> = <i>onnx::Relu</i>(<font color="#188855">_network_network.0_Gemm_output_0</font>)</td></tr><tr><td><font color="#cc3355">_network_network.1_Relu_output_0</font> = <font color="#1666ff">/network/network.1/Relu</font> </td></tr></table>>]
|
7 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
8 |
+
"/network/network.2/Gemm" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.2/Gemm</b></td></tr><tr><td><font color="#188855">_network_network.1_Relu_output_0</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#188855">network.2.weight</font> (shape: (64, 64), type: float)</td></tr><tr><td><font color="#188855">network.2.bias</font> (shape: (64,), type: float)</td></tr><tr><td><font color="#1666ff">alpha</font> = 1.0</td></tr><tr><td><font color="#1666ff">beta</font> = 1.0</td></tr><tr><td><font color="#1666ff">transB</font> = 1</td></tr><tr><td><font color="#1666ff">/network/network.2/Gemm</font> = <i>onnx::Gemm</i>(<font color="#188855">_network_network.1_Relu_output_0</font>, <font color="#188855">network.2.weight</font>, <font color="#188855">network.2.bias</font>)</td></tr><tr><td><font color="#cc3355">_network_network.2_Gemm_output_0</font> = <font color="#1666ff">/network/network.2/Gemm</font> </td></tr></table>>]
|
9 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
10 |
+
"/network/network.3/Relu" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.3/Relu</b></td></tr><tr><td><font color="#188855">_network_network.2_Gemm_output_0</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#1666ff">/network/network.3/Relu</font> = <i>onnx::Relu</i>(<font color="#188855">_network_network.2_Gemm_output_0</font>)</td></tr><tr><td><font color="#cc3355">_network_network.3_Relu_output_0</font> = <font color="#1666ff">/network/network.3/Relu</font> </td></tr></table>>]
|
11 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
12 |
+
"/network/network.4/Gemm" [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>/network/network.4/Gemm</b></td></tr><tr><td><font color="#188855">_network_network.3_Relu_output_0</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#188855">network.4.weight</font> (shape: (1, 64), type: float)</td></tr><tr><td><font color="#188855">network.4.bias</font> (shape: (1,), type: float)</td></tr><tr><td><font color="#1666ff">alpha</font> = 1.0</td></tr><tr><td><font color="#1666ff">beta</font> = 1.0</td></tr><tr><td><font color="#1666ff">transB</font> = 1</td></tr><tr><td><font color="#1666ff">/network/network.4/Gemm</font> = <i>onnx::Gemm</i>(<font color="#188855">_network_network.3_Relu_output_0</font>, <font color="#188855">network.4.weight</font>, <font color="#188855">network.4.bias</font>)</td></tr><tr><td><font color="#cc3355">output</font> = <font color="#1666ff">/network/network.4/Gemm</font> </td></tr></table>>]
|
13 |
+
"/network/network.0/Gemm" -> "/network/network.1/Relu" [label=</network/network.0/Gemm._network_network.0_Gemm_output_0_/network/network.1/Relu._network_network.0_Gemm_output_0 (<font color="#cc3355">_network_network.0_Gemm_output_0</font> -> <font color="#188855">_network_network.0_Gemm_output_0</font>)> arrowhead=empty]
|
14 |
+
"/network/network.1/Relu" -> "/network/network.2/Gemm" [label=</network/network.1/Relu._network_network.1_Relu_output_0_/network/network.2/Gemm._network_network.1_Relu_output_0 (<font color="#cc3355">_network_network.1_Relu_output_0</font> -> <font color="#188855">_network_network.1_Relu_output_0</font>)> arrowhead=empty]
|
15 |
+
"/network/network.2/Gemm" -> "/network/network.3/Relu" [label=</network/network.2/Gemm._network_network.2_Gemm_output_0_/network/network.3/Relu._network_network.2_Gemm_output_0 (<font color="#cc3355">_network_network.2_Gemm_output_0</font> -> <font color="#188855">_network_network.2_Gemm_output_0</font>)> arrowhead=empty]
|
16 |
+
"/network/network.3/Relu" -> "/network/network.4/Gemm" [label=</network/network.3/Relu._network_network.3_Relu_output_0_/network/network.4/Gemm._network_network.3_Relu_output_0 (<font color="#cc3355">_network_network.3_Relu_output_0</font> -> <font color="#188855">_network_network.3_Relu_output_0</font>)> arrowhead=empty]
|
17 |
+
}
|
models/sine_approximator_model.png
ADDED
models/sir_model
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
digraph arc_functions {
|
2 |
+
graph [rankdir=LR]
|
3 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
4 |
+
arctan_node [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>arctan_node</b></td></tr><tr><td><font color="#1666ff">input_value</font> = 1.0</td></tr><tr><td><font color="#1666ff">arctan_result</font> = <i>arctan</i>(<font color="#1666ff">input_value</font>, 0.4)</td></tr><tr><td><i>arctan(variable0, scale) = scale * arctan(variable0)</i></td></tr><tr><td><font color="#cc3355">output</font> = <font color="#1666ff">arctan_result</font> </td></tr></table>>]
|
5 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
6 |
+
arccos_node [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>arccos_node</b></td></tr><tr><td><font color="#188855">input_from_arctan</font> </td></tr><tr><td><font color="#1666ff">arccos_result</font> = <i>arccos</i>(<font color="#188855">input_from_arctan</font>, 0.3)</td></tr><tr><td><i>arccos(variable0, scale) = scale * arccos(variable0)</i></td></tr><tr><td><font color="#cc3355">output</font> = <font color="#1666ff">arccos_result</font> </td></tr></table>>]
|
7 |
+
node [color="#444444" fontcolor="#444444" penwidth=1 shape=box style=rounded]
|
8 |
+
arcsin_node [label=<<table border="0" cellborder="0"><tr><td colspan="2"><b>arcsin_node</b></td></tr><tr><td><font color="#188855">input_from_arccos</font> </td></tr><tr><td><font color="#1666ff">arcsin_result</font> = <i>arcsin</i>(<font color="#188855">input_from_arccos</font>, 0.2)</td></tr><tr><td><i>arcsin(variable0, scale) = scale * arcsin(variable0)</i></td></tr><tr><td><font color="#cc3355">output</font> = <font color="#1666ff">arcsin_result</font> </td></tr></table>>]
|
9 |
+
arctan_node -> arccos_node [label=<h (<font color="#cc3355">output</font> -> <font color="#188855">input_from_arctan</font>)> arrowhead=empty]
|
10 |
+
arccos_node -> arcsin_node [label=<i (<font color="#cc3355">output</font> -> <font color="#188855">input_from_arccos</font>)> arrowhead=empty]
|
11 |
+
}
|
models/sir_model.png
ADDED
pages/NLC.py
DELETED
@@ -1,107 +0,0 @@
|
|
1 |
-
from modeci_mdf.mdf import Model, Graph, Node, Parameter, OutputPort
|
2 |
-
import sys
|
3 |
-
import streamlit as st
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
-
|
6 |
-
def run_simulation(mod_graph, duration=100, dt=0.1):
|
7 |
-
from modeci_mdf.execution_engine import EvaluableGraph
|
8 |
-
|
9 |
-
eg = EvaluableGraph(mod_graph)
|
10 |
-
t = 0
|
11 |
-
times = []
|
12 |
-
temperatures = []
|
13 |
-
while t <= duration:
|
14 |
-
times.append(t)
|
15 |
-
if t == 0:
|
16 |
-
eg.evaluate()
|
17 |
-
else:
|
18 |
-
eg.evaluate(time_increment=dt)
|
19 |
-
temperatures.append(eg.enodes["node1"].evaluable_outputs["out_port"].curr_value)
|
20 |
-
t += dt
|
21 |
-
print(f"Time: {t:.1f}, Temperature: {temperatures[-1]:.3f}")
|
22 |
-
return times, temperatures
|
23 |
-
|
24 |
-
def main():
|
25 |
-
st.title("Newton Cooling Model Simulator")
|
26 |
-
with open('./markdowns/css.md', 'r') as file:
|
27 |
-
custom_styles = file.read()
|
28 |
-
st.markdown(custom_styles, unsafe_allow_html=True)
|
29 |
-
|
30 |
-
if 'page' not in st.session_state:
|
31 |
-
st.session_state.page = 'main'
|
32 |
-
|
33 |
-
if 'mod_graph' not in st.session_state:
|
34 |
-
mod = Model(id="NewtonCoolingModel")
|
35 |
-
mod_graph = Graph(id="cooling_process")
|
36 |
-
mod.graphs.append(mod_graph)
|
37 |
-
|
38 |
-
node1 = Node(id="node1")
|
39 |
-
node1.parameters.append(Parameter(id="cooling_coeff", value=0.1))
|
40 |
-
node1.parameters.append(Parameter(id="T_a", value=20))
|
41 |
-
s1 = Parameter(
|
42 |
-
id="T_curr", default_initial_value=90, time_derivative="dT_dt"
|
43 |
-
)
|
44 |
-
node1.parameters.append(s1)
|
45 |
-
s2 = Parameter(
|
46 |
-
id="dT_dt",
|
47 |
-
default_initial_value=0,
|
48 |
-
value="-cooling_coeff*(T_curr - T_a)",
|
49 |
-
)
|
50 |
-
node1.parameters.append(s2)
|
51 |
-
op1 = OutputPort(id="out_port", value="T_curr")
|
52 |
-
node1.output_ports.append(op1)
|
53 |
-
|
54 |
-
mod_graph.nodes.append(node1)
|
55 |
-
|
56 |
-
st.session_state.mod_graph = mod_graph
|
57 |
-
|
58 |
-
if st.session_state.page == 'main':
|
59 |
-
display_main_page()
|
60 |
-
elif st.session_state.page == 'custom_params':
|
61 |
-
display_custom_params_page()
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
def display_main_page():
|
67 |
-
with open('./markdowns/introduction.md', 'r') as file:
|
68 |
-
introduction = file.read()
|
69 |
-
st.markdown(introduction)
|
70 |
-
mod_graph = st.session_state.mod_graph
|
71 |
-
if st.button("Run Simulation"):
|
72 |
-
times, temperatures = run_simulation(mod_graph)
|
73 |
-
times = times[1:]
|
74 |
-
temperatures = temperatures[1:]
|
75 |
-
st.line_chart(list(zip(temperatures)), use_container_width=True, height=400)
|
76 |
-
pass
|
77 |
-
if st.button("Try Custom Parameters?"):
|
78 |
-
st.session_state.page = 'custom_params'
|
79 |
-
pass
|
80 |
-
|
81 |
-
def display_custom_params_page():
|
82 |
-
st.write("Customize the parameters of the Newton Cooling Model")
|
83 |
-
mod_graph = st.session_state.mod_graph
|
84 |
-
|
85 |
-
# Create a form for your inputs and the button
|
86 |
-
with st.form("parameter_form"):
|
87 |
-
col1, col2 = st.columns(2)
|
88 |
-
with col1:
|
89 |
-
cooling_coeff = st.number_input("Cooling Coefficient", value=0.1)
|
90 |
-
T_a = st.number_input("Ambient Temperature", value=20)
|
91 |
-
with col2:
|
92 |
-
duration = st.number_input("Duration", value=100)
|
93 |
-
dt = st.number_input("Time Step", value=0.1)
|
94 |
-
|
95 |
-
# Form submit button returns True upon form submission
|
96 |
-
submitted = st.form_submit_button("Run Simulation")
|
97 |
-
|
98 |
-
# Check if the form has been submitted
|
99 |
-
if submitted:
|
100 |
-
times, temperatures = run_simulation(mod_graph, duration, dt)
|
101 |
-
times = times[1:] # adjust based on your needs
|
102 |
-
temperatures = temperatures[1:] # adjust based on your needs
|
103 |
-
st.line_chart(list(zip(temperatures)), use_container_width=True, height=400)
|
104 |
-
|
105 |
-
if __name__ == "__main__":
|
106 |
-
main()
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,3 +1,5 @@
|
|
1 |
modeci_mdf
|
2 |
streamlit==1.8.0
|
3 |
matplotlib==3.5.1
|
|
|
|
|
|
1 |
modeci_mdf
|
2 |
streamlit==1.8.0
|
3 |
matplotlib==3.5.1
|
4 |
+
graphviz
|
5 |
+
ipython
|