Rimjhim Mittal commited on
Commit
b95e413
·
1 Parent(s): c4d242b

made UI changes

Browse files
app.py CHANGED
@@ -1,11 +1,19 @@
1
  import streamlit as st, pandas as pd, os, io
2
  from modeci_mdf.mdf import Model, Graph, Node, Parameter, OutputPort
3
  from modeci_mdf.utils import load_mdf_json, load_mdf, load_mdf_yaml
4
- from modeci_mdf.execution_engine import EvaluableGraph
5
  import json
6
- st.set_page_config(layout="wide")
7
- st.title("🔋 MDF Simulator")
8
  import requests
 
 
 
 
 
 
 
 
 
 
9
  # models: Purpose: To store the state of the model and update the model
10
  def run_simulation(param_inputs, mdf_model):
11
  mod_graph = mdf_model.graphs[0]
@@ -14,8 +22,10 @@ def run_simulation(param_inputs, mdf_model):
14
  parameters = node.parameters
15
  outputs = node.output_ports
16
  eg = EvaluableGraph(mod_graph, verbose=False)
 
17
  duration = param_inputs["Simulation Duration (s)"]
18
  dt = param_inputs["Time Step (s)"]
 
19
  t = 0
20
  times = []
21
  output_values = {op.value: [] for op in outputs}
@@ -27,25 +37,27 @@ def run_simulation(param_inputs, mdf_model):
27
  eg.evaluate(time_increment=dt)
28
 
29
  for param in output_values:
30
- eval_param = eg.enodes[node.id].evaluable_parameters[param]
 
 
 
 
31
  output_values[param].append(eval_param.curr_value)
32
  t += dt
33
  chart_data = pd.DataFrame(output_values)
34
  chart_data['Time'] = times
35
  chart_data.set_index('Time', inplace=True)
36
- return chart_data
37
-
38
  # views: Purpose: To display the state of the model
39
  def show_simulation_results(chart_data):
40
  st.line_chart(chart_data, use_container_width=True, height=400)
41
- st.write("Output Values")
42
- st.write(chart_data)
43
 
44
  def show_mdf_graph(mdf_model):
45
  st.subheader("MDF Graph")
46
  mdf_model.to_graph_image(engine="dot", output_format="png", view_on_render=False, level=3, filename_root=mdf_model.id, only_warn_on_fail=(os.name == "nt"))
47
  image_path = mdf_model.id + ".png"
48
- st.image(image_path, caption="Model Graph Visualization")
49
 
50
  def show_json_output(mdf_model):
51
  st.subheader("JSON Output")
@@ -54,16 +66,16 @@ def show_json_output(mdf_model):
54
  def view_tabs(mdf_model, param_inputs): # view
55
  tab1, tab2, tab3 = st.tabs(["Simulation Results", "MDF Graph", "Json Output"])
56
  with tab1:
57
- mod_graph = mdf_model.graphs[0]
58
- nodes = mod_graph.nodes
59
- for node in nodes:
60
- st.write("Node Name: ", node.id)
61
- node_parameters = {}
62
- for param in node.parameters:
63
- node_parameters[param.id] = node_parameters[param.id] = param.value if param.value else param.time_derivative
64
- st.write("Node Parameters: ", node_parameters)
65
- chart_data = run_simulation(param_inputs, mdf_model) # model
66
- show_simulation_results(chart_data) # view
67
  with tab2:
68
  show_mdf_graph(mdf_model) # view
69
  with tab3:
@@ -72,21 +84,22 @@ def view_tabs(mdf_model, param_inputs): # view
72
  def parameter_form_to_update_model_and_view(mdf_model, parameters, param_inputs, mod_graph, nodes):
73
  form = st.form(key="parameter_form")
74
  valid_inputs = True
75
-
76
- for i, param in enumerate(parameters):
77
- if isinstance(param.value, str) or param.value is None:
78
- continue
79
- key = f"{param.id}_{i}"
80
- if mdf_model.metadata:
81
- value = form.text_input(f"{param.metadata.get('description', param.id)} ({param.id})", value=str(param.value), key=key)
82
- else:
83
- value = form.text_input(f"{param.id}", value=str(param.value), key=key)
84
-
85
- try:
86
- param_inputs[param.id] = float(value)
87
- except ValueError:
88
- st.error(f"Invalid input for {param.id}. Please enter a valid number.")
89
- valid_inputs = False
 
90
 
91
  sim_duration = form.text_input("Simulation Duration (s)", value=str(param_inputs["Simulation Duration (s)"]), key="sim_duration")
92
  time_step = form.text_input("Time Step (s)", value=str(param_inputs["Time Step (s)"]), key="time_step")
@@ -105,41 +118,107 @@ def parameter_form_to_update_model_and_view(mdf_model, parameters, param_inputs,
105
  run_button = form.form_submit_button("Run Simulation")
106
  if run_button:
107
  if valid_inputs:
108
- for param in parameters:
109
- if param.id in param_inputs:
110
- param.value = param_inputs[param.id]
 
111
  view_tabs(mdf_model, param_inputs)
112
  # else:
113
  # st.error("Please correct the invalid inputs before running the simulation.")
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  def upload_file_and_load_to_model():
117
- st.write("Choose how to load the model:")
118
- load_option = st.radio("", ("Upload File", "GitHub URL"))
119
-
120
- if load_option == "Upload File":
121
- uploaded_file = st.file_uploader("Choose a JSON/YAML/BSON file", type=["json", "yaml", "bson"])
122
- if uploaded_file is not None:
123
- file_content = uploaded_file.getvalue()
124
- file_extension = uploaded_file.name.split('.')[-1].lower()
 
 
 
 
 
 
125
  return load_model_from_content(file_content, file_extension)
126
- else:
127
- st.write("sample_github_url = https://raw.githubusercontent.com/ModECI/MDF/development/examples/MDF/NewtonCoolingModel.json")
128
- github_url = st.text_input("Enter GitHub raw file URL:", placeholder="Enter GitHub raw file URL")
129
- if github_url:
130
- try:
131
- response = requests.get(github_url)
132
- response.raise_for_status()
133
- file_content = response.content
134
- # print(file_content)
135
- file_extension = github_url.split('.')[-1].lower()
136
- return load_model_from_content(file_content, file_extension)
137
- except requests.RequestException as e:
138
- st.error(f"Error loading file from GitHub: {e}")
139
- return None
140
-
 
 
 
 
 
 
 
 
 
141
  return None
142
 
 
143
  def load_model_from_content(file_content, file_extension):
144
  try:
145
  if file_extension == 'json':
@@ -160,14 +239,14 @@ def load_model_from_content(file_content, file_extension):
160
 
161
 
162
  def main():
163
- st.write("Text box changed to input. Github URL is allowed. Added some warnings eg. on adding text in input fields. Now working on multiple parameters allow.")
164
  mdf_model = upload_file_and_load_to_model() # controller
165
  if mdf_model:
166
  mod_graph = mdf_model.graphs[0]
167
  nodes = mod_graph.nodes
 
168
  for node in nodes:
169
- parameters = node.parameters
170
- param_inputs = {}
171
  if mdf_model.metadata:
172
  preferred_duration = float(mdf_model.metadata.get("preferred_duration", 10))
173
  preferred_dt = float(mdf_model.metadata.get("preferred_dt", 0.1))
 
1
  import streamlit as st, pandas as pd, os, io
2
  from modeci_mdf.mdf import Model, Graph, Node, Parameter, OutputPort
3
  from modeci_mdf.utils import load_mdf_json, load_mdf, load_mdf_yaml
4
+ from modeci_mdf.execution_engine import EvaluableGraph, EvaluableOutput
5
  import json
 
 
6
  import requests
7
+ st.set_page_config(layout="wide", page_icon="logo.png", page_title="Model Description Format", menu_items={
8
+ 'Report a bug': "https://github.com/ModECI/MDF/",
9
+ 'About': "ModECI (Model Exchange and Convergence Initiative) is a multi-investigator collaboration that aims to develop a standardized format for exchanging computational models across diverse software platforms and domains of scientific research and technology development, with a particular focus on neuroscience, Machine Learning and Artificial Intelligence. Refer to https://modeci.org/ for more."
10
+ })
11
+ header1, header2 = st.columns([1,12], vertical_alignment="top")
12
+ with header1:
13
+ st.image("logo.png", width=100)
14
+ with header2:
15
+ st.title("Welcome to Model Description Format")
16
+ st.write("Lets get started! Choose one of the following methods.")
17
  # models: Purpose: To store the state of the model and update the model
18
  def run_simulation(param_inputs, mdf_model):
19
  mod_graph = mdf_model.graphs[0]
 
22
  parameters = node.parameters
23
  outputs = node.output_ports
24
  eg = EvaluableGraph(mod_graph, verbose=False)
25
+ # eo = EvaluableOutput(mod_graph, verbose=)
26
  duration = param_inputs["Simulation Duration (s)"]
27
  dt = param_inputs["Time Step (s)"]
28
+ print("hi me param_inputs inside run simulation", param_inputs)
29
  t = 0
30
  times = []
31
  output_values = {op.value: [] for op in outputs}
 
37
  eg.evaluate(time_increment=dt)
38
 
39
  for param in output_values:
40
+ if any(operator in param for operator in "+-/*"):
41
+ eval_param = eg.enodes[node.id].evaluable_outputs[param]
42
+
43
+ else:
44
+ eval_param = eg.enodes[node.id].evaluable_parameters[param]
45
  output_values[param].append(eval_param.curr_value)
46
  t += dt
47
  chart_data = pd.DataFrame(output_values)
48
  chart_data['Time'] = times
49
  chart_data.set_index('Time', inplace=True)
50
+ show_simulation_results(chart_data)
51
+ return None
52
  # views: Purpose: To display the state of the model
53
  def show_simulation_results(chart_data):
54
  st.line_chart(chart_data, use_container_width=True, height=400)
 
 
55
 
56
  def show_mdf_graph(mdf_model):
57
  st.subheader("MDF Graph")
58
  mdf_model.to_graph_image(engine="dot", output_format="png", view_on_render=False, level=3, filename_root=mdf_model.id, only_warn_on_fail=(os.name == "nt"))
59
  image_path = mdf_model.id + ".png"
60
+ st.sidebar.image(image_path, caption="Model Graph Visualization")
61
 
62
  def show_json_output(mdf_model):
63
  st.subheader("JSON Output")
 
66
  def view_tabs(mdf_model, param_inputs): # view
67
  tab1, tab2, tab3 = st.tabs(["Simulation Results", "MDF Graph", "Json Output"])
68
  with tab1:
69
+ # mod_graph = mdf_model.graphs[0]
70
+ # nodes = mod_graph.nodes
71
+ # for node in nodes:
72
+ # st.write("Node Name: ", node.id)
73
+ # node_parameters = {}
74
+ # for param in node.parameters:
75
+ # node_parameters[param.id] = node_parameters[param.id] = param.value if param.value else param.time_derivative
76
+ # st.write("Node Parameters: ", node_parameters)
77
+ run_simulation(param_inputs, mdf_model) # model
78
+ # show_simulation_results(chart_data) # view
79
  with tab2:
80
  show_mdf_graph(mdf_model) # view
81
  with tab3:
 
84
  def parameter_form_to_update_model_and_view(mdf_model, parameters, param_inputs, mod_graph, nodes):
85
  form = st.form(key="parameter_form")
86
  valid_inputs = True
87
+ for node_wise_parameter_key, node_wise_parameter in enumerate(parameters):
88
+ # st.write("hi i am b", node_wise_parameter)
89
+ for i, param in enumerate(node_wise_parameter):
90
+ if isinstance(param.value, str) or param.value is None:
91
+ continue
92
+ key = f"{param.id}_{i}"
93
+ if mdf_model.metadata:
94
+ value = form.text_input(f"{param.metadata.get('description', param.id)} ({param.id})", value=str(param.value), key=key)
95
+ else:
96
+ value = form.text_input(f"{param.id}", value=str(param.value), key=key)
97
+
98
+ try:
99
+ param_inputs[param.id] = float(value)
100
+ except ValueError:
101
+ st.error(f"Invalid input for {param.id}. Please enter a valid number.")
102
+ valid_inputs = False
103
 
104
  sim_duration = form.text_input("Simulation Duration (s)", value=str(param_inputs["Simulation Duration (s)"]), key="sim_duration")
105
  time_step = form.text_input("Time Step (s)", value=str(param_inputs["Time Step (s)"]), key="time_step")
 
118
  run_button = form.form_submit_button("Run Simulation")
119
  if run_button:
120
  if valid_inputs:
121
+ for b in parameters:
122
+ for param in b:
123
+ if param.id in param_inputs:
124
+ param.value = param_inputs[param.id]
125
  view_tabs(mdf_model, param_inputs)
126
  # else:
127
  # st.error("Please correct the invalid inputs before running the simulation.")
128
 
129
+ # def upload_file_and_load_to_model():
130
+ # st.write("Choose how to load the model:")
131
+ # load_option = st.radio("", ("Upload File", "GitHub URL", "Example Models"), )
132
+ # st.write("Choose how to load the model:")
133
+ # if load_option == "Upload File":
134
+ # uploaded_file = st.file_uploader("Choose a JSON/YAML/BSON file", type=["json", "yaml", "bson"])
135
+ # if uploaded_file is not None:
136
+ # file_content = uploaded_file.getvalue()
137
+ # file_extension = uploaded_file.name.split('.')[-1].lower()
138
+ # return load_model_from_content(file_content, file_extension)
139
+
140
+ # elif load_option == "GitHub URL":
141
+ # st.write("sample_github_url = https://raw.githubusercontent.com/ModECI/MDF/development/examples/MDF/NewtonCoolingModel.json")
142
+ # github_url = st.text_input("Enter GitHub raw file URL:", placeholder="Enter GitHub raw file URL")
143
+ # if github_url:
144
+ # try:
145
+ # response = requests.get(github_url)
146
+ # response.raise_for_status()
147
+ # file_content = response.content
148
+ # file_extension = github_url.split('.')[-1].lower()
149
+ # return load_model_from_content(file_content, file_extension)
150
+ # except requests.RequestException as e:
151
+ # st.error(f"Error loading file from GitHub: {e}")
152
+ # return None
153
+
154
+ # elif load_option == "Example Models":
155
+ # example_models = {
156
+ # "Newton Cooling Model": "https://raw.githubusercontent.com/ModECI/MDF/development/examples/MDF/NewtonCoolingModel.json",
157
+ # "ABCD": "https://raw.githubusercontent.com/ModECI/MDF/main/examples/MDF/ABCD.json",
158
+ # "FN": "https://raw.githubusercontent.com/ModECI/MDF/main/examples/MDF/FN.mdf.json",
159
+ # "States": "https://raw.githubusercontent.com/ModECI/MDF/main/examples/MDF/States.json",
160
+ # "Other Model 4": "https://example.com/other_model_4.json"
161
+ # }
162
+
163
+ # selected_model = st.selectbox("Choose an example model", list(example_models.keys()))
164
+ # if selected_model:
165
+ # example_url = example_models[selected_model]
166
+ # try:
167
+ # response = requests.get(example_url)
168
+ # response.raise_for_status()
169
+ # file_content = response.content
170
+ # file_extension = example_url.split('.')[-1].lower()
171
+ # return load_model_from_content(file_content, file_extension)
172
+ # except requests.RequestException as e:
173
+ # st.error(f"Error loading example model: {e}")
174
+ # return None
175
+
176
+ # st.write("Try out example files:")
177
+ # return None
178
 
179
  def upload_file_and_load_to_model():
180
+ # col1, col2 = st.columns(2)
181
+ # with col1:
182
+ uploaded_file = st.file_uploader("Choose a JSON/YAML/BSON file", type=["json", "yaml", "bson"])
183
+ if uploaded_file is not None:
184
+ file_content = uploaded_file.getvalue()
185
+ file_extension = uploaded_file.name.split('.')[-1].lower()
186
+ return load_model_from_content(file_content, file_extension)
187
+ github_url = st.text_input("Enter GitHub raw file URL:", placeholder="Enter GitHub raw file URL")
188
+ if github_url:
189
+ try:
190
+ response = requests.get(github_url)
191
+ response.raise_for_status()
192
+ file_content = response.content
193
+ file_extension = github_url.split('.')[-1].lower()
194
  return load_model_from_content(file_content, file_extension)
195
+ except requests.RequestException as e:
196
+ st.error(f"Error loading file from GitHub: {e}")
197
+ return None
198
+ # with col2:
199
+ example_models = {
200
+ "Newton Cooling Model": "https://raw.githubusercontent.com/ModECI/MDF/development/examples/MDF/NewtonCoolingModel.json",
201
+ "ABCD": "https://raw.githubusercontent.com/ModECI/MDF/main/examples/MDF/ABCD.json",
202
+ "FN": "https://raw.githubusercontent.com/ModECI/MDF/main/examples/MDF/FN.mdf.json",
203
+ "States": "https://raw.githubusercontent.com/ModECI/MDF/main/examples/MDF/States.json",
204
+ "Other Model 4": "https://example.com/other_model_4.json"
205
+ }
206
+ selected_model = st.selectbox("Choose an example model", list(example_models.keys()), index=None)
207
+ if selected_model:
208
+ example_url = example_models[selected_model]
209
+ try:
210
+ response = requests.get(example_url)
211
+ response.raise_for_status()
212
+ file_content = response.content
213
+ file_extension = example_url.split('.')[-1].lower()
214
+ return load_model_from_content(file_content, file_extension)
215
+ except requests.RequestException as e:
216
+ st.error(f"Error loading example model: {e}")
217
+ return None
218
+ # st.button("Newton Cooling Model", on_click=load_mdf_json(""))
219
  return None
220
 
221
+
222
  def load_model_from_content(file_content, file_extension):
223
  try:
224
  if file_extension == 'json':
 
239
 
240
 
241
  def main():
 
242
  mdf_model = upload_file_and_load_to_model() # controller
243
  if mdf_model:
244
  mod_graph = mdf_model.graphs[0]
245
  nodes = mod_graph.nodes
246
+ parameters = []
247
  for node in nodes:
248
+ parameters.append(node.parameters)
249
+ param_inputs = {}
250
  if mdf_model.metadata:
251
  preferred_duration = float(mdf_model.metadata.get("preferred_duration", 10))
252
  preferred_dt = float(mdf_model.metadata.get("preferred_dt", 0.1))
examples/FN.mdf.json ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "FN": {
3
+ "format": "ModECI MDF v0.4",
4
+ "graphs": {
5
+ "FN": {
6
+ "notes": "FitzHugh Nagumo cell model - originally specified in NeuroML/LEMS",
7
+ "nodes": {
8
+ "FNpop": {
9
+ "metadata": {
10
+ "color": "0.2 0.2 0.2",
11
+ "radius": 3,
12
+ "region": "region1"
13
+ },
14
+ "parameters": {
15
+ "initial_w": {
16
+ "value": [
17
+ 0.0
18
+ ]
19
+ },
20
+ "initial_v": {
21
+ "value": [
22
+ -1.0
23
+ ]
24
+ },
25
+ "a_v": {
26
+ "value": [
27
+ -0.3333333333333333
28
+ ]
29
+ },
30
+ "b_v": {
31
+ "value": [
32
+ 0.0
33
+ ]
34
+ },
35
+ "c_v": {
36
+ "value": [
37
+ 1.0
38
+ ]
39
+ },
40
+ "d_v": {
41
+ "value": [
42
+ 1.0
43
+ ]
44
+ },
45
+ "e_v": {
46
+ "value": [
47
+ -1.0
48
+ ]
49
+ },
50
+ "f_v": {
51
+ "value": [
52
+ 1.0
53
+ ]
54
+ },
55
+ "time_constant_v": {
56
+ "value": [
57
+ 1.0
58
+ ]
59
+ },
60
+ "a_w": {
61
+ "value": [
62
+ 1.0
63
+ ]
64
+ },
65
+ "b_w": {
66
+ "value": [
67
+ -0.8
68
+ ]
69
+ },
70
+ "c_w": {
71
+ "value": [
72
+ 0.7
73
+ ]
74
+ },
75
+ "time_constant_w": {
76
+ "value": [
77
+ 12.5
78
+ ]
79
+ },
80
+ "threshold_exc": {
81
+ "value": [
82
+ -1.0
83
+ ]
84
+ },
85
+ "mode": {
86
+ "value": [
87
+ 1.0
88
+ ]
89
+ },
90
+ "uncorrelated_activity": {
91
+ "value": [
92
+ 0.0
93
+ ]
94
+ },
95
+ "Iext": {
96
+ "value": [
97
+ 0.0
98
+ ]
99
+ },
100
+ "MSEC": {
101
+ "value": [
102
+ 0.001
103
+ ]
104
+ },
105
+ "spike": {
106
+ "value": [
107
+ 0
108
+ ]
109
+ },
110
+ "V": {
111
+ "default_initial_value": "initial_v",
112
+ "time_derivative": "(a_v*V*V*V + (1+threshold_exc)*b_v*V*V + (-1*threshold_exc)*c_v*V + d_v + e_v*W + f_v*Iext + INPUT) / (time_constant_v*MSEC)"
113
+ },
114
+ "W": {
115
+ "default_initial_value": "initial_w",
116
+ "time_derivative": "(mode*a_w*V + b_w*W + c_w + (1-mode)*uncorrelated_activity) / (time_constant_w*MSEC)"
117
+ }
118
+ },
119
+ "input_ports": {
120
+ "INPUT": {}
121
+ },
122
+ "output_ports": {
123
+ "spike": {
124
+ "value": "spike"
125
+ },
126
+ "V": {
127
+ "value": "V"
128
+ },
129
+ "W": {
130
+ "value": "W"
131
+ }
132
+ },
133
+ "notes": "Cell: [Cell(notes=None, id='fn', parameters={'initial_w': 'initial_w', 'initial_v': 'initial_v', 'a_v': 'a_v', 'b_v': 'b_v', 'c_v': 'c_v', 'd_v': 'd_v', 'e_v': 'e_v', 'f_v': 'f_v', 'time_constant_v': 'time_constant_v', 'a_w': 'a_w', 'b_w': 'b_w', 'c_w': 'c_w', 'time_constant_w': 'time_constant_w', 'threshold': 'threshold', 'mode': 'mode', 'uncorrelated_activity': 'uncorrelated_activity', 'Iext': 'Iext'}, neuroml2_source_file=None, lems_source_file='FN_Definitions.xml', neuroml2_cell=None, pynn_cell=None, arbor_cell=None, bindsnet_node=None)] is defined in FN_Definitions.xml and in Lems is: Component, id: fn, type: fnCell,\n parameters: {'initial_w': '0.0', 'initial_v': '-1', 'a_v': '-0.3333333333333333', 'b_v': '0.0', 'c_v': '1.0', 'd_v': '1', 'e_v': '-1.0', 'f_v': '1.0', 'time_constant_v': '1.0', 'a_w': '1.0', 'b_w': '-0.8', 'c_w': '0.7', 'time_constant_w': '12.5', 'threshold_exc': '-1.0', 'mode': '1.0', 'uncorrelated_activity': '0.0', 'Iext': '0'}\n parent: None\n"
134
+ }
135
+ },
136
+ "edges": {}
137
+ }
138
+ }
139
+ }
140
+ }
examples/NewtonCoolingModel.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "NewtonCoolingModel": {
3
+ "format": "ModECI MDF v0.4",
4
+ "generating_application": "Python modeci-mdf v0.4.11",
5
+ "graphs": {
6
+ "cooling_process": {
7
+ "nodes": {
8
+ "cool_node": {
9
+ "parameters": {
10
+ "cooling_coeff": {
11
+ "value": 0.1
12
+ },
13
+ "T_a": {
14
+ "value": 20
15
+ },
16
+ "T_curr": {
17
+ "default_initial_value": 90,
18
+ "time_derivative": "dT_dt"
19
+ },
20
+ "dT_dt": {
21
+ "value": "-cooling_coeff*(T_curr - T_a)",
22
+ "default_initial_value": 0
23
+ }
24
+ },
25
+ "output_ports": {
26
+ "out_port": {
27
+ "value": "T_curr"
28
+ },
29
+ "out_port2": {
30
+ "value": "dT_dt"
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
examples/States.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "States": {
3
+ "format": "ModECI MDF v0.4",
4
+ "generating_application": "Python modeci-mdf v0.4.11",
5
+ "graphs": {
6
+ "state_example": {
7
+ "nodes": {
8
+ "counter_node": {
9
+ "parameters": {
10
+ "increment": {
11
+ "value": 1
12
+ },
13
+ "count": {
14
+ "value": "count + increment"
15
+ }
16
+ },
17
+ "output_ports": {
18
+ "out_port": {
19
+ "value": "count"
20
+ }
21
+ }
22
+ },
23
+ "sine_node": {
24
+ "parameters": {
25
+ "amp": {
26
+ "value": 3
27
+ },
28
+ "period": {
29
+ "value": 0.4
30
+ },
31
+ "level": {
32
+ "default_initial_value": 0,
33
+ "time_derivative": "6.283185 * rate / period"
34
+ },
35
+ "rate": {
36
+ "default_initial_value": 1,
37
+ "time_derivative": "-1 * 6.283185 * level / period"
38
+ }
39
+ },
40
+ "output_ports": {
41
+ "out_port": {
42
+ "value": "amp * level"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
examples/SwitchedRLC_Circuit.json ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "SwitchedRLC_Circuit": {
3
+ "format": "ModECI MDF v0.4",
4
+ "generating_application": "Python modeci-mdf v0.4.11",
5
+ "metadata": {
6
+ "preferred_duration": 2,
7
+ "preferred_dt": 0.001
8
+ },
9
+ "graphs": {
10
+ "SwitchedRLC_Circuit": {
11
+ "nodes": {
12
+ "V": {
13
+ "parameters": {
14
+ "Vs": {
15
+ "conditions": [
16
+ {
17
+ "id": "off",
18
+ "test": "time<0.5",
19
+ "value": "0"
20
+ },
21
+ {
22
+ "id": "on",
23
+ "test": "time>=0.5",
24
+ "value": 0.1
25
+ }
26
+ ]
27
+ },
28
+ "R": {
29
+ "metadata": {
30
+ "description": "Resistance in Ohms"
31
+ },
32
+ "value": 100
33
+ },
34
+ "L": {
35
+ "metadata": {
36
+ "description": "Inductance in Henrys"
37
+ },
38
+ "value": 1
39
+ },
40
+ "C": {
41
+ "value": 0.001
42
+ },
43
+ "time": {
44
+ "default_initial_value": 0,
45
+ "time_derivative": "1"
46
+ },
47
+ "V": {
48
+ "default_initial_value": 0,
49
+ "time_derivative": "i_C /C"
50
+ },
51
+ "i_R": {
52
+ "value": "V / R"
53
+ },
54
+ "i_L": {
55
+ "default_initial_value": 0,
56
+ "time_derivative": "(Vs - V)/L"
57
+ },
58
+ "i_C": {
59
+ "value": "i_L-i_R"
60
+ }
61
+ },
62
+ "output_ports": {
63
+ "V_out": {
64
+ "value": "V"
65
+ },
66
+ "i_L_out": {
67
+ "value": "i_L"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
logo.png ADDED