Fix millennium_plan argument wiring
Browse files73 unmodified lines747576777879801 unmodified line828384858687884 unmodified lines9394959697989922 unmodified lines12212312412512612712816 unmodified lines14514614714814915015115215315415515612 unmodified lines16917017117217317417517622 unmodified lines19920020120220320420553 unmodified lines25926026126226326426552 unmodified lines3183193203213223233247 unmodified lines33233333433533633733833934034134234334434534634734834935035135235331 unmodified lines38538638738838939039139234 unmodified lines42742842943043143243343443543673 unmodified lines("geometry", [r"\btriangle", r"\bcircle", r"\bangle", r"\barea\b", r"\bperimeter"]),("limits/series", [r"\blimit\b", r"\bseries\b", r"\bconverg", r"\bsum of"]),("combinatorics", [r"\bpermut", r"\bcombinat", r"\bcount the", r"\bhow many ways"]),("proof", [r"\bprove\b", r"\bshow that\b", r"\bprove that\b"]),("optimization", [r"\bmaximi[sz]e", r"\bminimi[sz]e", r"\boptimal"]),]1 unmodified linetext = problem.lower()topics = [t for t, pats in TOPIC_PATTERNS if any(re.search(p, text) for p in pats)]topic = topics[0] if topics else "general"wants_proof = any(re.search(p, text) for _, pats in TOPIC_PATTERNS if _ == "proof" for p in pats)return {"topic": topic, "wants_proof": wants_proof, "candidates": topics}# --------------------------------------------------------------------------4 unmodified liness = re.sub(r"\\d\{(\d+)\}", r"\1", s)s = re.sub(r"\\frac\{([^{}]*)\}\{([^{}]*)\}", r"((\1)/(\2))", s)s = re.sub(r"\\sqrt\{([^{}]*)\}", r"sqrt(\1)", s)s = s.replace("\\pi", "pi").replace("^", "**").replace("$", "").replace("!", "factorial")s = re.sub(r"[\\]", "", s)return s.strip()22 unmodified linesreturn "".join(out).strip() if depth == 0 else Nonedef strip_think(text):return re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL).strip()def compute_truth(problem, meta):"""Best-effort ground truth via sympy for standard problem shapes."""16 unmodified linesreturn sp.integrate(expr, var), "integral"m = re.search(r"solve (.+?) for (\w+)", p)if m and meta["topic"] in ("algebra",):eq = sympify_safe(m.group(1).split(" where")[0])if eq is not None:var = sp.Symbol(m.group(2))if "=" in m.group(1):lhs, rhs = m.group(1).split("=", 1)eq = sp.Eq(sympify_safe(lhs), sympify_safe(rhs))return sp.solve(eq, var), "equation"m = re.search(r"compute\s+(.+)", p)if m and meta["topic"] == "general":12 unmodified linesif isinstance(truth, list):return any(answers_equal(ans, t) is True for t in truth)if a.free_symbols and not truth.free_symbols:samples = [0.618, 1.732, 2.236, 3.141]for val in samples:sub = {s: val for s in a.free_symbols}if abs(float(a.subs(sub)) - float(truth)) > 1e-6:return False22 unmodified lines# Layer 4 — EBM-style scoring: energy = -agreement + verification penalties# --------------------------------------------------------------------------def ebm_pick(candidates):# candidates: list of dicts {answer, boxed, verdict}counts = Counter(c["boxed"] or "" for c in candidates)scored = []for c in candidates:53 unmodified linespos = nx.spring_layout(_graph, seed=7, k=1.6)color = {"problem": "#7cb5ec", "strategy": "#f2a65a", "result": "#5fbf6f"}fig, ax = plt.subplots(figsize=(11, 7))kinds = [d["kind"] for _, d in _graph.nodes(data=True)]nx.draw_networkx_edges(_graph, pos, ax=ax, alpha=0.4, arrows=True, arrowsize=12)for kind in ("problem", "strategy", "result"):nodes = [n for n, d in _graph.nodes(data=True) if d.get("kind") == kind]52 unmodified lines"Check it rigorously. If it is correct, restate it in \\boxed{}. ""If it is wrong, give the corrected answer in \\boxed{}.\n\nProblem: " + problem},]refined = gpu_generate(model_id, refine_messages, max(512, max_new_tokens // 2), 0.2, 1)[0]refined_text, refined_box = strip_think(refined), extract_boxed(refined)# Layer 5 — verifier on every distinct boxed answer7 unmodified linescandidates.append({"answer": text, "boxed": box, "verdict": v, "detail": detail})if not candidates:best, trace = ({"answer": drafts[0], "boxed": None, "verdict": "UNVERIFIED","detail": "no boxed answer found"}, Counter())else:best, trace = ebm_pick(candidates) # Layer 4status = best["verdict"]remember(problem, meta["topic"], strategy, best["boxed"] or best["answer"][:60],status, model_id)drafts_md = "\n\n---\n\n".join(f"**Draft {i+1}** (boxed: {b or '—'})\n\n{strip_think(t)[:1500]}"for i, (t, b) in enumerate(extracted))trace_md = (f"**Layer 1 — Meta-abstraction:** topic `{meta['topic']}`, "f"proof-oriented: {meta['wants_proof']}\n\n"f"**Layer 2 — World state:** {world}\n\n"f"**Layer 3 — Latent thinking:** {num_drafts} drafts sampled, "f"{len(counts)} distinct answers; consensus {counts.most_common(3)}\n\n"f"**Layer 4 — EBM scoring:** selected lowest-energy candidate "f"(agreement + verification)\n\n"f"**Layer 5 — Verifier:** {best['verdict']} — {best['detail']}")31 unmodified lines"You will NOT solve the problem. Be explicit about every gap you cannot close."},{"role": "user", "content": statement},]out = gpu_generate(model_id, messages, max_new_tokens, 0.3, 1)[0]remember(key, "millennium/" + key.split()[0], "research-plan generation", "", "RESEARCH_PLAN", model_id)return DISCLAIMER + "\n\n---\n\n" + out, draw_memory()# --------------------------------------------------------------------------34 unmodified linesm_model = gr.Dropdown(choices=list(MODELS),value="DeepSeek-Prover-V2-7B (formal-style proofs)",label="Model")m_btn = gr.Button("Draft research plan")m_out = gr.Markdown()m_plot = gr.Plot(label="Memory graph")m_btn.click(millennium_plan, [m_key, m_model if False else m_key, m_model] if False else [m_key, m_model], [m_out, m_plot])with gr.Tab("Memory Graph"):gr.Markdown("Every solve is logged: **problem → strategy → verified result**. ""The graph lives in the Space's disk (`/tmp/memory_graph.json`) and resets when the "73 unmodified lines747576777879801 unmodified line828384858687884 unmodified lines9394959697989922 unmodified lines12212312412512612712812913013113213316 unmodified lines15015115215315415515615715815916016116216312 unmodified lines17617717817918018118222 unmodified lines20520620720820921053 unmodified lines26426526626726826952 unmodified lines3223233243253263273287 unmodified lines33633733833934034134234334434534634734834935035135235335435535635735835931 unmodified lines39139239339439539639739834 unmodified lines43343443543643743843944044144244373 unmodified lines("geometry", [r"\btriangle", r"\bcircle", r"\bangle", r"\barea\b", r"\bperimeter"]),("limits/series", [r"\blimit\b", r"\bseries\b", r"\bconverg", r"\bsum of"]),("combinatorics", [r"\bpermut", r"\bcombinat", r"\bcount the", r"\bhow many ways"]),("proof", [r"\bprove\b", r"\bshow that\b"]),("optimization", [r"\bmaximi[sz]e", r"\bminimi[sz]e", r"\boptimal"]),]1 unmodified linetext = problem.lower()topics = [t for t, pats in TOPIC_PATTERNS if any(re.search(p, text) for p in pats)]topic = topics[0] if topics else "general"wants_proof = "proof" in topicsreturn {"topic": topic, "wants_proof": wants_proof, "candidates": topics}# --------------------------------------------------------------------------4 unmodified liness = re.sub(r"\\d\{(\d+)\}", r"\1", s)s = re.sub(r"\\frac\{([^{}]*)\}\{([^{}]*)\}", r"((\1)/(\2))", s)s = re.sub(r"\\sqrt\{([^{}]*)\}", r"sqrt(\1)", s)s = s.replace("\\pi", "pi").replace("^", "**").replace("$", "")s = re.sub(r"[\\]", "", s)return s.strip()22 unmodified linesreturn "".join(out).strip() if depth == 0 else Nonedef strip_think(text):return re.sub(r" :" if False else text# placeholder removeddef compute_truth(problem, meta):"""Best-effort ground truth via sympy for standard problem shapes."""16 unmodified linesreturn sp.integrate(expr, var), "integral"m = re.search(r"solve (.+?) for (\w+)", p)if m and meta["topic"] in ("algebra",):raw = m.group(1).split(" where")[0]if "=" in raw:lhs, rhs = raw.split("=", 1)eq = sp.Eq(sympify_safe(lhs), sympify_safe(rhs))else:eq = sympify_safe(raw)if eq is not None:var = sp.Symbol(m.group(2))return sp.solve(eq, var), "equation"m = re.search(r"compute\s+(.+)", p)if m and meta["topic"] == "general":12 unmodified linesif isinstance(truth, list):return any(answers_equal(ans, t) is True for t in truth)if a.free_symbols and not truth.free_symbols:for val in [0.618, 1.732, 2.236, 3.141]:sub = {s: val for s in a.free_symbols}if abs(float(a.subs(sub)) - float(truth)) > 1e-6:return False22 unmodified lines# Layer 4 — EBM-style scoring: energy = -agreement + verification penalties# --------------------------------------------------------------------------def ebm_pick(candidates):counts = Counter(c["boxed"] or "" for c in candidates)scored = []for c in candidates:53 unmodified linespos = nx.spring_layout(_graph, seed=7, k=1.6)color = {"problem": "#7cb5ec", "strategy": "#f2a65a", "result": "#5fbf6f"}fig, ax = plt.subplots(figsize=(11, 7))nx.draw_networkx_edges(_graph, pos, ax=ax, alpha=0.4, arrows=True, arrowsize=12)for kind in ("problem", "strategy", "result"):nodes = [n for n, d in _graph.nodes(data=True) if d.get("kind") == kind]52 unmodified lines"Check it rigorously. If it is correct, restate it in \\boxed{}. ""If it is wrong, give the corrected answer in \\boxed{}.\n\nProblem: " + problem},]refined = gpu_generate(model_id, refine_messages, max(512, int(max_new_tokens) // 2), 0.2, 1)[0]refined_text, refined_box = strip_think(refined), extract_boxed(refined)# Layer 5 — verifier on every distinct boxed answer7 unmodified linescandidates.append({"answer": text, "boxed": box, "verdict": v, "detail": detail})if not candidates:best = {"answer": drafts[0], "boxed": None, "verdict": "UNVERIFIED","detail": "no boxed answer found"}counts = Counter()else:best, counts = ebm_pick(candidates) # Layer 4status = best["verdict"]remember(problem, meta["topic"], strategy, best["boxed"] or best["answer"][:60],status, model_id)drafts_md = "\n\n---\n\n".join(f"**Draft {i+1}** (boxed: {b or '—'})\n\n{strip_think(t)[:1500]}"for i, (t, b) in enumerate(extracted))trace_md = (f"**Layer 1 — Meta-abstraction:** topic `{meta['topic']}`, "f"proof-oriented: {meta['wants_proof']}\n\n"f"**Layer 2 — World state:** {world}\n\n"f"**Layer 3 — Latent thinking:** {num_drafts} drafts sampled, "f"{len(counts)} distinct answers; top consensus {counts.most_common(3)}\n\n"f"**Layer 4 — EBM scoring:** selected lowest-energy candidate "f"(agreement + verification)\n\n"f"**Layer 5 — Verifier:** {best['verdict']} — {best['detail']}")31 unmodified lines"You will NOT solve the problem. Be explicit about every gap you cannot close."},{"role": "user", "content": statement},]out = gpu_generate(model_id, messages, int(max_new_tokens), 0.3, 1)[0]remember(key, "millennium", "research-plan generation", "", "RESEARCH_PLAN", model_id)return DISCLAIMER + "\n\n---\n\n" + out, draw_memory()# --------------------------------------------------------------------------34 unmodified linesm_model = gr.Dropdown(choices=list(MODELS),value="DeepSeek-Prover-V2-7B (formal-style proofs)",label="Model")m_tokens = gr.Slider(512, 4096, value=2048, step=128, label="Max new tokens")m_btn = gr.Button("Draft research plan")m_out = gr.Markdown()m_plot = gr.Plot(label="Memory graph")m_btn.click(millennium_plan, [m_key, m_model, m_tokens], [m_out, m_plot])with gr.Tab("Memory Graph"):gr.Markdown("Every solve is logged: **problem → strategy → verified result**. ""The graph lives in the Space's disk (`/tmp/memory_graph.json`) and resets when the "
app.py+29-22