Rimjhim Mittal commited on
Commit
4f709ff
·
1 Parent(s): af2c3c7

arrays greater than 10 not to be editted, 1D array naming fix #2

Browse files
Files changed (1) hide show
  1. app.py +33 -34
app.py CHANGED
@@ -24,9 +24,6 @@ def run_simulation(param_inputs, mdf_model, stateful):
24
  if stateful:
25
  duration = param_inputs["Simulation Duration (s)"]
26
  dt = param_inputs["Time Step (s)"]
27
-
28
-
29
-
30
  for node in nodes:
31
  eg = EvaluableGraph(mod_graph, verbose=False)
32
  t = 0
@@ -59,7 +56,7 @@ def run_simulation(param_inputs, mdf_model, stateful):
59
  for node in nodes:
60
  eg = EvaluableGraph(mod_graph, verbose=False)
61
  eg.evaluate()
62
- all_node_results[node.id] = pd.DataFrame({op.value: [float(eg.enodes[node.id].evaluable_outputs[op.id].curr_value)] for op in node.output_ports})
63
 
64
  return all_node_results
65
  def show_simulation_results(all_node_results, stateful_nodes):
@@ -88,21 +85,9 @@ def show_simulation_results(all_node_results, stateful_nodes):
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}"]
@@ -137,21 +122,34 @@ def display_and_edit_array(array, key):
137
  if isinstance(array, list):
138
  array = np.array(array)
139
 
 
140
  rows, cols = array.shape if array.ndim > 1 else (1, len(array))
141
-
142
- edited_array = []
143
- for i in range(rows):
144
- row = []
145
- for j in range(cols):
146
- value = array[i][j] if array.ndim > 1 else array[i]
147
- edited_value = st.text_input(f"[{i}][{j}]", value=str(value), key=f"{key}_{i}_{j}")
148
- try:
149
- row.append(float(edited_value))
150
- except ValueError:
151
- st.error(f"Invalid input for [{i}][{j}]. Please enter a valid number.")
152
- edited_array.append(row)
153
-
154
- return np.array(edited_array)
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  def parameter_form_to_update_model_and_view(mdf_model):
157
  mod_graph = mdf_model.graphs[0]
@@ -262,10 +260,11 @@ def upload_file_and_load_to_model():
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
  }
270
  selected_model = st.sidebar.selectbox("Choose an example model", list(example_models.keys()), index=None, placeholder="Dont have an MDF Model? Try some sample examples here!")
271
 
 
24
  if stateful:
25
  duration = param_inputs["Simulation Duration (s)"]
26
  dt = param_inputs["Time Step (s)"]
 
 
 
27
  for node in nodes:
28
  eg = EvaluableGraph(mod_graph, verbose=False)
29
  t = 0
 
56
  for node in nodes:
57
  eg = EvaluableGraph(mod_graph, verbose=False)
58
  eg.evaluate()
59
+ all_node_results[node.id] = pd.DataFrame({op.value: [eg.enodes[node.id].evaluable_outputs[op.id].curr_value] for op in node.output_ports})
60
 
61
  return all_node_results
62
  def show_simulation_results(all_node_results, stateful_nodes):
 
85
  on_change=update_selected_columns,
86
  args=(node_id, column,)
87
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  else:
89
+ for col in chart_data.columns:
90
+ st.write(f"{col}: {chart_data[col][0]}")
91
 
92
  def update_selected_columns(node_id, column):
93
  st.session_state.selected_columns[node_id][column] = st.session_state[f"checkbox_{node_id}_{column}"]
 
122
  if isinstance(array, list):
123
  array = np.array(array)
124
 
125
+ # st.write(array)
126
  rows, cols = array.shape if array.ndim > 1 else (1, len(array))
127
+ if rows*cols > 10:
128
+ st.write(array)
129
+ st.write("Array Shape:", array.shape)
130
+ else:
131
+ edited_array = []
132
+ if rows == 1:
133
+ for j in range(cols):
134
+ value = array[j] if array.ndim > 1 else array[j]
135
+ edited_value = st.text_input(f"[{j}]", value=str(value), key=f"{key}_{j}")
136
+ try:
137
+ edited_array.append(float(edited_value))
138
+ except ValueError:
139
+ st.error(f"Invalid input for [{j}]. Please enter a valid number.")
140
+ else:
141
+ for i in range(rows):
142
+ row = []
143
+ for j in range(cols):
144
+ value = array[i][j] if array.ndim > 1 else array[i]
145
+ edited_value = st.text_input(f"[{i}][{j}]", value=str(value), key=f"{key}_{i}_{j}")
146
+ try:
147
+ row.append(float(edited_value))
148
+ except ValueError:
149
+ st.error(f"Invalid input for [{i}][{j}]. Please enter a valid number.")
150
+ edited_array.append(row)
151
+
152
+ return np.array(edited_array)
153
 
154
  def parameter_form_to_update_model_and_view(mdf_model):
155
  mod_graph = mdf_model.graphs[0]
 
260
  "States": "./examples/States.json",
261
  "Switched RLC Circuit": "./examples/switched_rlc_circuit.json",
262
  "Simple":"./examples/Simple.json",
263
+ "Arrays":"./examples/Arrays.json",
264
  # "RNN":"./examples/RNNs.json", # some issue
265
  "IAF":"./examples/IAFs.json",
266
+ "Izhikevich Test":"./examples/IzhikevichTest.mdf.json",
267
+ "Keras to MDF IRIS":"./examples/keras_to_MDF.json",
268
  }
269
  selected_model = st.sidebar.selectbox("Choose an example model", list(example_models.keys()), index=None, placeholder="Dont have an MDF Model? Try some sample examples here!")
270