Rimjhim Mittal commited on
Commit
af2c3c7
·
unverified ·
2 Parent(s): 676ece303c089f

Merge pull request #11 from rimjhimittal/main

Browse files
.github/workflows/teststreamlit.yml CHANGED
@@ -20,4 +20,4 @@ jobs:
20
  - uses: streamlit/streamlit-app-action@v0.0.3
21
  with:
22
  app-path: app.py
23
- ruff: true
 
20
  - uses: streamlit/streamlit-app-action@v0.0.3
21
  with:
22
  app-path: app.py
23
+ ruff: false
app.py CHANGED
@@ -5,7 +5,7 @@ from modeci_mdf.execution_engine import EvaluableGraph, EvaluableOutput
5
  import json
6
  import numpy as np
7
  import requests
8
- st.set_page_config(layout="wide", page_icon="logo.png", page_title="Model Description Format", menu_items={
9
  'Report a bug': "https://github.com/ModECI/MDF/",
10
  '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."
11
  })
@@ -71,25 +71,39 @@ def show_simulation_results(all_node_results, stateful_nodes):
71
  st.session_state.selected_columns = {node_id: {col: True for col in chart_data.columns}}
72
  elif node_id not in st.session_state.selected_columns:
73
  st.session_state.selected_columns[node_id] = {col: True for col in chart_data.columns}
74
- columns = chart_data.columns
75
- for column in columns:
76
- st.checkbox(
77
- f"{column}",
78
- value=st.session_state.selected_columns[node_id][column],
79
- key=f"checkbox_{node_id}_{column}",
80
- on_change=update_selected_columns,
81
- args=(node_id, column,)
82
- )
83
-
84
  # Filter the data based on selected checkboxes
85
  filtered_data = chart_data[[col for col, selected in st.session_state.selected_columns[node_id].items() if selected]]
86
-
87
  # Display the line chart with filtered data
88
  st.line_chart(filtered_data, use_container_width=True, height=400)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  else:
90
  st.write(all_node_results[node_id])
91
 
92
-
93
  def update_selected_columns(node_id, column):
94
  st.session_state.selected_columns[node_id][column] = st.session_state[f"checkbox_{node_id}_{column}"]
95
 
@@ -99,7 +113,7 @@ def show_mdf_graph(mdf_model):
99
  image_path = mdf_model.id + ".png"
100
  st.image(image_path, caption="Model Graph Visualization")
101
 
102
- def show_json_output(mdf_model):
103
  st.subheader("JSON Model")
104
  st.json(mdf_model.to_json())
105
 
@@ -107,27 +121,17 @@ def show_json_output(mdf_model):
107
  def view_tabs(mdf_model, param_inputs, stateful): # view
108
  tab1, tab2, tab3 = st.tabs(["Simulation Results", "MDF Graph", "Json Model"])
109
  with tab1:
110
- if stateful:
111
- if 'simulation_results' not in st.session_state:
112
- st.session_state.simulation_results = None
113
-
114
- if st.session_state.simulation_results is not None:
115
- show_simulation_results(st.session_state.simulation_results, stateful)
116
- else:
117
- st.write("Run the simulation to see results.") # model
118
  else:
119
- if 'simulation_results' not in st.session_state:
120
- st.session_state.simulation_results = None
121
-
122
- if st.session_state.simulation_results is not None:
123
- show_simulation_results(st.session_state.simulation_results, stateful)
124
- else:
125
- st.write("Stateless.")
126
 
127
  with tab2:
128
  show_mdf_graph(mdf_model) # view
129
  with tab3:
130
- show_json_output(mdf_model) # view
131
 
132
  def display_and_edit_array(array, key):
133
  if isinstance(array, list):
@@ -241,6 +245,9 @@ def parameter_form_to_update_model_and_view(mdf_model):
241
  if param.id in param_inputs:
242
  param.value = param_inputs[param.id]
243
  st.session_state.simulation_results = run_simulation(param_inputs, mdf_model, stateful)
 
 
 
244
 
245
  view_tabs(mdf_model, param_inputs, stateful_nodes)
246
 
@@ -250,13 +257,13 @@ def upload_file_and_load_to_model():
250
  github_url = st.sidebar.text_input("Enter GitHub raw file URL:", placeholder="Enter GitHub raw file URL")
251
  example_models = {
252
  "Newton Cooling Model": "./examples/NewtonCoolingModel.json",
253
- # "ABCD": "./examples/ABCD.json",
254
  "FN": "./examples/FN.mdf.json",
255
  "States": "./examples/States.json",
256
- "Swicthed RLC Circuit": "./examples/switched_rlc_circuit.json",
257
  "Simple":"./examples/Simple.json",
258
  # "Arrays":"./examples/Arrays.json",
259
- # "RNN":"./examples/RNNs.json",
260
  "IAF":"./examples/IAFs.json",
261
  "Izhikevich Test":"./examples/IzhikevichTest.mdf.json"
262
  }
@@ -311,6 +318,7 @@ def main():
311
  mdf_model = upload_file_and_load_to_model() # controller
312
 
313
  if mdf_model:
 
314
  header1, header2 = st.columns([1, 8], vertical_alignment="top")
315
  with header1:
316
  with st.container():
 
5
  import json
6
  import numpy as np
7
  import requests
8
+ st.set_page_config(layout="wide", page_icon="page_icon.png", page_title="Model Description Format", menu_items={
9
  'Report a bug': "https://github.com/ModECI/MDF/",
10
  '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."
11
  })
 
71
  st.session_state.selected_columns = {node_id: {col: True for col in chart_data.columns}}
72
  elif node_id not in st.session_state.selected_columns:
73
  st.session_state.selected_columns[node_id] = {col: True for col in chart_data.columns}
74
+
 
 
 
 
 
 
 
 
 
75
  # Filter the data based on selected checkboxes
76
  filtered_data = chart_data[[col for col, selected in st.session_state.selected_columns[node_id].items() if selected]]
 
77
  # Display the line chart with filtered data
78
  st.line_chart(filtered_data, use_container_width=True, height=400)
79
+ columns = chart_data.columns
80
+ checks = st.columns(8)
81
+ if len(columns) > 0 and len(st.session_state.selected_columns[node_id])>1:
82
+ for l, column in enumerate(columns):
83
+ with checks[l]:
84
+ st.checkbox(
85
+ f"{column}",
86
+ value=st.session_state.selected_columns[node_id][column],
87
+ key=f"checkbox_{node_id}_{column}",
88
+ on_change=update_selected_columns,
89
+ args=(node_id, column,)
90
+ )
91
+ #show checkboxes horizontally
92
+ # in case we late go back to vertical
93
+ # for column in columns:
94
+ # st.checkbox(
95
+ # f"{column}",
96
+ # value=st.session_state.selected_columns[node_id][column],
97
+ # key=f"checkbox_{node_id}_{column}",
98
+ # on_change=update_selected_columns,
99
+ # args=(node_id, column,)
100
+ # )
101
+
102
+
103
+
104
  else:
105
  st.write(all_node_results[node_id])
106
 
 
107
  def update_selected_columns(node_id, column):
108
  st.session_state.selected_columns[node_id][column] = st.session_state[f"checkbox_{node_id}_{column}"]
109
 
 
113
  image_path = mdf_model.id + ".png"
114
  st.image(image_path, caption="Model Graph Visualization")
115
 
116
+ def show_json_model(mdf_model):
117
  st.subheader("JSON Model")
118
  st.json(mdf_model.to_json())
119
 
 
121
  def view_tabs(mdf_model, param_inputs, stateful): # view
122
  tab1, tab2, tab3 = st.tabs(["Simulation Results", "MDF Graph", "Json Model"])
123
  with tab1:
124
+ if 'simulation_run' not in st.session_state or not st.session_state.simulation_run:
125
+ st.write("Run the simulation to see results.")
126
+ elif st.session_state.simulation_results is not None:
127
+ show_simulation_results(st.session_state.simulation_results, stateful)
 
 
 
 
128
  else:
129
+ st.write("No simulation results available.")
 
 
 
 
 
 
130
 
131
  with tab2:
132
  show_mdf_graph(mdf_model) # view
133
  with tab3:
134
+ show_json_model(mdf_model) # view
135
 
136
  def display_and_edit_array(array, key):
137
  if isinstance(array, list):
 
245
  if param.id in param_inputs:
246
  param.value = param_inputs[param.id]
247
  st.session_state.simulation_results = run_simulation(param_inputs, mdf_model, stateful)
248
+ st.session_state.simulation_run = True
249
+ else:
250
+ st.error("Please correct the invalid inputs before running the simulation.")
251
 
252
  view_tabs(mdf_model, param_inputs, stateful_nodes)
253
 
 
257
  github_url = st.sidebar.text_input("Enter GitHub raw file URL:", placeholder="Enter GitHub raw file URL")
258
  example_models = {
259
  "Newton Cooling Model": "./examples/NewtonCoolingModel.json",
260
+ "ABCD": "./examples/ABCD.json",
261
  "FN": "./examples/FN.mdf.json",
262
  "States": "./examples/States.json",
263
+ "Switched RLC Circuit": "./examples/switched_rlc_circuit.json",
264
  "Simple":"./examples/Simple.json",
265
  # "Arrays":"./examples/Arrays.json",
266
+ # "RNN":"./examples/RNNs.json", # some issue
267
  "IAF":"./examples/IAFs.json",
268
  "Izhikevich Test":"./examples/IzhikevichTest.mdf.json"
269
  }
 
318
  mdf_model = upload_file_and_load_to_model() # controller
319
 
320
  if mdf_model:
321
+ st.session_state.current_model = mdf_model
322
  header1, header2 = st.columns([1, 8], vertical_alignment="top")
323
  with header1:
324
  with st.container():
examples/keras_to_MDF.json ADDED
The diff for this file is too large to render. See raw diff
 
page_icon.png ADDED