Research-Stack/5-Applications/scripts/map_all_equations.py
devin-ai-integration[bot] fcfaef17f3 fix(scripts): replace bare except clauses with specific exception types (#77)
Replace 30+ bare `except:` and `except: pass` patterns across 17 files
with specific exception types (OSError, ValueError, etc.) and add
logging so errors are no longer silently swallowed.

Changes by category:

Infrastructure (surface/main.py):
- GPU/process probes now catch FileNotFoundError | SubprocessError

Application scripts:
- API fetchers (finalize_database, final_push, bulk_10x) now catch
  URLError | JSONDecodeError | KeyError | OSError and print to stderr
- Hardware probes (unified_hardware_surface, swarm_transport_layer)
  catch OSError | ValueError for /proc/meminfo reads
- Backend availability checks (prover_backend_interface, hot_swap_manager)
  catch requests.RequestException and log at debug/warning
- Code inspector (swarm_system_inspector) catches OSError | UnicodeDecodeError
  for file reads
- Model fallback (map_all_equations) now logs the intermediate error
- Minor: gpu_pist_compress → RuntimeError | ZeroDivisionError,
  mathlib_to_parquet → ValueError, moe_utils → OSError,
  quandela_remote → OSError | IndexError, topology inline scripts
  → ImportError, consolidate_language_databases → UnicodeDecodeError

All touched files pass py_compile.

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
2026-06-14 19:30:28 -05:00

80 lines
3.1 KiB
Python

import sys
import json
import os
import csv
from pathlib import Path
# Add project root to path
sys.path.append("/home/allaun/Research Stack")
from infra.deepseek_adapter import DeepSeekV4
def map_all_equations():
client = DeepSeekV4(use_local=True)
equations_file = "/home/allaun/Documents/Research Stack/3-Mathematical-Models/MATH_MODEL_MAP.tsv"
equations = []
with open(equations_file, 'r', encoding='utf-8') as f:
reader = csv.DictReader(f, delimiter='\t')
for row in reader:
equations.append({
"name": row.get("Model_Name", ""),
"family": row.get("Family", ""),
"domain": row.get("Domain_Type", ""),
"bind": row.get("Bind_Class", ""),
})
# Compress the list to just essential info to fit in context
# format: Name [Family/Domain]
eq_summary = []
for eq in equations:
eq_summary.append(f"{eq['name']} [{eq['family']}/{eq['domain']}]")
eq_text = "\n".join(eq_summary)
print(f"Total equations loaded: {len(equations)}")
print(f"Total prompt length (chars): {len(eq_text)}")
prompt = f"""
You are a mathematical physicist and systems architect.
I am providing you with the names and domains of EVERY equation ({len(equations)} in total) from the Sovereign Research Stack, including core primitives like PIST, Tree Fiddy, BHOCS, and more.
Your task is to analyze this massive corpus and find where EVERY equation connects to the grand unified topology.
Since there are too many to list 1-by-1, you must:
1. Identify the central HUB equations (the most fundamental roots, e.g., PIST, Tree Fiddy, RGFlow, Burgers).
2. Trace the major pathways: How do the physics equations connect to the topological and informational (neural) equations?
3. Synthesize the Grand Unified Topology of this research stack based on the families and domains provided.
Provide a comprehensive markdown report.
Equation List:
{eq_text}
"""
print("Sending prompt to DeepSeek V4...")
messages = [{"role": "user", "content": prompt}]
try:
# User explicitly asked for deepseek v4
res = client.chat(messages, model="deepseek-v4-pro:cloud")
content = res["message"]["content"]
except Exception as e:
print(f"Error using deepseek-v4-pro:cloud: {e}")
print("Falling back to deepseek-r1:32b...")
try:
res = client.chat(messages, model="deepseek-r1:32b")
content = res["message"]["content"]
except Exception as exc:
print(f"Error using deepseek-r1:32b: {exc}")
print("Falling back to deepseek-r1:8b...")
res = client.chat(messages, model="deepseek-r1:8b")
content = res["message"]["content"]
output_path = "/home/allaun/Documents/Research Stack/artifacts/master_equation_topology.md"
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, "w") as f:
f.write(content)
print(f"Mapping complete. Saved to {output_path}")
if __name__ == "__main__":
map_all_equations()