euler314 commited on
Commit
10e2411
·
verified ·
1 Parent(s): bb706ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -69
app.py CHANGED
@@ -122,23 +122,35 @@ def run_command(cmd, show_output=True):
122
  if show_output:
123
  st.code(f"Running command: {cmd_str}", language="bash")
124
 
125
- process = subprocess.Popen(
126
- cmd,
127
- stdout=subprocess.PIPE,
128
- stderr=subprocess.PIPE,
129
- text=True
130
- )
131
-
132
- stdout, stderr = process.communicate()
133
-
134
- if process.returncode != 0:
135
  if show_output:
136
- st.error(f"Command failed with return code {process.returncode}")
 
 
 
 
 
 
 
 
 
137
  st.error(f"Command: {cmd_str}")
138
- st.error(f"Error output: {stderr}")
139
- return False, stdout, stderr
140
 
141
- return True, stdout, stderr
 
 
 
142
 
143
  # Create tabs for different analyses
144
  tab1, tab2 = st.tabs(["Eigenvalue Analysis", "Im(s) vs z Analysis"])
@@ -233,41 +245,67 @@ with tab1:
233
  if os.path.exists(data_file):
234
  os.remove(data_file)
235
 
236
- # Build command for eigenvalue analysis
237
  cmd = [
238
  executable,
239
- "eigenvalues",
240
- str(n),
241
- str(p),
242
- str(a),
243
- str(y),
244
- str(fineness),
245
  str(theory_grid_points),
246
  str(theory_tolerance),
247
  data_file
248
  ]
249
 
250
- # Run the command with our helper function
251
  status_text.text("Running eigenvalue analysis...")
252
- success, stdout, stderr = run_command(cmd, debug_mode)
253
 
254
- if not success:
255
- st.error("Eigenvalue analysis failed. Please check the debug output.")
256
- if debug_mode:
257
- st.text("Command output:")
258
- st.code(stdout)
259
- st.text("Error output:")
260
- st.code(stderr)
261
  else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  progress_bar.progress(1.0)
263
  status_text.text("Analysis complete! Generating visualization...")
264
 
265
  # Check if the output file was created
266
  if not os.path.exists(data_file):
267
  st.error(f"Output file not created: {data_file}")
268
- if debug_mode:
269
- st.text("Command output:")
270
- st.code(stdout)
271
  st.stop()
272
 
273
  # Load the results from the JSON file
@@ -628,34 +666,32 @@ with tab2:
628
  # Build command for cubic equation analysis
629
  cmd = [
630
  executable,
631
- "cubic",
632
- str(cubic_a),
633
- str(cubic_y),
634
- str(cubic_beta),
635
  str(cubic_points),
636
  data_file
637
  ]
638
 
639
- # Run the command with our helper function
640
  status_text.text("Calculating Im(s) vs z values...")
641
- success, stdout, stderr = run_command(cmd, cubic_debug_mode)
642
 
643
- if not success:
644
- st.error("Cubic equation analysis failed. Please check the debug output.")
645
- if cubic_debug_mode:
646
- st.text("Command output:")
647
- st.code(stdout)
648
- st.text("Error output:")
649
- st.code(stderr)
650
  else:
 
 
 
 
 
 
 
651
  status_text.text("Calculations complete! Generating visualization...")
652
 
653
  # Check if the output file was created
654
  if not os.path.exists(data_file):
655
  st.error(f"Output file not created: {data_file}")
656
- if cubic_debug_mode:
657
- st.text("Command output:")
658
- st.code(stdout)
659
  st.stop()
660
 
661
  # Load the results from the JSON file
@@ -883,23 +919,4 @@ with tab2:
883
  # Show placeholder
884
  st.info("👈 Set parameters and click 'Generate Im(s) vs z Analysis' to create a visualization.")
885
 
886
- st.markdown('</div>', unsafe_allow_html=True)
887
-
888
- # Add footer with information
889
- with st.expander("About this Application"):
890
- st.markdown("""
891
- ## Matrix Analysis Dashboard
892
-
893
- This application provides tools for analyzing matrix properties and related cubic equations:
894
-
895
- ### Tab 1: Eigenvalue Analysis
896
- Visualizes the relationship between empirical and theoretical eigenvalues of matrices as a function of β.
897
-
898
- ### Tab 2: Im(s) vs z Analysis
899
- Explores the imaginary parts of the roots of the cubic equation:
900
- ```
901
- zas³ + [z(a+1)+a(1-y)]s² + [z+(a+1)-y-yβ(a-1)]s + 1 = 0
902
- ```
903
-
904
- The application uses C++ for high-performance numerical calculations and Python with Streamlit and Plotly for the interactive user interface and visualizations.
905
- """)
 
122
  if show_output:
123
  st.code(f"Running command: {cmd_str}", language="bash")
124
 
125
+ # Run the command
126
+ try:
127
+ result = subprocess.run(
128
+ cmd,
129
+ stdout=subprocess.PIPE,
130
+ stderr=subprocess.PIPE,
131
+ text=True,
132
+ check=True
133
+ )
134
+
135
  if show_output:
136
+ st.write("Command completed successfully.")
137
+ if result.stdout:
138
+ st.text("Output:")
139
+ st.code(result.stdout)
140
+
141
+ return True, result.stdout, result.stderr
142
+
143
+ except subprocess.CalledProcessError as e:
144
+ if show_output:
145
+ st.error(f"Command failed with return code {e.returncode}")
146
  st.error(f"Command: {cmd_str}")
147
+ st.error(f"Error output: {e.stderr}")
148
+ return False, e.stdout, e.stderr
149
 
150
+ except Exception as e:
151
+ if show_output:
152
+ st.error(f"Error executing command: {str(e)}")
153
+ return False, "", str(e)
154
 
155
  # Create tabs for different analyses
156
  tab1, tab2 = st.tabs(["Eigenvalue Analysis", "Im(s) vs z Analysis"])
 
245
  if os.path.exists(data_file):
246
  os.remove(data_file)
247
 
248
+ # Build command for eigenvalue analysis with the proper arguments
249
  cmd = [
250
  executable,
251
+ "eigenvalues", # Mode argument
252
+ str(n),
253
+ str(p),
254
+ str(a),
255
+ str(y),
256
+ str(fineness),
257
  str(theory_grid_points),
258
  str(theory_tolerance),
259
  data_file
260
  ]
261
 
262
+ # Run the command
263
  status_text.text("Running eigenvalue analysis...")
 
264
 
265
+ if debug_mode:
266
+ success, stdout, stderr = run_command(cmd, True)
 
 
 
 
 
267
  else:
268
+ # Start the process with pipe for stdout to read progress
269
+ process = subprocess.Popen(
270
+ cmd,
271
+ stdout=subprocess.PIPE,
272
+ stderr=subprocess.PIPE,
273
+ text=True
274
+ )
275
+
276
+ # Track progress from stdout
277
+ success = True
278
+ while True:
279
+ line = process.stdout.readline()
280
+ if not line and process.poll() is not None:
281
+ break
282
+
283
+ if line.startswith("PROGRESS:"):
284
+ try:
285
+ # Update progress bar
286
+ progress_value = float(line.split(":")[1].strip())
287
+ progress_bar.progress(progress_value)
288
+ status_text.text(f"Calculating... {int(progress_value * 100)}% complete")
289
+ except:
290
+ pass
291
+ elif line:
292
+ status_text.text(line.strip())
293
+
294
+ # Get the return code and stderr
295
+ returncode = process.poll()
296
+ stderr = process.stderr.read()
297
+
298
+ if returncode != 0:
299
+ success = False
300
+ st.error(f"Error executing the analysis: {stderr}")
301
+
302
+ if success:
303
  progress_bar.progress(1.0)
304
  status_text.text("Analysis complete! Generating visualization...")
305
 
306
  # Check if the output file was created
307
  if not os.path.exists(data_file):
308
  st.error(f"Output file not created: {data_file}")
 
 
 
309
  st.stop()
310
 
311
  # Load the results from the JSON file
 
666
  # Build command for cubic equation analysis
667
  cmd = [
668
  executable,
669
+ "cubic", # Mode argument
670
+ str(cubic_a),
671
+ str(cubic_y),
672
+ str(cubic_beta),
673
  str(cubic_points),
674
  data_file
675
  ]
676
 
677
+ # Run the command
678
  status_text.text("Calculating Im(s) vs z values...")
 
679
 
680
+ if cubic_debug_mode:
681
+ success, stdout, stderr = run_command(cmd, True)
 
 
 
 
 
682
  else:
683
+ # Run the command with our helper function
684
+ result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
685
+ success = result.returncode == 0
686
+ if not success:
687
+ st.error(f"Error executing cubic analysis: {result.stderr}")
688
+
689
+ if success:
690
  status_text.text("Calculations complete! Generating visualization...")
691
 
692
  # Check if the output file was created
693
  if not os.path.exists(data_file):
694
  st.error(f"Output file not created: {data_file}")
 
 
 
695
  st.stop()
696
 
697
  # Load the results from the JSON file
 
919
  # Show placeholder
920
  st.info("👈 Set parameters and click 'Generate Im(s) vs z Analysis' to create a visualization.")
921
 
922
+ st.markdown('</div>', unsafe_allow_html=True)