Spaces:
Running
Running
Commit
·
6c4abbd
1
Parent(s):
84444f7
Add detailed error logging for debugging
Browse files
app.py
CHANGED
|
@@ -40,7 +40,7 @@ def check_api_health():
|
|
| 40 |
return f"Error: {str(e)}"
|
| 41 |
|
| 42 |
|
| 43 |
-
def run_verification(num_variables: int, num_trials: int
|
| 44 |
"""
|
| 45 |
Run SAT verification through the public API.
|
| 46 |
|
|
@@ -55,8 +55,6 @@ def run_verification(num_variables: int, num_trials: int, progress=gr.Progress()
|
|
| 55 |
num_variables = max(20, min(500, int(num_variables)))
|
| 56 |
num_trials = max(1, min(20, int(num_trials)))
|
| 57 |
|
| 58 |
-
progress(0.1, desc="Generating SAT problem...")
|
| 59 |
-
|
| 60 |
# Calculate problem parameters
|
| 61 |
alpha = 4.27 # Phase transition ratio
|
| 62 |
num_clauses = int(num_variables * alpha)
|
|
@@ -64,28 +62,25 @@ def run_verification(num_variables: int, num_trials: int, progress=gr.Progress()
|
|
| 64 |
start_time = time.time()
|
| 65 |
|
| 66 |
try:
|
| 67 |
-
progress(0.3, desc="Sending to Daugherty Engine API...")
|
| 68 |
-
|
| 69 |
response = requests.post(
|
| 70 |
f"{API_BASE}/verify/sat",
|
| 71 |
json={
|
| 72 |
"size": num_variables,
|
| 73 |
"trials": num_trials
|
| 74 |
},
|
| 75 |
-
timeout=120
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
elapsed_time = time.time() - start_time
|
| 79 |
|
| 80 |
if response.status_code != 200:
|
| 81 |
-
return format_error(f"API Error: {response.status_code}")
|
| 82 |
|
| 83 |
data = response.json()
|
| 84 |
|
| 85 |
if not data.get("success"):
|
| 86 |
-
return format_error(
|
| 87 |
-
|
| 88 |
-
progress(0.8, desc="Processing results...")
|
| 89 |
|
| 90 |
results = data.get("data", {}).get("results", {})
|
| 91 |
|
|
@@ -112,8 +107,6 @@ def run_verification(num_variables: int, num_trials: int, progress=gr.Progress()
|
|
| 112 |
power_ratio = round(dwave_energy / energy_joules) if energy_joules > 0 else 0
|
| 113 |
cost_ratio = round(COMPETITORS["D-Wave Advantage"]["cost_per_hour"] / HARDWARE_INFO["cost_per_hour"])
|
| 114 |
|
| 115 |
-
progress(1.0, desc="Complete!")
|
| 116 |
-
|
| 117 |
return format_results(
|
| 118 |
num_variables=num_variables,
|
| 119 |
num_clauses=num_clauses,
|
|
@@ -131,10 +124,11 @@ def run_verification(num_variables: int, num_trials: int, progress=gr.Progress()
|
|
| 131 |
|
| 132 |
except requests.exceptions.Timeout:
|
| 133 |
return format_error("Request timed out. Try a smaller problem size.")
|
| 134 |
-
except requests.exceptions.ConnectionError:
|
| 135 |
-
return format_error("Could not connect to API
|
| 136 |
except Exception as e:
|
| 137 |
-
|
|
|
|
| 138 |
|
| 139 |
|
| 140 |
def format_results(**kwargs):
|
|
|
|
| 40 |
return f"Error: {str(e)}"
|
| 41 |
|
| 42 |
|
| 43 |
+
def run_verification(num_variables: int, num_trials: int):
|
| 44 |
"""
|
| 45 |
Run SAT verification through the public API.
|
| 46 |
|
|
|
|
| 55 |
num_variables = max(20, min(500, int(num_variables)))
|
| 56 |
num_trials = max(1, min(20, int(num_trials)))
|
| 57 |
|
|
|
|
|
|
|
| 58 |
# Calculate problem parameters
|
| 59 |
alpha = 4.27 # Phase transition ratio
|
| 60 |
num_clauses = int(num_variables * alpha)
|
|
|
|
| 62 |
start_time = time.time()
|
| 63 |
|
| 64 |
try:
|
|
|
|
|
|
|
| 65 |
response = requests.post(
|
| 66 |
f"{API_BASE}/verify/sat",
|
| 67 |
json={
|
| 68 |
"size": num_variables,
|
| 69 |
"trials": num_trials
|
| 70 |
},
|
| 71 |
+
timeout=120,
|
| 72 |
+
headers={"Content-Type": "application/json"}
|
| 73 |
)
|
| 74 |
|
| 75 |
elapsed_time = time.time() - start_time
|
| 76 |
|
| 77 |
if response.status_code != 200:
|
| 78 |
+
return format_error(f"API Error: {response.status_code} - {response.text[:200]}")
|
| 79 |
|
| 80 |
data = response.json()
|
| 81 |
|
| 82 |
if not data.get("success"):
|
| 83 |
+
return format_error(f"API returned error: {data}")
|
|
|
|
|
|
|
| 84 |
|
| 85 |
results = data.get("data", {}).get("results", {})
|
| 86 |
|
|
|
|
| 107 |
power_ratio = round(dwave_energy / energy_joules) if energy_joules > 0 else 0
|
| 108 |
cost_ratio = round(COMPETITORS["D-Wave Advantage"]["cost_per_hour"] / HARDWARE_INFO["cost_per_hour"])
|
| 109 |
|
|
|
|
|
|
|
| 110 |
return format_results(
|
| 111 |
num_variables=num_variables,
|
| 112 |
num_clauses=num_clauses,
|
|
|
|
| 124 |
|
| 125 |
except requests.exceptions.Timeout:
|
| 126 |
return format_error("Request timed out. Try a smaller problem size.")
|
| 127 |
+
except requests.exceptions.ConnectionError as e:
|
| 128 |
+
return format_error(f"Could not connect to API: {str(e)}")
|
| 129 |
except Exception as e:
|
| 130 |
+
import traceback
|
| 131 |
+
return format_error(f"Error: {str(e)}\n\nTraceback:\n```\n{traceback.format_exc()}\n```")
|
| 132 |
|
| 133 |
|
| 134 |
def format_results(**kwargs):
|