everydaytok commited on
Commit
21bddda
·
verified ·
1 Parent(s): 4a4e4fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -30
app.py CHANGED
@@ -1,6 +1,6 @@
1
  #!/usr/bin/env python3
2
  """
3
- PRACTICALITY SYSTEM 3.11
4
 
5
  ===================================================================
6
  ARCHITECTURE & TENSOR TRANSITION MANIFESTO (V4.0 PREP)
@@ -23,16 +23,14 @@ without regressions, we must adhere to the following mapping:
23
  Invalid regions generate boolean bitmasks `valid_mask = np.ones(N_boxes)`.
24
  ===================================================================
25
 
26
- Changes from 3.10:
27
- FIX 1 — Coordinate Walker State Bug: V3.10 successfully evaluated CE spikes
28
- but failed to persist them into the walking binding, effectively
29
- paralyzing the walker and crashing chain10's solve rate. The state
30
- tracking is now correctly decoupled: the walker takes the spike, while
31
- the absolute `best_overall` state is safely preserved.
32
- FIX 2 Topological Shrink State Bug: V3.10 shrank variables to avoid math
33
- domain errors (negative roots) but didn't save the shrunk variables
34
- to the binding. It now formally updates the binding dependencies,
35
- which creates the geometric tractor-beam fully10 requires.
36
  """
37
 
38
  import asyncio, time, random, math, threading, warnings
@@ -260,7 +258,7 @@ def expand_psl(prog:PSLProgram) -> ExpandedProblem:
260
 
261
  def add_con(kind,expr,direction,scope="root",weight=1.0,branches=None):
262
  idx=len(constraints)
263
- constraints.append(Constraint(kind,expr,direction,weight,scope,branches or []))
264
  scope_groups[scope].append(idx)
265
  try:
266
  syms={v:sp.Symbol(v) for v in variables}
@@ -617,7 +615,8 @@ def _global_hc4_tighten(problem:Problem) -> Dict[str,Tuple[float,float]]:
617
  if orig_vol > 0 and new_vol < orig_vol * HC4_VOLUME_FLOOR: return dict(problem.bounds)
618
  return {v:(max(problem.bounds[v][0], contracted[v].lo), min(problem.bounds[v][1], contracted[v].hi)) for v in problem.bounds if v in contracted}
619
 
620
- def _single_snap_pass(problem: Problem, current_binding: Dict[str, float], ordered_vars: List[str], current_ce: float, spike_tolerance: float) -> Tuple[Dict[str, float], float, bool]:
 
621
  l9 = RESIDUAL_ORACLE.evaluate(current_binding, problem,[])
622
  if not l9.dominant_exprs:
623
  return current_binding, current_ce, False
@@ -643,7 +642,6 @@ def _single_snap_pass(problem: Problem, current_binding: Dict[str, float], order
643
  args = [test_binding.get(s, 0.0) for s in proj["syms"]]
644
  val = float(proj["func"](*args))
645
  except (ValueError, TypeError):
646
- # FIX 2: Topological Shrink. Safe state persistence.
647
  for s in proj["syms"]:
648
  lo, hi = problem.bounds.get(s, (-1e18, 1e18))
649
  mid = (lo + hi) / 2.0 if lo != -1e18 else 0.0
@@ -662,9 +660,8 @@ def _single_snap_pass(problem: Problem, current_binding: Dict[str, float], order
662
  test_binding[v] = val
663
  new_ce = problem.constraint_energy(test_binding)
664
 
665
- # FIX 1: Proper state tracking for spikes.
666
- # Returns immediately so caller can preserve the spike into the next round.
667
- if new_ce < current_ce * (1 + spike_tolerance):
668
  return test_binding, new_ce, True
669
 
670
  return current_binding, current_ce, False
@@ -676,6 +673,7 @@ def _algebraic_snap(problem: Problem, binding: Dict[str, float]) -> Tuple[Dict[s
676
  active_scopes = [s for s in problem.scope_order if s != "root" and problem.scope_vars.get(s)]
677
  l7 = TOPOLOGY_ORACLE.evaluate(problem, active_scopes)
678
 
 
679
  ordered_vars =[]
680
  if l7.solve_order:
681
  for sn in l7.solve_order:
@@ -684,24 +682,38 @@ def _algebraic_snap(problem: Problem, binding: Dict[str, float]) -> Tuple[Dict[s
684
  for v in problem.variables:
685
  if v not in ordered_vars: ordered_vars.append(v)
686
 
687
- # 1. Causal order pass
688
  causal_b = dict(binding)
689
  causal_ce = best_ce_overall
 
690
  for _ in range(20):
691
- causal_b, causal_ce, improved = _single_snap_pass(problem, causal_b, ordered_vars, causal_ce, 0.15)
692
- if causal_ce < best_ce_overall:
693
- best_ce_overall = causal_ce
694
- best_binding_overall = dict(causal_b)
 
 
 
 
695
  if not improved or causal_ce < SOLVE_THRESHOLD: break
696
 
697
- # 2. Greedy order pass
698
  greedy_b = dict(binding)
699
  greedy_ce = problem.constraint_energy(binding)
 
700
  for _ in range(20):
701
- greedy_b, greedy_ce, improved = _single_snap_pass(problem, greedy_b, problem.variables, greedy_ce, 0.15)
702
- if greedy_ce < best_ce_overall:
703
- best_ce_overall = greedy_ce
704
- best_binding_overall = dict(greedy_b)
 
 
 
 
 
 
 
 
 
705
  if not improved or greedy_ce < SOLVE_THRESHOLD: break
706
 
707
  return best_binding_overall, best_ce_overall
@@ -1288,7 +1300,7 @@ async def lifespan(app: FastAPI):
1288
  yield
1289
  POOL.shutdown(wait=False)
1290
 
1291
- app = FastAPI(title="Practicality System 3.11", lifespan=lifespan)
1292
 
1293
  @app.post("/inject/{pid}")
1294
  async def inject_seed(pid:str, request:Request):
@@ -1363,7 +1375,7 @@ async def dashboard():
1363
  f"font-size:0.85em;margin:2px'>{label}: {val}</span>")
1364
 
1365
  html=f"""<!DOCTYPE html><html>
1366
- <head><title>Practicality System 3.11</title>
1367
  <meta http-equiv="refresh" content="3">
1368
  <style>
1369
  body{{background:#0a0a0a;color:#e0e0e0;font-family:monospace;padding:20px}}
@@ -1374,7 +1386,7 @@ async def dashboard():
1374
  th{{color:#444}}
1375
  .witness-box{{background:#111; border:1px solid #333; padding:15px; color:#aaa; white-space:pre-wrap; font-size:0.9em;}}
1376
  </style></head><body>
1377
- <h1>⚗ Practicality System 3.11</h1>
1378
  <div style='margin-bottom:16px;line-height:2.2em;'>
1379
  {badge("Trials",runs,"#aaa")}
1380
  {badge("Avg rounds",avg_rounds,"#aaa")}
 
1
  #!/usr/bin/env python3
2
  """
3
+ PRACTICALITY SYSTEM 3.12
4
 
5
  ===================================================================
6
  ARCHITECTURE & TENSOR TRANSITION MANIFESTO (V4.0 PREP)
 
23
  Invalid regions generate boolean bitmasks `valid_mask = np.ones(N_boxes)`.
24
  ===================================================================
25
 
26
+ Changes from 3.11:
27
+ FIX 1 — Bounded Coordinate Walker: V3.11 evaluated spikes against the rolling
28
+ `current_ce`, causing a divergent walk that ruined chain10. Spikes are
29
+ now strictly bounded against `best_ce`, allowing ridge-walking without
30
+ exponential climbing.
31
+ FIX 2 True Greedy Pass: The secondary snap pass now sorts variables dynamically
32
+ by their L9 residual impact, rather than blindly relying on the PSL file's
33
+ lexical variable order.
 
 
34
  """
35
 
36
  import asyncio, time, random, math, threading, warnings
 
258
 
259
  def add_con(kind,expr,direction,scope="root",weight=1.0,branches=None):
260
  idx=len(constraints)
261
+ constraints.append(Constraint(kind,expr,direction,weight,scope,branches or[]))
262
  scope_groups[scope].append(idx)
263
  try:
264
  syms={v:sp.Symbol(v) for v in variables}
 
615
  if orig_vol > 0 and new_vol < orig_vol * HC4_VOLUME_FLOOR: return dict(problem.bounds)
616
  return {v:(max(problem.bounds[v][0], contracted[v].lo), min(problem.bounds[v][1], contracted[v].hi)) for v in problem.bounds if v in contracted}
617
 
618
+ def _single_snap_pass(problem: Problem, current_binding: Dict[str, float], ordered_vars: List[str], current_ce: float, max_spike_ce: float) -> Tuple[Dict[str, float], float, bool]:
619
+ # FIX 1: Max Spike CE is now strictly anchored to the absolute best CE of the pass, preventing divergent walks.
620
  l9 = RESIDUAL_ORACLE.evaluate(current_binding, problem,[])
621
  if not l9.dominant_exprs:
622
  return current_binding, current_ce, False
 
642
  args = [test_binding.get(s, 0.0) for s in proj["syms"]]
643
  val = float(proj["func"](*args))
644
  except (ValueError, TypeError):
 
645
  for s in proj["syms"]:
646
  lo, hi = problem.bounds.get(s, (-1e18, 1e18))
647
  mid = (lo + hi) / 2.0 if lo != -1e18 else 0.0
 
660
  test_binding[v] = val
661
  new_ce = problem.constraint_energy(test_binding)
662
 
663
+ # Check against the absolute bound, not the rolling CE
664
+ if new_ce < max_spike_ce:
 
665
  return test_binding, new_ce, True
666
 
667
  return current_binding, current_ce, False
 
673
  active_scopes = [s for s in problem.scope_order if s != "root" and problem.scope_vars.get(s)]
674
  l7 = TOPOLOGY_ORACLE.evaluate(problem, active_scopes)
675
 
676
+ # 1. Causal order pass
677
  ordered_vars =[]
678
  if l7.solve_order:
679
  for sn in l7.solve_order:
 
682
  for v in problem.variables:
683
  if v not in ordered_vars: ordered_vars.append(v)
684
 
 
685
  causal_b = dict(binding)
686
  causal_ce = best_ce_overall
687
+ causal_best = best_ce_overall
688
  for _ in range(20):
689
+ # FIX 1: Anchor the tolerance mathematically to the best known state
690
+ max_allowable_spike = causal_best * 1.15
691
+ causal_b, causal_ce, improved = _single_snap_pass(problem, causal_b, ordered_vars, causal_ce, max_allowable_spike)
692
+ if improved and causal_ce < causal_best:
693
+ causal_best = causal_ce
694
+ if causal_ce < best_ce_overall:
695
+ best_ce_overall = causal_ce
696
+ best_binding_overall = dict(causal_b)
697
  if not improved or causal_ce < SOLVE_THRESHOLD: break
698
 
699
+ # 2. FIX 2: True Greedy Pass. Prioritize variables causing the most error dynamically.
700
  greedy_b = dict(binding)
701
  greedy_ce = problem.constraint_energy(binding)
702
+ greedy_best = greedy_ce
703
  for _ in range(20):
704
+ l9 = RESIDUAL_ORACLE.evaluate(greedy_b, problem,[])
705
+ dynamic_greedy_vars = l9.dominant_vars if l9.dominant_vars else problem.variables
706
+ # Ensure all variables are included as fallbacks
707
+ for v in problem.variables:
708
+ if v not in dynamic_greedy_vars: dynamic_greedy_vars.append(v)
709
+
710
+ max_allowable_spike = greedy_best * 1.15
711
+ greedy_b, greedy_ce, improved = _single_snap_pass(problem, greedy_b, dynamic_greedy_vars, greedy_ce, max_allowable_spike)
712
+ if improved and greedy_ce < greedy_best:
713
+ greedy_best = greedy_ce
714
+ if greedy_ce < best_ce_overall:
715
+ best_ce_overall = greedy_ce
716
+ best_binding_overall = dict(greedy_b)
717
  if not improved or greedy_ce < SOLVE_THRESHOLD: break
718
 
719
  return best_binding_overall, best_ce_overall
 
1300
  yield
1301
  POOL.shutdown(wait=False)
1302
 
1303
+ app = FastAPI(title="Practicality System 3.12", lifespan=lifespan)
1304
 
1305
  @app.post("/inject/{pid}")
1306
  async def inject_seed(pid:str, request:Request):
 
1375
  f"font-size:0.85em;margin:2px'>{label}: {val}</span>")
1376
 
1377
  html=f"""<!DOCTYPE html><html>
1378
+ <head><title>Practicality System 3.12</title>
1379
  <meta http-equiv="refresh" content="3">
1380
  <style>
1381
  body{{background:#0a0a0a;color:#e0e0e0;font-family:monospace;padding:20px}}
 
1386
  th{{color:#444}}
1387
  .witness-box{{background:#111; border:1px solid #333; padding:15px; color:#aaa; white-space:pre-wrap; font-size:0.9em;}}
1388
  </style></head><body>
1389
+ <h1>⚗ Practicality System 3.12</h1>
1390
  <div style='margin-bottom:16px;line-height:2.2em;'>
1391
  {badge("Trials",runs,"#aaa")}
1392
  {badge("Avg rounds",avg_rounds,"#aaa")}