Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions backend/cms_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""CryptoMiniSat baseline wrapper (pycryptosat) -- a fair competitor to beat.

CryptoMiniSat is the strongest widely-used CDCL solver that also carries a native
GF(2) Gaussian engine, so it OWNS the parity fragment (it is the honest hard case
for our parity frame -- see BEYOND_CDCL_NOTE.md) while remaining a strong general
CDCL. This wrapper runs it on the RAW CNF, exactly as Kissat and CaDiCaL receive it
(no XOR pre-extraction on our side), so the comparison is apples-to-apples: whatever
structure CMS exploits, it finds itself.

It is a BASELINE competitor, not part of the certified path: SAT models are replayed
against the CNF (verify, don't trust), but CMS UNSAT is not DRAT-certified here (the
Python binding does not emit a proof) -- our own certified UNSAT always comes from a
frame refutation or from DRAT-checked Kissat, never from CMS.
"""

from __future__ import annotations

import time
from dataclasses import dataclass
from typing import Dict, Optional

from .cnf_utils import CNFFormula, verify_model


@dataclass
class CMSResult:
status: str # 'SAT' | 'UNSAT' | 'TIMEOUT'
seconds: float
model: Optional[Dict[int, bool]] # 1-indexed, when SAT
verified: bool # SAT model replayed against the CNF


def cms_solve(formula: CNFFormula, timeout_s: float = 20.0) -> CMSResult:
"""Solve `formula` with CryptoMiniSat on the raw CNF. Returns a CMSResult; a SAT
model is independently re-verified. TIMEOUT (or an 'unknown' return) maps to
status 'TIMEOUT'."""
from pycryptosat import Solver
solver = Solver(time_limit=max(1, int(timeout_s)))
for clause in formula.clauses:
if clause: # CMS rejects the empty clause add
solver.add_clause(list(clause))
else:
# an explicit empty clause is an immediate refutation
return CMSResult('UNSAT', 0.0, None, False)
t0 = time.perf_counter()
sat, solution = solver.solve()
dt = time.perf_counter() - t0
if sat is None: # time/confl limit -> undecided
return CMSResult('TIMEOUT', dt, None, False)
if sat:
# pycryptosat solution is indexed by variable (solution[0] is None); it can
# be shorter than num_vars+1 when trailing variables never appear in a clause
# -- those are free, default them to False.
model = {v: (bool(solution[v]) if v < len(solution) else False)
for v in range(1, formula.num_vars + 1)}
return CMSResult('SAT', dt, model, verify_model(formula, model))
return CMSResult('UNSAT', dt, None, False)
109 changes: 109 additions & 0 deletions backend/dynamics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""dynamics -- the view from outside: the laws, relations and motions of an
instance's solve, collected as one dynamical description.

Floating outside the model, we do not solve first -- we DESCRIBE. An instance,
before any CDCL search, already exhibits a dynamical signature under the coupled
frame router, and this module reads it into three registers:

LAWS the invariants -- what is conserved / cannot change under the solve:
which algebraic conserved quantities are present (a GF(2) parity
invariant, a ℤ counting bound, a 2-SAT implication closure), and whether
the verdict is sound-by-construction.
RELATIONS the couplings -- how the frames talk: the literals one frame ENTAILS and
hands to the others (the Nelson-Oppen exchange), and how many cross.
MOTIONS the trajectory -- how the state moves: the breath (entailed-literal count
per coupling round), its amplitude, whether it resonates to rest, and the
instance's position in the hyperbolic mesh (gyration/depth toward ∂∞) and
relative to the decidability fold (island / fold / tunnel).

This description is the bridge the operator asked for: collect the laws/relations/
motions dynamically, then REVERT them into an operational dispatch (backend/
metasolver.py) -- use the descriptive power precisely where the concrete frames and
geometry do not suffice. The description is sound to read (every entailed literal is
genuinely implied); it is a *predictor/driver*, never itself a verdict.
"""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Dict, List

from .cnf_utils import CNFFormula
from .fabric import fabric
from .frame_solver import coupling_breath


@dataclass
class Dynamics:
# --- LAWS: the invariants (what is conserved under the solve) ---
conserved: List[str] # present algebraic invariants: parity|counting|implication
verdict: str # 'SAT' | 'UNSAT' | 'CDCL_NEEDED' (frame/coupling)
certified: bool # verdict sound by construction (not CDCL_NEEDED)

# --- RELATIONS: the couplings (how the frames exchange entailed facts) ---
entailed: Dict[int, bool] # literals the coupling entails (the exchange)
coupling_rank: int # |entailed| -- strength of the cross-frame relation

# --- MOTIONS: the trajectory (how the state moves) ---
breath: List[int] # |fixed| after each coupling round (the inhale)
amplitude: int # deepest single-round intake
settled: bool # resonated to a fixpoint/conflict (rest)
gyration: float # hyperbolic depth (distance toward the boundary ∂∞)
region: str # 'island' | 'fold' | 'tunnel'
predicted_frame: str # the fabric's shallowest-frame guess

# a compact, hashable signature of the whole dynamical state
signature: tuple = field(default=())

def sufficient(self) -> bool:
"""True when frame + geometry already suffice -- a certified verdict with no
CDCL needed. When False, the description is the lever the metasolver reverts
into a dispatch (this is 'where frame and geometry do not suffice')."""
return self.certified

def as_record(self) -> Dict[str, object]:
return {
"conserved": self.conserved, "verdict": self.verdict,
"certified": self.certified, "coupling_rank": self.coupling_rank,
"amplitude": self.amplitude, "settled": self.settled,
"gyration": round(self.gyration, 3), "region": self.region,
"predicted_frame": self.predicted_frame,
}


def _conserved_invariants(formula: CNFFormula, fb) -> List[str]:
"""Which algebraic conserved quantities the instance carries (its 'laws')."""
laws: List[str] = []
if fb.parity_signal > 0.0:
laws.append("parity") # a GF(2) invariant lives here
if fb.counting_signal > 0.0 or fb.orbit_coarseness >= 0.6:
laws.append("counting") # a ℤ magnitude bound / symmetry to count on
if fb.implication_signal > 0.0:
laws.append("implication") # a 2-SAT closure
return laws


def describe(formula: CNFFormula) -> Dynamics:
"""Read the instance's full dynamical description -- the view from outside. Runs
the coupled router as a dynamical instrument (coupling_breath) and the fabric as
the geometric read; collects both into the laws/relations/motions registers."""
fb = fabric(formula)
bt = coupling_breath(formula)
entailed = dict(bt.entailed or {})
conserved = _conserved_invariants(formula, fb)
dyn = Dynamics(
conserved=conserved,
verdict=bt.verdict,
certified=(bt.verdict != "CDCL_NEEDED"),
entailed=entailed,
coupling_rank=len(entailed),
breath=list(bt.breath),
amplitude=bt.amplitude,
settled=bt.settled,
gyration=fb.gyration,
region=fb.region,
predicted_frame=fb.predicted_frame,
)
dyn.signature = (tuple(conserved), dyn.verdict, dyn.region,
round(dyn.gyration, 2), dyn.coupling_rank)
return dyn
9 changes: 6 additions & 3 deletions backend/fabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@dataclass
class Fabric:
parity_kind: str # 'consistent'|'inconsistent'|'nostruct'
parity_signal: float # XOR coverage: how much of the formula IS parity (0..1)
rank_deficiency: float # parity thread: 0 determined ... 1 free (fold ~0.05)
orbit_coarseness: float # orbit thread: 0 rigid ... 1 highly symmetric (fold ~0.9)
gyration: float # hyperbolic depth (distance to the boundary ∂∞)
Expand All @@ -42,8 +43,9 @@ class Fabric:
predicted_frame: str

def as_dict(self) -> Dict[str, float]:
return {"rank_def": self.rank_deficiency, "orbit": self.orbit_coarseness,
"gyration": self.gyration, "counting": self.counting_signal,
return {"parity": self.parity_signal, "rank_def": self.rank_deficiency,
"orbit": self.orbit_coarseness, "gyration": self.gyration,
"counting": self.counting_signal,
"implication": self.implication_signal, "ratio": self.ratio}


Expand All @@ -60,9 +62,10 @@ def fabric(formula: CNFFormula) -> Fabric:
r = scout(formula)
return Fabric(
parity_kind=kind,
parity_signal=r.features.get("xor", 0.0),
rank_deficiency=defic,
orbit_coarseness=orbit,
gyration=hyperbolic_depth(formula),
gyration=hyperbolic_depth(formula, exact=False),
counting_signal=amo,
implication_signal=binf,
ratio=m / n,
Expand Down
Loading
Loading