How to catch "runs fine, physics is wrong" bugs in LLM-written code?

1 reply · 161 views · last reply
YihangLyu
Messages
1
Reaction score
1
TL;DR
LLM scripts often run cleanly while getting the physics wrong (examples attached from a quick ERA5 check). What simple sanity checks do you use?
Hi everyone,

I'm a first-year grad student in atmospheric science (mostly extreme precipitation and satellite data). When I use LLMs to help write Python analysis scripts, the annoying part isn't syntax errors. The code usually runs fine and gives numbers that look normal, until you notice the physics or geometry is wrong.

I plotted two quick examples using an ERA5 precip file I had on hand (attached). In (a), the script forgot cos(lat) when taking the global mean, so it gave 2.39 mm/day instead of 2.91 mm/day (about 18% off). In (b), it used tp > 0 for wet days and flagged 89% of the globe as rainy, instead of a standard 1.0 mm/day threshold (42%), and ignored tiny negative values in the dataset.

I want to put a few simple checks in my workflow before trusting any script output (units, area weights, non-negative bounds, etc.). If you write scientific code regularly, what basic sanity checks do you usually include to catch silent errors like this?
 
Attachments
  • era5_sanity_checks_pf.webp
    era5_sanity_checks_pf.webp
    106 KB · Views: 1
The model assumes you are in control of physics and it is fitting the math to your physics. If the physics is wrong, it is usually because either it doesn't know which framework you are using or because you have contaminated your context with a different framework. "Physics" isn't a set thing in it's mind because it knows every framework and they are all potentially valid for what you might be doing. Contaminate the context and it is impossible to fix. The whole chat and possibly even whole project needs to deleted and begun again. A similar, but different problem can happen if the context limitation of the model cannot hold everything it needs to in order to conceptualize your framework and produce a result. In that instance, the issue is that it can never fully process anything to a conclusion. There is no simple check for either except you. Finally, it is very difficult to be certain a model has fully read and understood any particular source material even when the context is large enough. For that there is a fix, but only if you are the one creating the document. See the primary the build_ocean_formalism.py and the first page of Ocean_Scalar_Tensor_Hydrodynamics_v3_16.pdf here: https://github.com/hunanguy/Ocean
 
Last edited: