The language divide in quantitative finance is real. Quants prototype in Python. Production runs in C++. The translation between the two is expensive, error-prone, and never-ending.
The problem
A typical workflow: a quant writes a new model in Python with NumPy. It works. Risk engineering rewrites it in C++ for production. The C++ version has a bug that takes two weeks to find. Meanwhile, the quant has updated the Python version three times. The C++ version is always behind.
Mix-mode execution
What if the Python code and the C++ code could coexist on the same computation tape?
Mix-mode execution records operations from both languages into a single computational graph. The graph is then JIT-compiled to native machine code, producing the same compiled kernel regardless of which language originated the computation.
This means:
- Python code runs at C++ speed. Not “close to C++ speed,” but identical, because both compile to the same machine code.
- C++ libraries callable from Python. A quant can call into an existing C++ pricing library from Python, and the entire computation (Python + C++) lands on one tape.
- NumPy ufuncs supported. Standard NumPy operations are captured on the tape and compiled.
- One kernel, full adjoint Greeks. The backward pass differentiates through both the Python and C++ portions seamlessly.
How it works
- Record: Execute the Python + C++ computation once. Operations from both languages are captured on the tape.
- Compile: The tape is JIT-compiled to a native AVX-vectorized kernel.
- Replay: The kernel executes millions of times with different inputs. No Python interpreter, no C++ framework. Just compiled machine code.
Use cases
- Gradual migration: Start with Python, move hot paths to C++ one function at a time. The kernel handles both.
- Quant-developer collaboration: Quants write model logic in Python. Developers write infrastructure in C++. Both contribute to the same kernel.
- Legacy integration: Wrap an existing C++ library, call it from Python, get adjoint Greeks through the entire stack.
Implemented using AADC, a commercial adjoint AD compiler (matlogica.com).
Frequently Asked Questions
What is Mix-Mode Execution?
Mix-Mode Execution is AADC’s unique capability to create unified optimized kernels from computational graphs that span both Python and C++ code. Functions can be recorded across both languages and compiled into a single high-performance kernel.
Can I call C++ libraries from Python with AADC?
Yes, AADC allows C++ libraries to be callable from Python with no performance penalty. The Python code is compiled to native machine code, bypassing the interpreter entirely, and unified optimization occurs across language boundaries.
Does Mix-Mode support NumPy?
Yes, NumPy ufuncs are supported for native Python integration. This allows existing Python/NumPy code to benefit from AADC acceleration without major rewrites.