2026-06-30 / Qi Yang
C++ in Computational Physics in the Era of LLM Agentic Coding
High-performance computational physics has always faced a practical tension: the clearest algorithms are often written in high-level languages, while the fastest programs often need C++ and CUDA.
The truly expensive part is not writing code that runs. It is maintaining a highly specialized, difficult-to-extend, and difficult-to-verify high-performance implementation. Specialized code is fast, but its long-term cost is also high.
In the era of LLM agentic coding, this cost structure is beginning to change.
Julia as oracle
In this experiment, we used Julia implementations as oracles. KrylovKit.jl and TeneT.jl define the algorithmic behavior, numerical outputs, and correctness boundaries; the LLM agent then worked around these oracles to replace key linear algebra and VUMPS paths with specialized C++ and CUDA implementations.
Every optimization had to be validated against the oracle: matching outputs, passing residual checks, CPU against CPU, and GPU against GPU.
What matters
The most important point here is not that one implementation defeated another. On the contrary, this work relies on these excellent Julia packages as reliable oracles. I especially thank Jutho for KrylovKit.jl and Xingyu Zhang for TeneT.jl. If you use the code here, please directly cite their packages.
What I find truly exciting is this: LLM agents go beyond helping us write code. They can participate in profiling, bottleneck localization, kernel rewriting, validation design, and repeated iteration under strict oracle constraints.
Throughout the entire process, I did not manually write a single line of low-level implementation code; my role was to define the target, set the constraints, check correctness, and judge whether an optimization was genuinely meaningful.
For computational physics
Physicists can devote more attention to algorithms, models, convergence, and physical interpretation, while reducing the long-term burden imposed by low-level implementation details.
This is especially relevant on GPUs, where complex kernel cooperation, memory layout, and host/device scheduling are among the hardest parts to maintain. They can now be organized into a verifiable engineering optimization loop.
My view is direct: the two-language problem will not disappear immediately, but it will be redefined. High-level languages will be responsible for ideas and correctness, low-level languages will be responsible for performance, and the most painful migration and optimization steps in between will increasingly be carried out by LLM agents.