CodeJeNN: A simple C++ neural network generator for physics applications
summary
The gist
The gist The CodeJeNN library bridges the gap between Python-based machine learning libraries and high-performance C++ solvers by auto-generating self-contained C++ code from trained Keras models,
In short
CodeJeNN automatically generates self-contained C++ code from trained Keras models, bridging Python machine learning and high-performance solvers. This allows researchers to embed neural networks directly into physics simulations, replacing complex constitutive models like Wilke's. The resulting C++ code is highly optimized for speed, offering significant inference acceleration over standard Keras implementations.
Key concepts
- CodeJeNN
- A tool that converts a trained Keras model (like an MLP or CNN) into a standalone C++ header file. This eliminates the need for external dependencies like Lapack or Eigen by inlining operations, enabling seamless integration into existing high-performance C++ frameworks.
- Keras Models
- Neural networks used as surrogate models to approximate complex mappings from training data. CodeJeNN specifically targets Multi-Layer Perceptrons (MLPs) and Convolutional Neural Networks (CNNs), which are the types of models it can convert into efficient C++ code.
- Inference Speedup
- The performance gain achieved when running the generated neural network in C++ compared to running it within a standard Python Keras environment. Benchmarks show CodeJeNN can be up to 25 times faster on an Apple M1 Pro and nearly 38 times faster with PyTorch.
- CFD Surrogates
- Using a neural network as a mathematical substitute for traditional, complex physics equations (constitutive models) within Computational Fluid Dynamics (CFD) simulations. This allows researchers to maintain accuracy while speeding up computationally expensive calculations.
Terminology used across episodes
This episode discusses
- CodeJeNN: A simple C++ neural network generator for physics applications · Paper Radio
- Learning incomplete factorization preconditioners for GMRES
- Fast and Accurate Deep Network Learning by Exponential Linear Units (ELUs)
- Searching for Activation Functions
- Gaussian Error Linear Units (GELUs)
- Efficient Object Localization Using Convolutional Networks
- A guide to convolution arithmetic for deep learning
- Tokenomics: Quantifying Where Tokens Are Used in Agentic Software Engineering
- Graph Neural Networks in TensorFlow and Keras with Spektral
- Attention-based Graph Neural Network for Semi-supervised Learning
The paper
CodeJeNN: A simple C++ neural network generator for physics applications · Read on arXiv
Jay Arciti, Pavel Popova, Eric J. Ching, Kamal Viswanath, Ryan F. Johnson
San Diego State University · U.S. Naval Research Laboratory
Machine learning has shown promise for physics applications, but integrating Python-based libraries into high-performance C++ solvers can create performance bottlenecks. We present CodeJeNN, which addresses this gap by auto-generating self-contained C++ code from trained Keras models for inference. This eliminates external dependencies through inlined functions, allowing seamless integration into existing frameworks. We describe the Keras-to-C++ workflow, supported architectures, and limitations. CodeJeNN is demonstrated through inference benchmarks against Keras (eager and optimized) and a computational fluid dynamics (CFD) simulation of a hydrogen-air mixing layer in which viscosity is modeled using a neural network, showing that the generated models integrate directly into a solver while remaining efficient and accurate.
Transcript
Introduction to the show: ident: AI Radio. Generated commentary on the latest Artificial Intelligence papers.
Tom: I'm Tom.
Jane: And I'm Jane, here with Lu, Meng and our in-house large language model, Lalam.
Tom: We're looking at the paper: "CodeJeNN: A simple C++ neural network generator for physics applications".
Jane: Here's the gist of the paper. The gist The CodeJeNN library bridges the gap between Python-based machine learning libraries and high-performance C++ solvers by auto-generating self-contained C++ code from trained Keras models, eliminating external dependencies and allowing seamless integration into existing frameworks.
Tom: Machine learning has shown promise when integrated with numerical schemes for partial differential equations (PDEs), enabling research in data-driven preconditioners
1, 2: , surrogate constitutive models
3: , and physics-informed neural networks
4, 5, 6: .
Jane: However, speed and accuracy are critical during inference because most physics solvers are written in compiled languages while ML libraries are primarily Python-based, which often adds computational overhead.
Tom: The gap between ML libraries and compiled solvers often forces researchers to rely on framework-provided C++ APIs, which can be incompatible with established parallelization and vectorization codes.
Title and authors: Tom: So, we've seen the authors and the title, "CodeJeNN: A simple C++ neural network generator for physics applications." What does that actually mean in plain English? It’s essentially a tool that takes a trained model and spits out the C++ code you need to run it without hassle >
Jane: Right. It means instead of you having to manually translate every layer and activation function from Python into optimized C++ code, this system does that for you automatically >
Lu: They are auto-generating self-contained C++ code from trained Keras models, which is the big win because it cuts out the manual implementation effort >
Meng: It’s about eliminating external dependencies through minimal inlined functions, so you don't have to wrestle with those huge libraries when you try to integrate it into your existing high-performance solver >
Lalam: Think of it like an automatic translator that takes a Keras file and gives you C++ header files ready for compile time >
Tom: So, the paper is showing a workflow, from loading the saved model file using Keras' load model function to finally converting everything into a C++ header file >
Jane: And they emphasize that this process is designed so that everything is known at compile time, which means it helps with cache utilization and fast inlined computation when the code runs >
The paper's summary: Tom: Okay, so what’s the actual substance of what CodeJeNN does? It takes a trained model—whether it’s an MLP or a CNN—and converts its structure into efficient C++ code for inference >
Lu: They describe the Keras-to-C++ workflow in detail, and they show how they handle different supported architectures like Dense layers and various convolutional operations >
Meng: They list a lot of supported things, like ReLU, Sigmoid, Tanh, LeakyReLU all the way to Mish and Swish as activation functions >
Jane: And they also mention that you can even support custom activation functions if you serialize them when saving your model and define them in a Python script when loading >
Tom: The paper points out that they aggressively inline generated code wherever possible to minimize computational cost during the actual inference step >
Lalam: They focus on making sure everything is optimized for speed right from the start, so the goal is to get that C++ version running as fast as possible on a real physics problem >
The paper's improvements: Tom: Now let's talk about what they improved. The main improvement seems to be the performance boost, because they ran inference benchmarks against standard Keras implementations and got some pretty solid numbers >
Jane: They showed that CodeJeNN can execute roughly twenty-five times faster than Keras when using a TensorFlow backend for inference on an Apple MacBook M1 Pro >
Lu: And when they used PyTorch, the speedup factor was nearly thirty-eight times, which is significant for getting machine learning into real-time simulations >
Meng: That speedup is huge if you’re dealing with large datasets or complex simulations because it drastically cuts down the inference time that usually causes bottlenecks in production environments >
Tom: Beyond the speed, they demonstrated this by using a CFD test case modeling viscosity in a hydrogen-air mixing layer where the neural network replaced Wilke’s model >
Jane: That was pretty important because they showed it could replace that complex constitutive model and still maintain accuracy with a mean error of zero point one two against the reference solution >
Conclusion: Tom: So, to wrap up, CodeJeNN gives you this self-contained C++ rendition of your Keras model, which is a huge plus because it lets you optimize the raw source code directly without worrying about external tensor operations >
Jane: The real strength is producing that raw source code where everything is inlined and enclosed within a single header file, which means you don't have to export complicated tensor operations from high-performance libraries >
Lu: They are looking ahead, mentioning that future work will integrate Spektral and explore adding features to export functions using low-level high-performance libraries like Eigen >
Meng: From a deployment standpoint, the fact that it generates a clean C++ structure means less debugging time when something breaks at scale because the code is so self-contained >
Lalam: The CodeJeNN paper shows a clear path for researchers to embed these models robustly into CFD workflows as surrogates for physical models while keeping the math consistent >
Tom: So, it’s about moving ML from just a Python experiment to something you can actually deploy efficiently in a high-performance simulation environment >
More episodes
- 2605.08424-Generalized Wasserstein Flow Matching: Nested Couplings for Point Cloud Generation
- 2605.14879-Temporal Fair Division in Multi-Agent Systems: From Precise Alternation Metrics to Scalable Coordination Proxies
- 2605.18147-Tabular Foundation Models for Credit Risk Prediction: A Dedicated Review and Empirical Comparison
- 2605.22561-Regret-Based (epsilon, delta) -optimal Stopping Criteria for Bayesian Optimization
- 2605.23751-Approaching I/O-optimality for Approximate Attention
- 2605.27043-Causal Representation Learning for Generalisable Recommendation
- 2605.29748-Instance-dependent Stochastic Lipschitz bandit
- 2606.04031-Transient Amplification in Cascaded Gradient Methods: Exact Minimax Laws and Tracking without Resonance
- 2606.09623-Joint user-item allocation for e-commerce marketing campaigns
- 2606.11319-Neural networks become centroid classifiers when trained on heavily corrupted inputs