igriv Claude commited on
Commit
54d34d7
·
1 Parent(s): 1345aff

Fix distribution analysis crash when all volume computations fail

Browse files

Added checks for empty volumes array to prevent crashes:
- Added np.isfinite() check before appending volumes
- Return helpful error message if no valid volumes computed
- Prevents ValueError on empty array reduction operations

This fixes the crash when distribution sampling generates all invalid configurations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. bin/gui.py +22 -2
bin/gui.py CHANGED
@@ -294,13 +294,33 @@ def analyze_volume_distribution(n_vertices, n_samples, seed, progress=gr.Progres
294
  try:
295
  vertices_np = np.array(vertices, dtype=np.complex128)
296
  vol = ideal_poly_volume_via_delaunay(vertices_np, mode='fast', series_terms=96)
297
- if 0 < vol < 1000:
298
  volumes.append(vol)
299
- except:
 
300
  pass
301
 
302
  volumes = np.array(volumes)
303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  # Create histogram
305
  fig, ax = plt.subplots(figsize=(10, 6))
306
  ax.hist(volumes, bins=50, density=True, alpha=0.7, color='steelblue', edgecolor='black')
 
294
  try:
295
  vertices_np = np.array(vertices, dtype=np.complex128)
296
  vol = ideal_poly_volume_via_delaunay(vertices_np, mode='fast', series_terms=96)
297
+ if np.isfinite(vol) and 0 < vol < 1000:
298
  volumes.append(vol)
299
+ except Exception as e:
300
+ # Silently skip failed computations
301
  pass
302
 
303
  volumes = np.array(volumes)
304
 
305
+ # Check if we have any valid volumes
306
+ if len(volumes) == 0:
307
+ error_msg = f"""
308
+ ## Distribution Analysis Failed
309
+
310
+ **Error:** No valid volume computations succeeded.
311
+
312
+ **Possible causes:**
313
+ - Random vertices may be generating degenerate configurations
314
+ - Try increasing the number of samples
315
+ - Try a different number of vertices
316
+
317
+ **Configuration:**
318
+ - Random vertices requested: {n_random}
319
+ - Samples attempted: {n_samples}
320
+ - Valid samples: 0
321
+ """
322
+ return error_msg, None
323
+
324
  # Create histogram
325
  fig, ax = plt.subplots(figsize=(10, 6))
326
  ax.hist(volumes, bins=50, density=True, alpha=0.7, color='steelblue', edgecolor='black')