Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,23 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
PRACTICALITY SYSTEM 27.
|
| 4 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
-
REGRESSIONS FIXED FROM 27.
|
| 6 |
|
| 7 |
-
1. THE
|
| 8 |
-
Clamping
|
| 9 |
-
|
| 10 |
-
erased by floating point limits). Clamping is now 1e5, yielding
|
| 11 |
-
a max penalty of 1e10, strictly preserving Adam's gradients.
|
| 12 |
|
| 13 |
-
2.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
3.
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
HERITAGE MAINTAINED:
|
| 23 |
All 17 domain templates. Original-Space Adam. Depth-0 Ray Expansion.
|
|
@@ -47,12 +47,12 @@ except ImportError:
|
|
| 47 |
HAS_QUANTUM = False
|
| 48 |
|
| 49 |
DEFAULT_GEMINI_API_KEY = os.environ.get("AI_Key", "")
|
| 50 |
-
GEMINI_MODEL = "gemini-3-flash-preview"
|
| 51 |
|
| 52 |
warnings.filterwarnings("ignore")
|
| 53 |
USE_GPU = torch.cuda.is_available()
|
| 54 |
DEVICE = torch.device("cuda" if USE_GPU else "cpu")
|
| 55 |
-
print(f"[SYSTEM 27.
|
| 56 |
|
| 57 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 58 |
# SECTION 1: CONSTANTS & SAFE HELPERS
|
|
@@ -87,11 +87,11 @@ def safe_round(val, ndigits=8):
|
|
| 87 |
return round(val, ndigits)
|
| 88 |
except: return val
|
| 89 |
|
| 90 |
-
def
|
| 91 |
-
"""Clamps
|
| 92 |
try:
|
| 93 |
-
if not math.isfinite(v): return
|
| 94 |
-
return max(-
|
| 95 |
except: return 0.0
|
| 96 |
|
| 97 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -366,6 +366,15 @@ class MathConstraint:
|
|
| 366 |
scope:str="root"; branches:List['MathConstraint']=field(default_factory=list)
|
| 367 |
projections:Dict[str,List[Dict]]=field(default_factory=dict)
|
| 368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
def compile_mc(kind,expr_str,direction,variables,weight=1.0,scope="root",branches=None):
|
| 370 |
expr_str=expr_str.replace("^","**")
|
| 371 |
mc=MathConstraint(kind=kind,expr_str=expr_str,direction=direction,weight=weight,scope=scope)
|
|
@@ -395,11 +404,14 @@ def compile_mc(kind,expr_str,direction,variables,weight=1.0,scope="root",branche
|
|
| 395 |
mc.parsed=parsed
|
| 396 |
mc.syms_used=[v for v in variables if sp.Symbol(v) in parsed.free_symbols]
|
| 397 |
mc.fast_iv=compile_iv(parsed,variables)
|
|
|
|
|
|
|
| 398 |
pt_map={'sin':torch.sin,'cos':torch.cos,'tan':torch.tan,'exp':torch.exp,
|
| 399 |
-
'log':
|
| 400 |
'asin':torch.asin,'acos':torch.acos,'atan':torch.atan,
|
| 401 |
'sinh':torch.sinh,'cosh':torch.cosh,'tanh':torch.tanh,
|
| 402 |
'pi':math.pi,'E':math.e}
|
|
|
|
| 403 |
t_func_raw=sp.lambdify([sp.Symbol(v) for v in mc.syms_used],parsed,modules=[pt_map,"math"])
|
| 404 |
|
| 405 |
def _t_wrapper(*args):
|
|
@@ -408,10 +420,9 @@ def compile_mc(kind,expr_str,direction,variables,weight=1.0,scope="root",branche
|
|
| 408 |
if not isinstance(val, torch.Tensor):
|
| 409 |
val = torch.tensor(float(val), device=DEVICE, dtype=torch.float32)
|
| 410 |
except Exception:
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
return torch.nan_to_num(val, posinf=1e5, neginf=-1e5, nan=1e5)
|
| 415 |
|
| 416 |
mc.torch_func=_t_wrapper
|
| 417 |
if kind=="equality":
|
|
@@ -532,7 +543,7 @@ class Problem:
|
|
| 532 |
elif mc.direction=="geq": total+=(torch.relu(-val)**2)*eff_weight
|
| 533 |
else: total+=(torch.relu(val)**2)*eff_weight
|
| 534 |
for i,v in enumerate(self.variables):
|
| 535 |
-
lo,hi=
|
| 536 |
col=X[:,i] if is_batched else X[i]
|
| 537 |
margin=(hi-lo)*0.1*(1.0-step_ratio)
|
| 538 |
out_of_bounds=torch.relu(lo-margin-col)+torch.relu(col-(hi+margin))
|
|
@@ -540,7 +551,7 @@ class Problem:
|
|
| 540 |
|
| 541 |
if is_optimizing and self.minimize_var and self.minimize_var in self.var_idx:
|
| 542 |
midx = self.var_idx[self.minimize_var]
|
| 543 |
-
lo,hi =
|
| 544 |
rng = max(hi-lo, 1e-8)
|
| 545 |
col = X[:,midx] if is_batched else X[midx]
|
| 546 |
normalized = (col - lo) / rng
|
|
@@ -549,7 +560,7 @@ class Problem:
|
|
| 549 |
return total.view(batch_size,-1).sum(dim=1)
|
| 550 |
|
| 551 |
def scalar_energy(self, b: Dict[str,float]) -> float:
|
| 552 |
-
x_arr=[b.get(v,(
|
| 553 |
X_t=torch.tensor(x_arr,device=DEVICE,dtype=torch.float32).unsqueeze(0)
|
| 554 |
with torch.no_grad():
|
| 555 |
return float(self.tensor_energy(X_t, step_ratio=1.0, is_optimizing=False).item())
|
|
@@ -1677,12 +1688,12 @@ def _batched_deduce_and_evaluate(problem, hyps: List['Hypothesis']) -> List[Tupl
|
|
| 1677 |
xr, mr, tr = [], [], []
|
| 1678 |
active_vars=problem.get_markov_blanket(set(hyp.pinned_vars.keys()), depth=2)
|
| 1679 |
for j,v in enumerate(problem.variables):
|
| 1680 |
-
lo,hi=
|
| 1681 |
if v in hyp.pinned_vars:
|
| 1682 |
-
val=
|
| 1683 |
xr.append(val); mr.append(0.0); tr.append(val)
|
| 1684 |
else:
|
| 1685 |
-
val=
|
| 1686 |
is_active=(v in active_vars) or (len(hyp.pinned_vars)==0)
|
| 1687 |
xr.append(val); mr.append(1.0 if is_active else 0.0); tr.append(0.0)
|
| 1688 |
x_data.append(xr); mask_data.append(mr); target_data.append(tr)
|
|
@@ -1708,7 +1719,7 @@ def _batched_deduce_and_evaluate(problem, hyps: List['Hypothesis']) -> List[Tupl
|
|
| 1708 |
optimizer.step()
|
| 1709 |
X.data = torch.where(mask == 0.0, target, X.data)
|
| 1710 |
for j, v in enumerate(problem.variables):
|
| 1711 |
-
lo, hi =
|
| 1712 |
margin = (hi - lo) * 0.1 * (1.0 - step_ratio)
|
| 1713 |
X.data[:, j] = torch.clamp(X.data[:, j], lo - margin, hi + margin)
|
| 1714 |
|
|
@@ -1734,8 +1745,8 @@ def _batched_deduce_and_evaluate(problem, hyps: List['Hypothesis']) -> List[Tupl
|
|
| 1734 |
|
| 1735 |
def _mprt_sample(problem, work_box, N):
|
| 1736 |
var_list=problem.variables; V=len(var_list)
|
| 1737 |
-
lo_t=torch.tensor([
|
| 1738 |
-
hi_t=torch.tensor([
|
| 1739 |
for i in range(V):
|
| 1740 |
if lo_t[i]>=hi_t[i]: m=(lo_t[i]+hi_t[i])/2; lo_t[i]=m-1e-6; hi_t[i]=m+1e-6
|
| 1741 |
X=lo_t.unsqueeze(0)+(hi_t-lo_t).unsqueeze(0)*torch.rand((N,V), device=DEVICE)
|
|
@@ -2168,8 +2179,6 @@ class SequenceRayTracer:
|
|
| 2168 |
g1_pass,g2_pass,inv_results,_=_verify(final_b,base_problem,axl_def.anchors)
|
| 2169 |
improved=final_ce<best_ce; passed_pruning=final_ce<parent_ce*CE_EARN_RATIO
|
| 2170 |
|
| 2171 |
-
# UI Trace Visibility: Show improvements, passing states, or force a scout ray every 2k shots
|
| 2172 |
-
# so the user knows the engine hasn't frozen on a flatland plateau.
|
| 2173 |
force_ui_scout = not improved and not passed_pruning and (total_fired - last_ui_update_fired > 2000)
|
| 2174 |
|
| 2175 |
if improved or (g1_pass and g2_pass) or passed_pruning or force_ui_scout:
|
|
@@ -2187,9 +2196,8 @@ class SequenceRayTracer:
|
|
| 2187 |
out_baton=Baton(binding=final_b,ce=final_ce,ray_id=ray.ray_id,
|
| 2188 |
l9=L9Certificate(final_ce,dom_vars,[],tension_class))
|
| 2189 |
|
| 2190 |
-
#
|
| 2191 |
-
|
| 2192 |
-
dynamic_baton_thresh = min(100000.0, max(BATON_REGISTRY_THRESHOLD, best_ce * 1.5, init_ce * 0.1))
|
| 2193 |
if final_ce < dynamic_baton_thresh:
|
| 2194 |
baton_registry[ray.ray_id] = out_baton
|
| 2195 |
if len(baton_registry) > BATON_REGISTRY_MAX:
|
|
@@ -2260,7 +2268,7 @@ OUTPUT SCHEMA (JSON only, no markdown):
|
|
| 2260 |
RULES: USE ** FOR EXPONENTS. NEVER USE ^. No =, >=, <= inside expressions.
|
| 2261 |
EQ/GEQ/LEQ are expression's relation to zero. Output ONLY the JSON object."""
|
| 2262 |
|
| 2263 |
-
COLLAPSER_SYSTEM_PROMPT = """You are the Grounded Hypothesis Engine for Practicality 27.
|
| 2264 |
|
| 2265 |
Check infeasibility_report first. If non-empty: the system proved infeasibility via
|
| 2266 |
algebraic propagation before firing any rays. Output:
|
|
@@ -2666,10 +2674,10 @@ def _reset_ans_cache(a_cache):
|
|
| 2666 |
return a_cache
|
| 2667 |
|
| 2668 |
# ββ Gradio App ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2669 |
-
with gr.Blocks(css=CSS, title="Practicality 27.
|
| 2670 |
gr.Markdown(
|
| 2671 |
-
"## β Practicality 27.
|
| 2672 |
-
"`[Direct Parser / LLM] -> [
|
| 2673 |
)
|
| 2674 |
|
| 2675 |
dash_cache = gr.State({"html": ""})
|
|
@@ -2716,19 +2724,19 @@ with gr.Blocks(css=CSS, title="Practicality 27.5") as demo:
|
|
| 2716 |
value=(f"Compute: {DEVICE.type.upper()}\n"
|
| 2717 |
f"Axioms: {len(ALL_AXIOMS)}\n"
|
| 2718 |
f"Templates: {len(STRUCTURAL_HYPOTHESIS_TEMPLATES)}\n"
|
| 2719 |
-
f"\n27.
|
| 2720 |
-
f" β
|
| 2721 |
-
f"
|
| 2722 |
-
f"
|
| 2723 |
-
f"
|
| 2724 |
-
f"
|
| 2725 |
-
f" β
|
| 2726 |
-
f"
|
| 2727 |
-
f"
|
|
|
|
| 2728 |
f" Fail-Fast execution (No retries)\n"
|
| 2729 |
f" ray.depth < 1 unconditional branching.\n"
|
| 2730 |
f" MINIMIZE Soft Objectives (isolated)\n"
|
| 2731 |
-
f" Range-normalized Adam reverted to orig space.\n"
|
| 2732 |
f"\n MAX_RAYS={MAX_RAYS_PER_ATTEMPT:,}\n"
|
| 2733 |
f" MAX_CHAIN_DEPTH={MAX_CHAIN_DEPTH}"),
|
| 2734 |
lines=35,interactive=False,elem_classes=["solver-log"])
|
|
@@ -2757,15 +2765,15 @@ with gr.Blocks(css=CSS, title="Practicality 27.5") as demo:
|
|
| 2757 |
outputs=[live_html,dash_cache,ans_cache],
|
| 2758 |
js="""
|
| 2759 |
function() {
|
| 2760 |
-
if (!window.
|
| 2761 |
-
window.
|
| 2762 |
const el = document.getElementById('dash_poll_btn');
|
| 2763 |
if (!el) return;
|
| 2764 |
(el.tagName === 'BUTTON' ? el : el.querySelector('button'))?.click();
|
| 2765 |
}, 1000);
|
| 2766 |
}
|
| 2767 |
-
if (!window.
|
| 2768 |
-
window.
|
| 2769 |
const el = document.getElementById('ans_poll_btn');
|
| 2770 |
if (!el) return;
|
| 2771 |
(el.tagName === 'BUTTON' ? el : el.querySelector('button'))?.click();
|
|
@@ -2803,11 +2811,11 @@ with gr.Blocks(css=CSS, title="Practicality 27.5") as demo:
|
|
| 2803 |
outputs=[ans_cache])
|
| 2804 |
|
| 2805 |
gr.Markdown(
|
| 2806 |
-
f"Practicality 27.
|
| 2807 |
elem_classes=["status-bar"])
|
| 2808 |
|
| 2809 |
if __name__ == "__main__":
|
| 2810 |
-
print(f"[SYSTEM 27.
|
| 2811 |
-
print(f"[SYSTEM 27.
|
| 2812 |
-
print(f"[SYSTEM 27.
|
| 2813 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
PRACTICALITY SYSTEM 27.6 β THE SAFE-MATH CORE
|
| 4 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
+
REGRESSIONS FIXED FROM 27.5:
|
| 6 |
|
| 7 |
+
1. THE LOBOTOMY BUG (1e5 -> 1e15)
|
| 8 |
+
Clamping variables to 1e5 prevented astronomical variables (like
|
| 9 |
+
1,000,000 qubits) from evaluating correctly. Restored to 1e15.
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
2. SAFE MATH FUNCTIONS (NaN Gradient Protection)
|
| 12 |
+
Instead of penalizing NaNs after they destroy the computational
|
| 13 |
+
graph, functions like log() and sqrt() are now intercepted by
|
| 14 |
+
safe_log() and safe_sqrt(). They clamp inputs to >1e-7, ensuring
|
| 15 |
+
valid math while pushing strong restorative gradients to Adam.
|
| 16 |
|
| 17 |
+
3. AUTO-RATCHETING BATON REGISTRY
|
| 18 |
+
Removed the arbitrary 100,000 CE hard-cap. The registry now
|
| 19 |
+
dynamically accepts states < best_ce * 1.2. The search tree will
|
| 20 |
+
no longer artificially stall at 500 rays if initial CE is high.
|
| 21 |
|
| 22 |
HERITAGE MAINTAINED:
|
| 23 |
All 17 domain templates. Original-Space Adam. Depth-0 Ray Expansion.
|
|
|
|
| 47 |
HAS_QUANTUM = False
|
| 48 |
|
| 49 |
DEFAULT_GEMINI_API_KEY = os.environ.get("AI_Key", "")
|
| 50 |
+
GEMINI_MODEL = "gemini-3.0-flash-preview"
|
| 51 |
|
| 52 |
warnings.filterwarnings("ignore")
|
| 53 |
USE_GPU = torch.cuda.is_available()
|
| 54 |
DEVICE = torch.device("cuda" if USE_GPU else "cpu")
|
| 55 |
+
print(f"[SYSTEM 27.6] Compute: {DEVICE.type.upper()} | Safe-Math Core Active")
|
| 56 |
|
| 57 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 58 |
# SECTION 1: CONSTANTS & SAFE HELPERS
|
|
|
|
| 87 |
return round(val, ndigits)
|
| 88 |
except: return val
|
| 89 |
|
| 90 |
+
def _c15(v):
|
| 91 |
+
"""Clamps variables to 1e15 to prevent absolute Float32 Infinity."""
|
| 92 |
try:
|
| 93 |
+
if not math.isfinite(v): return 1e15 if v > 0 else -1e15
|
| 94 |
+
return max(-1e15, min(1e15, float(v)))
|
| 95 |
except: return 0.0
|
| 96 |
|
| 97 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 366 |
scope:str="root"; branches:List['MathConstraint']=field(default_factory=list)
|
| 367 |
projections:Dict[str,List[Dict]]=field(default_factory=dict)
|
| 368 |
|
| 369 |
+
# SAFE MATH WRAPPERS (Prevents PyTorch from evaluating log(-1) and dying)
|
| 370 |
+
def safe_log(x):
|
| 371 |
+
if not isinstance(x, torch.Tensor): x = torch.tensor(float(x), device=DEVICE, dtype=torch.float32)
|
| 372 |
+
return torch.log(torch.clamp(x, min=1e-7))
|
| 373 |
+
|
| 374 |
+
def safe_sqrt(x):
|
| 375 |
+
if not isinstance(x, torch.Tensor): x = torch.tensor(float(x), device=DEVICE, dtype=torch.float32)
|
| 376 |
+
return torch.sqrt(torch.clamp(x, min=0.0))
|
| 377 |
+
|
| 378 |
def compile_mc(kind,expr_str,direction,variables,weight=1.0,scope="root",branches=None):
|
| 379 |
expr_str=expr_str.replace("^","**")
|
| 380 |
mc=MathConstraint(kind=kind,expr_str=expr_str,direction=direction,weight=weight,scope=scope)
|
|
|
|
| 404 |
mc.parsed=parsed
|
| 405 |
mc.syms_used=[v for v in variables if sp.Symbol(v) in parsed.free_symbols]
|
| 406 |
mc.fast_iv=compile_iv(parsed,variables)
|
| 407 |
+
|
| 408 |
+
# Inject Safe Math functions
|
| 409 |
pt_map={'sin':torch.sin,'cos':torch.cos,'tan':torch.tan,'exp':torch.exp,
|
| 410 |
+
'log':safe_log,'sqrt':safe_sqrt,'Abs':torch.abs,
|
| 411 |
'asin':torch.asin,'acos':torch.acos,'atan':torch.atan,
|
| 412 |
'sinh':torch.sinh,'cosh':torch.cosh,'tanh':torch.tanh,
|
| 413 |
'pi':math.pi,'E':math.e}
|
| 414 |
+
|
| 415 |
t_func_raw=sp.lambdify([sp.Symbol(v) for v in mc.syms_used],parsed,modules=[pt_map,"math"])
|
| 416 |
|
| 417 |
def _t_wrapper(*args):
|
|
|
|
| 420 |
if not isinstance(val, torch.Tensor):
|
| 421 |
val = torch.tensor(float(val), device=DEVICE, dtype=torch.float32)
|
| 422 |
except Exception:
|
| 423 |
+
val = torch.tensor(1e6, device=DEVICE, dtype=torch.float32)
|
| 424 |
+
# Replaced 1e15 with 1e6 so MSE squares to 1e12, preserving float32 precision
|
| 425 |
+
return torch.nan_to_num(val, posinf=1e6, neginf=-1e6, nan=1e6)
|
|
|
|
| 426 |
|
| 427 |
mc.torch_func=_t_wrapper
|
| 428 |
if kind=="equality":
|
|
|
|
| 543 |
elif mc.direction=="geq": total+=(torch.relu(-val)**2)*eff_weight
|
| 544 |
else: total+=(torch.relu(val)**2)*eff_weight
|
| 545 |
for i,v in enumerate(self.variables):
|
| 546 |
+
lo,hi=_c15(self.bounds[v][0]),_c15(self.bounds[v][1])
|
| 547 |
col=X[:,i] if is_batched else X[i]
|
| 548 |
margin=(hi-lo)*0.1*(1.0-step_ratio)
|
| 549 |
out_of_bounds=torch.relu(lo-margin-col)+torch.relu(col-(hi+margin))
|
|
|
|
| 551 |
|
| 552 |
if is_optimizing and self.minimize_var and self.minimize_var in self.var_idx:
|
| 553 |
midx = self.var_idx[self.minimize_var]
|
| 554 |
+
lo,hi = _c15(self.bounds[self.minimize_var][0]), _c15(self.bounds[self.minimize_var][1])
|
| 555 |
rng = max(hi-lo, 1e-8)
|
| 556 |
col = X[:,midx] if is_batched else X[midx]
|
| 557 |
normalized = (col - lo) / rng
|
|
|
|
| 560 |
return total.view(batch_size,-1).sum(dim=1)
|
| 561 |
|
| 562 |
def scalar_energy(self, b: Dict[str,float]) -> float:
|
| 563 |
+
x_arr=[b.get(v,(_c15(self.bounds.get(v,(-1,1))[0])+_c15(self.bounds.get(v,(-1,1))[1]))/2) for v in self.variables]
|
| 564 |
X_t=torch.tensor(x_arr,device=DEVICE,dtype=torch.float32).unsqueeze(0)
|
| 565 |
with torch.no_grad():
|
| 566 |
return float(self.tensor_energy(X_t, step_ratio=1.0, is_optimizing=False).item())
|
|
|
|
| 1688 |
xr, mr, tr = [], [], []
|
| 1689 |
active_vars=problem.get_markov_blanket(set(hyp.pinned_vars.keys()), depth=2)
|
| 1690 |
for j,v in enumerate(problem.variables):
|
| 1691 |
+
lo,hi=_c15(problem.bounds[v][0]),_c15(problem.bounds[v][1])
|
| 1692 |
if v in hyp.pinned_vars:
|
| 1693 |
+
val=_c15(hyp.pinned_vars[v])
|
| 1694 |
xr.append(val); mr.append(0.0); tr.append(val)
|
| 1695 |
else:
|
| 1696 |
+
val=_c15(hyp.binding.get(v,(lo+hi)/2))
|
| 1697 |
is_active=(v in active_vars) or (len(hyp.pinned_vars)==0)
|
| 1698 |
xr.append(val); mr.append(1.0 if is_active else 0.0); tr.append(0.0)
|
| 1699 |
x_data.append(xr); mask_data.append(mr); target_data.append(tr)
|
|
|
|
| 1719 |
optimizer.step()
|
| 1720 |
X.data = torch.where(mask == 0.0, target, X.data)
|
| 1721 |
for j, v in enumerate(problem.variables):
|
| 1722 |
+
lo, hi = _c15(problem.bounds[v][0]), _c15(problem.bounds[v][1])
|
| 1723 |
margin = (hi - lo) * 0.1 * (1.0 - step_ratio)
|
| 1724 |
X.data[:, j] = torch.clamp(X.data[:, j], lo - margin, hi + margin)
|
| 1725 |
|
|
|
|
| 1745 |
|
| 1746 |
def _mprt_sample(problem, work_box, N):
|
| 1747 |
var_list=problem.variables; V=len(var_list)
|
| 1748 |
+
lo_t=torch.tensor([_c15(max(problem.bounds.get(v,(-10.0,10.0))[0], work_box[v].lo if v in work_box else problem.bounds.get(v,(-10,10))[0])) for v in var_list], device=DEVICE, dtype=torch.float32)
|
| 1749 |
+
hi_t=torch.tensor([_c15(min(problem.bounds.get(v,(-10.0,10.0))[1], work_box[v].hi if v in work_box else problem.bounds.get(v,(-10,10))[1])) for v in var_list], device=DEVICE, dtype=torch.float32)
|
| 1750 |
for i in range(V):
|
| 1751 |
if lo_t[i]>=hi_t[i]: m=(lo_t[i]+hi_t[i])/2; lo_t[i]=m-1e-6; hi_t[i]=m+1e-6
|
| 1752 |
X=lo_t.unsqueeze(0)+(hi_t-lo_t).unsqueeze(0)*torch.rand((N,V), device=DEVICE)
|
|
|
|
| 2179 |
g1_pass,g2_pass,inv_results,_=_verify(final_b,base_problem,axl_def.anchors)
|
| 2180 |
improved=final_ce<best_ce; passed_pruning=final_ce<parent_ce*CE_EARN_RATIO
|
| 2181 |
|
|
|
|
|
|
|
| 2182 |
force_ui_scout = not improved and not passed_pruning and (total_fired - last_ui_update_fired > 2000)
|
| 2183 |
|
| 2184 |
if improved or (g1_pass and g2_pass) or passed_pruning or force_ui_scout:
|
|
|
|
| 2196 |
out_baton=Baton(binding=final_b,ce=final_ce,ray_id=ray.ray_id,
|
| 2197 |
l9=L9Certificate(final_ce,dom_vars,[],tension_class))
|
| 2198 |
|
| 2199 |
+
# AUTO-RATCHETING REGISTRY FIX: Scales with best_ce so search never stalls
|
| 2200 |
+
dynamic_baton_thresh = max(BATON_REGISTRY_THRESHOLD, best_ce * 1.2)
|
|
|
|
| 2201 |
if final_ce < dynamic_baton_thresh:
|
| 2202 |
baton_registry[ray.ray_id] = out_baton
|
| 2203 |
if len(baton_registry) > BATON_REGISTRY_MAX:
|
|
|
|
| 2268 |
RULES: USE ** FOR EXPONENTS. NEVER USE ^. No =, >=, <= inside expressions.
|
| 2269 |
EQ/GEQ/LEQ are expression's relation to zero. Output ONLY the JSON object."""
|
| 2270 |
|
| 2271 |
+
COLLAPSER_SYSTEM_PROMPT = """You are the Grounded Hypothesis Engine for Practicality 27.6.
|
| 2272 |
|
| 2273 |
Check infeasibility_report first. If non-empty: the system proved infeasibility via
|
| 2274 |
algebraic propagation before firing any rays. Output:
|
|
|
|
| 2674 |
return a_cache
|
| 2675 |
|
| 2676 |
# ββ Gradio App ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2677 |
+
with gr.Blocks(css=CSS, title="Practicality 27.6") as demo:
|
| 2678 |
gr.Markdown(
|
| 2679 |
+
"## β Practicality 27.6 β The Safe-Math Core\n"
|
| 2680 |
+
"`[Direct Parser / LLM] -> [Safe Log/Sqrt Intercepts] -> [Orig Space Adam] -> [Dynamic Re-seeding]`"
|
| 2681 |
)
|
| 2682 |
|
| 2683 |
dash_cache = gr.State({"html": ""})
|
|
|
|
| 2724 |
value=(f"Compute: {DEVICE.type.upper()}\n"
|
| 2725 |
f"Axioms: {len(ALL_AXIOMS)}\n"
|
| 2726 |
f"Templates: {len(STRUCTURAL_HYPOTHESIS_TEMPLATES)}\n"
|
| 2727 |
+
f"\n27.6 UPDATES (Safe-Math Paradigm):\n"
|
| 2728 |
+
f" β LOBOTOMY FIXED: Bounds clamp restored\n"
|
| 2729 |
+
f" to 1e15. 1,000,000 qubits now allowed.\n"
|
| 2730 |
+
f" β SAFE MATH: Tensors no longer throw NaN.\n"
|
| 2731 |
+
f" log() and sqrt() are dynamically clamped >1e-7.\n"
|
| 2732 |
+
f" Gradients naturally pull out of negative valleys.\n"
|
| 2733 |
+
f" β REGISTRY RATCHET: The 100,000 CE cap is gone.\n"
|
| 2734 |
+
f" Registry tracks max(2.0, best_ce * 1.2).\n"
|
| 2735 |
+
f" The 573-ray death loop is permanently fixed.\n"
|
| 2736 |
+
f"\n27.5 FEATURES RETAINED:\n"
|
| 2737 |
f" Fail-Fast execution (No retries)\n"
|
| 2738 |
f" ray.depth < 1 unconditional branching.\n"
|
| 2739 |
f" MINIMIZE Soft Objectives (isolated)\n"
|
|
|
|
| 2740 |
f"\n MAX_RAYS={MAX_RAYS_PER_ATTEMPT:,}\n"
|
| 2741 |
f" MAX_CHAIN_DEPTH={MAX_CHAIN_DEPTH}"),
|
| 2742 |
lines=35,interactive=False,elem_classes=["solver-log"])
|
|
|
|
| 2765 |
outputs=[live_html,dash_cache,ans_cache],
|
| 2766 |
js="""
|
| 2767 |
function() {
|
| 2768 |
+
if (!window._p276_dash) {
|
| 2769 |
+
window._p276_dash = setInterval(() => {
|
| 2770 |
const el = document.getElementById('dash_poll_btn');
|
| 2771 |
if (!el) return;
|
| 2772 |
(el.tagName === 'BUTTON' ? el : el.querySelector('button'))?.click();
|
| 2773 |
}, 1000);
|
| 2774 |
}
|
| 2775 |
+
if (!window._p276_ans) {
|
| 2776 |
+
window._p276_ans = setInterval(() => {
|
| 2777 |
const el = document.getElementById('ans_poll_btn');
|
| 2778 |
if (!el) return;
|
| 2779 |
(el.tagName === 'BUTTON' ? el : el.querySelector('button'))?.click();
|
|
|
|
| 2811 |
outputs=[ans_cache])
|
| 2812 |
|
| 2813 |
gr.Markdown(
|
| 2814 |
+
f"Practicality 27.6 Β· Safe-Math Integration Β· Auto-Ratcheting Registry",
|
| 2815 |
elem_classes=["status-bar"])
|
| 2816 |
|
| 2817 |
if __name__ == "__main__":
|
| 2818 |
+
print(f"[SYSTEM 27.6] Compute: {DEVICE.type.upper()} | Quantum={HAS_QUANTUM}")
|
| 2819 |
+
print(f"[SYSTEM 27.6] Templates: {len(STRUCTURAL_HYPOTHESIS_TEMPLATES)}")
|
| 2820 |
+
print(f"[SYSTEM 27.6] Fixes: Safe Math intercepted log() limits. 1e15 bounds restored.")
|
| 2821 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|