AOT compilation#
- pybamm.codegen.compilation.aot_compile(fn_or_fns, **kwargs)[source]#
Ahead-of-time compile one or more casadi
Functionobjects to a single shared library and returncasadi.externalwrappers.Accepts either a single
casadi.Function(returns a Function) or a list/tuple of Functions (returns a list, one per input, in order). In either case everything is lowered in oneCodeGenerator/gccinvocation – a single fn is a bundle of size one.Intended for the outermost Functions a solver hands off (e.g.
rhs_algebraic,jac_times_cjmass,rootfn, output-variable evaluators). Intermediate Functions should stay as MX/SX socasadi.CodeGeneratorcan inline them into one translation unit. Wrapping inner Functions as Externals forces cross-dylib dispatch and produces unresolvableexterndeclarations.Results are cached in-process (by a hash of the serialised forms) and on disk under
$PYBAMM_CASADI_AOT_CACHE(default$TMPDIR/pybamm_casadi_aot). Inputs already of classExternalare returned unchanged. On any failure, the original Function(s) are returned and a warning is logged.- Parameters:
fn_or_fns (casadi.Function or list of casadi.Function)
**kwargs –
cache_dir,compilerandflagsoverrides.
Environment variables#
PYBAMM_CASADI_AOT_CACHEOn-disk cache directory. Defaults to
$TMPDIR/pybamm_casadi_aot.PYBAMM_CASADI_AOT_KEEP_CIf set, retain the generated
.csource next to each compiled library. Useful for debugging codegen output.