FLARE¶
- class milp_flare.flare.FLARE(harness)[source]¶
Agentic MILP reformulation verifier.
FLARE (Formulation-Level Automated Reformulation Evaluation) uses an LLM-based agent and the Lean proof assistant to verify MILP reformulations according to the FormulationBench definition of reformulation. See the FLARE Paper for more details.
- Parameters:
- harness
Harness The agent harness to use for autoformalization and theorem proving. See Agent Harnesses for the available harnesses.
- harness
- Attributes:
- harness
Harness The configured agent harness.
- harness
Examples
Use FLARE to verify if formulation
bof problemp1from FormulationBench is a reformulation of formulationa(also see Running FLARE on FormulationBench):>>> from pathlib import Path >>> from formulation_bench import Dataset >>> from milp_flare import FLARE, FormulationInput, ParameterMapInput >>> from milp_flare.harness import ClaudeCodeHarness >>> ds = Dataset.load() >>> pair = ds.reformulations[0] # p1.a -> p1.b >>> a, b = pair.a, pair.b >>> harness = ClaudeCodeHarness(model="claude-opus-5") >>> flare = FLARE(harness=harness) >>> result = flare.verify( ... FormulationInput(a.render_markdown(), a.gen_solve_py()), ... FormulationInput(b.render_markdown(), b.gen_solve_py()), ... ParameterMapInput( ... pair.parameter_map.render_markdown(), pair.gen_map_py() ... ), ... output_path=Path("runs/p1_a_b"), ... ) [flare] monitor: tail -f runs/p1_a_b/wd/agent_output.jsonl >>> result.is_reformulation True
- start(a, b, parameter_map, output_path)[source]¶
Start a FLARE run on a pair of MILP formulations and return a handle.
Determines (asynchronously) if formulation
bis a reformulation of formulationaunder the given parameter map, according to the FormulationBench definition of reformulation. This method creates the agent working directory (see below) and starts the agent, returning aFLARERunthe caller drives to completion withFLARERun.result().output_pathis populated (byFLARERun.result()) with:The agent working directory (
wd/)The FLARE configuration (
config.json)The result dictionary (
result.json)
The agent working directory contains descriptions of each formulation, the parameter map, the agent prompt
prompt.txt(see Prompts), and the necessary Lake environment files.wd/ ├── A/ │ ├── formulation.md │ ├── solve.py │ └── Formulation.lean # written by agent ├── B/ │ ├── formulation.md │ ├── solve.py │ └── Formulation.lean # written by agent ├── map.md ├── map.py ├── Reformulation.lean # written by agent ├── prompt.txt ├── Common.lean ├── lake-manifest.json ├── lakefile.toml └── lean-toolchain
- Parameters:
- a
FormulationInput Inputs for formulation A.
- b
FormulationInput Inputs for formulation B (the candidate reformulation of A).
- parameter_map
ParameterMapInput The parameter mapping the agent must use for the reformulation construction.
- output_path
pathlib.Path Directory to populate with run artifacts.
- a
- Returns:
- run
FLARERun A handle to the in-flight run. Call
result()to block for the verdict, orcancel()to stop it.SeeRunning FLARE on FormulationBenchformoreexampleusage.
- run
- verify(a, b, parameter_map, output_path)[source]¶
Run FLARE on a pair of formulations and block for the result.
Blocking convenience equivalent to
start(a, b, parameter_map, output_path).result(). Usestart()directly when an external owner needs to hold theFLARERunhandle tocancel()it from another thread.Examples
Run FLARE on formulations
aandband inspect the result:>>> from pathlib import Path >>> from formulation_bench import Dataset >>> from milp_flare import ( ... FLARE, ... FormulationInput, ... ParameterMapInput, ... ) >>> from milp_flare.harness import ClaudeCodeHarness >>> pair = Dataset.load().reformulations[0] # p1.a -> p1.b >>> a = FormulationInput( ... pair.a.render_markdown(), pair.a.gen_solve_py() ... ) >>> b = FormulationInput( ... pair.b.render_markdown(), pair.b.gen_solve_py() ... ) >>> pmap = ParameterMapInput( ... pair.parameter_map.render_markdown(), pair.gen_map_py() ... ) >>> flare = FLARE(harness=ClaudeCodeHarness(model="claude-opus-5")) >>> result = flare.verify(a, b, pmap, output_path=Path("runs/a_b")) [flare] monitor: tail -f runs/a_b/wd/agent_output.jsonl >>> result.is_reformulation True >>> result.metadata["form_a_written"] True >>> result.cost_usd 1.49
- class milp_flare.flare.FormulationInput(formulation_md, solve_py)[source]¶
Formulation input for the FLARE agent.
- Attributes:
- formulation_md
str Markdown description of the formulation. Typically produced by
Formulation.render_markdown()from FormulationBench.- solve_py
str Python solver script with Gurobi implementation of the formulation.
FLAREdoes not execute this script; it is only used as an additional reference for the agent. Typically produced byFormulation.gen_solve_py()from FormulationBench.
- formulation_md
Examples
Construct a
FormulationInputfrom formulationp1.afrom FormulationBench:>>> from formulation_bench import Dataset >>> from milp_flare import FormulationInput >>> ds = Dataset.load() >>> a = ds.problems[1].formulations["a"] >>> inp = FormulationInput(a.render_markdown(), a.gen_solve_py()) >>> print(inp.formulation_md) # Amusement Park Ticket Machines ## Problem Description An amusement park is installing cash-based machines and card-only machines... >>> print(inp.solve_py) import json from gurobipy import Model, GRB import argparse def main(params_path: str, solution_path: str) -> None: ...
- class milp_flare.flare.ParameterMapInput(map_md, map_py)[source]¶
Parameter-map input for the FLARE agent.
The parameter map fixes the parameter mapping of the reformulation construction (see FormulationBench), so the agent proves the reformulation against a given mapping rather than searching for one.
- Attributes:
- map_md
str Markdown description of the map from formulation A’s parameters to formulation B’s. Typically produced by
Reformulation.parameter_map.render_markdown()from FormulationBench.- map_py
str Python script computing formulation B’s parameters from formulation A’s.
FLAREdoes not execute this script; it is only used as an additional reference for the agent. Typically produced byReformulation.gen_map_py()from FormulationBench.
- map_md
Examples
Construct a
ParameterMapInputfor theatobpair ofp1from FormulationBench:>>> from formulation_bench import Dataset >>> from milp_flare import ParameterMapInput >>> ds = Dataset.load() >>> pair = ds.reformulations[0] >>> inp = ParameterMapInput( ... pair.parameter_map.render_markdown(), pair.gen_map_py() ... ) >>> print(inp.map_md) # Parameter Map ... >>> print(inp.map_py) import argparse import json ...
- class milp_flare.flare.FLAREResult(is_reformulation, duration_s=None, cost_usd=None, metadata=<factory>)[source]¶
Result from FLARE.
- Attributes:
- is_reformulationbool
Final verdict. True if all sub-checks pass: both
Formulation.leanfiles compile,Reformulation.leancompiles and contains adef : MILPReformulation, and the proof issorry-free using only theSTANDARD_AXIOMS.- duration_s
float, optional Wall-clock duration of the agent run, in seconds.
- cost_usd
float, optional Estimated USD cost of the agent run.
Nonewhen the harness does not report cost.- metadata
dict[str,Any] Per-check breakdown and harness run metadata:
form_a_written,form_a_compiled,form_b_written,form_b_compiled,proof_compiled,milp_reform_found,sorry_free,no_new_axioms,axioms,agent_decision, and token counts.
- milp_flare.flare.STANDARD_AXIOMS = frozenset({'Classical.choice', 'Quot.sound', 'propext'})¶
Axioms permitted in a verified reformulation proof. All of Mathlib is built on these three; a proof depending on anything else is not trusted by FLARE.