Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,73 +66,7 @@ except ImportError as e:
|
|
| 66 |
except Exception as compile_error:
|
| 67 |
print(f"Failed to compile C++ module: {compile_error}")
|
| 68 |
cpp_available = False
|
| 69 |
-
|
| 70 |
-
if cpp_available:
|
| 71 |
-
# Start with all Python implementations
|
| 72 |
-
discriminant_func = discriminant_func_py
|
| 73 |
-
find_z_at_discriminant_zero = find_z_at_discriminant_zero_py
|
| 74 |
-
sweep_beta_and_find_z_bounds = sweep_beta_and_find_z_bounds_py
|
| 75 |
-
compute_eigenvalue_support_boundaries = compute_eigenvalue_support_boundaries_py
|
| 76 |
-
compute_cubic_roots = compute_cubic_roots_py
|
| 77 |
-
compute_high_y_curve = compute_high_y_curve_py
|
| 78 |
-
compute_alternate_low_expr = compute_alternate_low_expr_py
|
| 79 |
-
compute_max_k_expression = compute_max_k_expression_py
|
| 80 |
-
compute_min_t_expression = compute_min_t_expression_py
|
| 81 |
-
compute_derivatives = compute_derivatives_py
|
| 82 |
-
generate_eigenvalue_distribution = generate_eigenvalue_distribution_py
|
| 83 |
-
|
| 84 |
-
# Now override with C++ implementations if they exist
|
| 85 |
-
try:
|
| 86 |
-
# Check each C++ function individually
|
| 87 |
-
if hasattr(cubic_cpp, "discriminant_func"):
|
| 88 |
-
discriminant_func = cubic_cpp.discriminant_func
|
| 89 |
-
|
| 90 |
-
if hasattr(cubic_cpp, "find_z_at_discriminant_zero"):
|
| 91 |
-
find_z_at_discriminant_zero = cubic_cpp.find_z_at_discriminant_zero
|
| 92 |
-
|
| 93 |
-
if hasattr(cubic_cpp, "sweep_beta_and_find_z_bounds"):
|
| 94 |
-
sweep_beta_and_find_z_bounds = cubic_cpp.sweep_beta_and_find_z_bounds
|
| 95 |
-
|
| 96 |
-
if hasattr(cubic_cpp, "compute_eigenvalue_support_boundaries"):
|
| 97 |
-
compute_eigenvalue_support_boundaries = cubic_cpp.compute_eigenvalue_support_boundaries
|
| 98 |
-
|
| 99 |
-
if hasattr(cubic_cpp, "compute_cubic_roots"):
|
| 100 |
-
compute_cubic_roots = cubic_cpp.compute_cubic_roots
|
| 101 |
-
|
| 102 |
-
if hasattr(cubic_cpp, "compute_high_y_curve"):
|
| 103 |
-
compute_high_y_curve = cubic_cpp.compute_high_y_curve
|
| 104 |
-
|
| 105 |
-
if hasattr(cubic_cpp, "compute_alternate_low_expr"):
|
| 106 |
-
compute_alternate_low_expr = cubic_cpp.compute_alternate_low_expr
|
| 107 |
-
|
| 108 |
-
if hasattr(cubic_cpp, "compute_max_k_expression"):
|
| 109 |
-
compute_max_k_expression = cubic_cpp.compute_max_k_expression
|
| 110 |
-
|
| 111 |
-
if hasattr(cubic_cpp, "compute_min_t_expression"):
|
| 112 |
-
compute_min_t_expression = cubic_cpp.compute_min_t_expression
|
| 113 |
-
|
| 114 |
-
if hasattr(cubic_cpp, "compute_derivatives"):
|
| 115 |
-
compute_derivatives = cubic_cpp.compute_derivatives
|
| 116 |
-
|
| 117 |
-
if hasattr(cubic_cpp, "generate_eigenvalue_distribution"):
|
| 118 |
-
generate_eigenvalue_distribution = lambda beta, y, z_a, n=1000, seed=42: cubic_cpp.generate_eigenvalue_distribution(beta, y, z_a, n, seed)
|
| 119 |
-
|
| 120 |
-
print("Using C++ acceleration for available functions")
|
| 121 |
-
except Exception as e:
|
| 122 |
-
print(f"Error setting up C++ functions: {e}")
|
| 123 |
-
else:
|
| 124 |
-
# Use all Python implementations
|
| 125 |
-
discriminant_func = discriminant_func_py
|
| 126 |
-
find_z_at_discriminant_zero = find_z_at_discriminant_zero_py
|
| 127 |
-
sweep_beta_and_find_z_bounds = sweep_beta_and_find_z_bounds_py
|
| 128 |
-
compute_eigenvalue_support_boundaries = compute_eigenvalue_support_boundaries_py
|
| 129 |
-
compute_cubic_roots = compute_cubic_roots_py
|
| 130 |
-
compute_high_y_curve = compute_high_y_curve_py
|
| 131 |
-
compute_alternate_low_expr = compute_alternate_low_expr_py
|
| 132 |
-
compute_max_k_expression = compute_max_k_expression_py
|
| 133 |
-
compute_min_t_expression = compute_min_t_expression_py
|
| 134 |
-
compute_derivatives = compute_derivatives_py
|
| 135 |
-
generate_eigenvalue_distribution = generate_eigenvalue_distribution_py
|
| 136 |
def add_sqrt_support(expr_str):
|
| 137 |
"""Replace 'sqrt(' with 'sp.sqrt(' for sympy compatibility"""
|
| 138 |
return expr_str.replace('sqrt(', 'sp.sqrt(')
|
|
@@ -1123,7 +1057,31 @@ def generate_eigenvalue_distribution_plot(beta, y, z_a, n=1000, seed=42):
|
|
| 1123 |
)
|
| 1124 |
|
| 1125 |
return fig, eigenvalues
|
| 1126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1127 |
# ----------------- Streamlit UI -----------------
|
| 1128 |
def main():
|
| 1129 |
st.title("Cubic Root Analysis")
|
|
|
|
| 66 |
except Exception as compile_error:
|
| 67 |
print(f"Failed to compile C++ module: {compile_error}")
|
| 68 |
cpp_available = False
|
| 69 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def add_sqrt_support(expr_str):
|
| 71 |
"""Replace 'sqrt(' with 'sp.sqrt(' for sympy compatibility"""
|
| 72 |
return expr_str.replace('sqrt(', 'sp.sqrt(')
|
|
|
|
| 1057 |
)
|
| 1058 |
|
| 1059 |
return fig, eigenvalues
|
| 1060 |
+
# Use C++ implementations if available, otherwise use Python implementations
|
| 1061 |
+
if cpp_available:
|
| 1062 |
+
discriminant_func = cubic_cpp.discriminant_func
|
| 1063 |
+
find_z_at_discriminant_zero = cubic_cpp.find_z_at_discriminant_zero
|
| 1064 |
+
sweep_beta_and_find_z_bounds = cubic_cpp.sweep_beta_and_find_z_bounds
|
| 1065 |
+
compute_eigenvalue_support_boundaries = cubic_cpp.compute_eigenvalue_support_boundaries
|
| 1066 |
+
compute_cubic_roots = cubic_cpp.compute_cubic_roots
|
| 1067 |
+
compute_high_y_curve = cubic_cpp.compute_high_y_curve
|
| 1068 |
+
compute_alternate_low_expr = cubic_cpp.compute_alternate_low_expr
|
| 1069 |
+
compute_max_k_expression = cubic_cpp.compute_max_k_expression
|
| 1070 |
+
compute_min_t_expression = cubic_cpp.compute_min_t_expression
|
| 1071 |
+
compute_derivatives = cubic_cpp.compute_derivatives
|
| 1072 |
+
generate_eigenvalue_distribution = lambda beta, y, z_a, n=1000, seed=42: cubic_cpp.generate_eigenvalue_distribution(beta, y, z_a, n, seed)
|
| 1073 |
+
else:
|
| 1074 |
+
discriminant_func = discriminant_func_py
|
| 1075 |
+
find_z_at_discriminant_zero = find_z_at_discriminant_zero_py
|
| 1076 |
+
sweep_beta_and_find_z_bounds = sweep_beta_and_find_z_bounds_py
|
| 1077 |
+
compute_eigenvalue_support_boundaries = compute_eigenvalue_support_boundaries_py
|
| 1078 |
+
compute_cubic_roots = compute_cubic_roots_py
|
| 1079 |
+
compute_high_y_curve = compute_high_y_curve_py
|
| 1080 |
+
compute_alternate_low_expr = compute_alternate_low_expr_py
|
| 1081 |
+
compute_max_k_expression = compute_max_k_expression_py
|
| 1082 |
+
compute_min_t_expression = compute_min_t_expression_py
|
| 1083 |
+
compute_derivatives = compute_derivatives_py
|
| 1084 |
+
generate_eigenvalue_distribution = generate_eigenvalue_distribution_py
|
| 1085 |
# ----------------- Streamlit UI -----------------
|
| 1086 |
def main():
|
| 1087 |
st.title("Cubic Root Analysis")
|