opensi·si

Mathematical proof generation and evaluation environment for OpenEnv, ported from QED-Nano. Agents receive math problems, submit proofs, and receive LLM-based rubric grading on…

QED Math

Mathematical proof generation and evaluation environment for OpenEnv, ported from QED-Nano. Agents receive math problems, submit proofs, and receive LLM-based rubric grading on a 0–7 scale with normalized rewards.

Features

  • LLM-based rubric grading (0–7 scale) via any OpenAI-compatible endpoint
  • Process-based answer verification service (math_verify in worker processes)
  • Backpressure + retries + worker restart for robust concurrent rollout operation
  • Gold-answer cache keyed by problem_id and verifier normalization settings
  • Flexible dataset loading: local JSONL/JSON, Hugging Face Hub, or built-in bootstrap problems
  • Reward shaping: discount factor, length penalty, and optional score thresholding
  • Reasoning stripping: configurable delimiters (e.g. <think>...</think>) removed before grading
  • Multi-step problems: configurable max attempts with per-attempt feedback
  • Verifier metrics: rollout/staging counters and health signals surfaced in observation metadata, ready for TrackIO / WandB
  • MCP tool interface: get_problem, submit_proof, get_grading_guidelines

Quick Start

Async (default)

import asyncio
from qed_math_env import QEDMathEnv

async def main():
    async with QEDMathEnv(base_url="http://localhost:8000") as env:
        # Reset to load a problem
        result = await env.reset()
        obs = result.observation
        print(f"Problem: {obs.problem[:100]}...")

        # Submit a proof
        submission = await env.submit_proof(proof="By induction on n...")
        print(f"Score: {submission.score}/7, Reward: {submission.reward:.2f}")

asyncio.run(main())

Sync

from qed_math_env import QEDMathEnv

with QEDMathEnv(base_url="http://localhost:8000").sync() as env:
    result = env.reset()
    submission = env.call_tool("submit_proof", proof="By induction on n...")

MCP tool-calling

async with QEDMathEnv(base_url="http://localhost:8000") as env:
    await env.reset()

    # Discover tools
    tools = await env.list_tools()
    print([t.name for t in tools])
    # ['get_problem', 'submit_proof', 'get_grading_guidelines']

    # Call tools by name
    problem = await env.call_tool("get_problem")
    guidelines = await env.call_tool("get_grading_guidelines")
    result = await env.call_tool("submit_proof", proof="...")

Building & Running

# Build Docker image (from project root)
docker build -t qed-math-env:latest -f envs/qed_math_env/server/Dockerfile .

# Run the server
docker run -p 8000:8000 -e OPENAI_API_KEY=$OPENAI_API_KEY qed-math-env:latest

# Or run locally with uvicorn
PYTHONPATH=src:envs uvicorn qed_math_env.server.app:app --port 8000

# Or install and run via uv
cd envs/qed_math_env
uv sync
uv run server

Project Structure

qed_math_env/
├── __init__.py              # Module exports (QEDMathEnv, models)
├── models.py                # ProblemObservation, ProofSubmissionObservation
├── client.py                # QEDMathEnv client (MCPToolClient subclass)
├── openenv.yaml             # OpenEnv manifest with metrics declarations
├── pyproject.toml           # Dependencies
├── uv.lock                  # Locked dependencies
├── README.md
├── prompts/
│   └── evaluator_prompts/
│       ├── v0.md            # Evaluator prompt (QED-Nano v0, uses reference solution)
│       ├── v1.md            # Evaluator prompt (QED-Nano v1, default, full 0–7 range)
│       └── v2.md            # Evaluator prompt (QED-Nano v2, scores constrained to {0,1,6,7})
└── server/
    ├── __init__.py
    ├── app.py               # FastAPI server (create_app factory)
    ├── qed_math_environment.py  # QEDMathEnvironment (MCPEnvironment)
    ├── math_verify_service.py   # Process-pool verifier service + health/metrics
    ├── mcp_server.py        # MCP tool registration
    ├── rubric.py            # MathProofRubric + GradingResult
    └── Dockerfile

Configuration

The environment is configured via QEDMathConfig:

テーブル(20 行)
Parameter Default Description
dataset_path None Dataset source: local path, Hub ID, or list of specs. None uses bootstrap problems.
grader_model "gemini-3-pro" Model identifier for the LLM grader (any OpenAI-compatible endpoint)
prompt_name "v1" Evaluator prompt template name (v0, v1, or v2 in prompts/evaluator_prompts/). v1 matches the QED-Nano default (full 0–7 range); v2 constrains scores to {0,1,6,7}
grader_temperature 1.0 Sampling temperature forwarded to the grader (matches QED-Nano)
grader_max_output_tokens None Optional output-token cap for the grader. None uses the provider default to avoid truncating the trailing <score> tag
custom_reward_threshold False When True, collapses partial-credit scores 1–5 → 1
answer_reward_preset "pure_success" Answer-mode reward table: pure_success (correct→1, else 0) or base (adds penalties: wrong −0.5, no_answer/unparsable −1)
max_attempts 1 Max proof attempts per problem (>1 for multi-step)
discount_factor 1.0 Exponential discount: reward *= discount_factor ** output_length_tokens
buffer_tokens 0 Length penalty zone width. 0 disables the penalty.
max_tokens 0 Max token limit for length penalty computation
reasoning_delimiters ["</think>"] Delimiter strings to strip reasoning before grading (matches QED-Nano). Set to None to grade the full completion.
verifier_workers max(2, min(8, cpu_count//2)) Number of process workers used for answer-mode verification
verifier_queue_size verifier_workers * 32 Max in-flight verifier requests before backpressure
verifier_request_timeout_seconds 5.0 Per-request client-side timeout when awaiting worker response
verifier_max_retries 1 Retry budget for transient verifier infra failures
verifier_strict True Strict math_verify equivalence mode
verifier_numeric_precision 5 Numeric precision setting used in verifier request contract
verifier_float_rounding 10 Float rounding setting used in verifier request contract

Environment variables:

  • OPENAI_API_KEY — API key for the grader LLM
  • OPENAI_BASE_URL — Base URL override (for non-OpenAI providers)

Dataset Format

Local JSONL/JSON

{
  "problem": "Prove that the sum of two even integers is even.",
  "solution": "Let a=2m and b=2n. Then a+b=2(m+n), which is even.",
  "rubrics": [
    {"title": "Definitions", "points": 2, "desc": "Correctly defines even integers."},
    {"title": "Algebra", "points": 3, "desc": "Valid algebraic manipulation."},
    {"title": "Conclusion", "points": 2, "desc": "Correctly concludes evenness."}
  ],
  "dataset": "FineProofs-RL",
  "problem_id": "fp_001"
}

Hugging Face Hub

QEDMathConfig(dataset_path="meta-math/MetaMathQA")
# or with config
QEDMathConfig(dataset_path={"hub_id": "meta-math/MetaMathQA", "split": "train", "config": "default"})

Field Aliases

The environment normalizes many dataset formats automatically:

Canonical Field Accepted Aliases
problem task, Problem
reference_solution solution, answer, Solution
grading_guidelines rubrics, schema, schema_0, Grading guidelines, details
problem_id id
original_problem Used for RC-stream problems where the actor prompt differs from grading prompt

Observation Space

ProblemObservation (from reset / get_problem)

Field Type Description
problem str Math problem statement
reference_solution str Always empty. The ground-truth solution stays on the server and is only used for grading.
grading_guidelines str Rubric / marking scheme
problem_id str Unique identifier
problem_type str "proof", "answer", or "multi_step"
dataset_source str Source dataset name
metadata dict Additional context (e.g. original_problem)

ProofSubmissionObservation (from submit_proof)

Field Type Description
proof str Submitted proof text
score int Raw grade (0–7)
feedback str Full grader response
reward float Shaped reward in [0, 1]
done bool Whether the episode is over
is_correct bool Whether score >= success threshold (default 7, matching QED-Nano's score == 7)
attempt_number int Current attempt count
attempts_remaining int Remaining attempts
problem_type str Problem type
metadata dict Contains verifier_metrics, base_reward, shaped_reward