r/ScientificComputing • u/Low-Physics-3076 • 5d ago
I built a physics-checking workflow (PhysGate) to catch silent numerical/physical bugs when coding with AI agents
I do lightning and atmospheric physics research, and lately I kept running into an annoying problem when using AI coding agents (Claude Code, Codex, Gemini CLI) for diagnostic scripts: the Python code runs cleanly and passes basic unit tests, yet silently breaks physics. Things like negative humidity (q < 0) from spectral ringing, forgetting the cos(phi) factor in spherical divergence, or integrating pressure right through coastal mountains.
So I put together PhysGate, a small open-source SKILL.md + pytest workflow (MIT license) to keep myself from vibe-coding straight into broken math.
What it actually does:
Before writing implementation code, /physgate forces the agent to ask clarifying questions in plain language and freeze a SPEC.md file with physical red lines. Then it writes automated pytest checks for conservation laws, units, positivity/bounds, and limiting cases, splits implementation into isolated git worktree slices, and sends the result to two other model families in read-only mode for blind review instead of letting one model grade its own work.
There is a reproducible 3D North Pacific atmospheric river & jet-streak audit example in examples/ar_ai_physics_audit/ if you want to run pytest on it locally.
Repo: https://github.com/oldsixxiaolv/PhysGate
Curious how others here validate AI-generated scientific or numerical Python before trusting the plots—what invariant checks do you always enforce?