templater

codegen.templater

Attributes

Name Description
TEMPLATES
exec_globals

Functions

Name Description
boolean2bitwise
coupling2class
equation2class
format_code Format code using black for Python variants.
formulate_dependency_imports
get_integrator_info
get_model_info
get_param_info
get_statevariable_equations
get_sv_info
integrator2class
is_derived Return True if obs derives from other observations in experiment.
model2class
source_observations Return the source names of obs that resolve to other observations.

boolean2bitwise

codegen.templater.boolean2bitwise(code_str)

coupling2class

codegen.templater.coupling2class(CF, fout=None, print_source=False, **kwargs)

equation2class

codegen.templater.equation2class(EQ, fout=None, print_source=False, **kwargs)

format_code

codegen.templater.format_code(code, format='python', use_black=True, **kwargs)

Format code using black for Python variants.

Parameters

Name Type Description Default
code str Source code string to format required
format str Language/variant (python, jax, numpy, scipy, tvboptim) 'python'
use_black bool Whether to apply black formatting (default True) True
**kwargs Any Additional black.FileMode options (line_length, etc.) {}

formulate_dependency_imports

codegen.templater.formulate_dependency_imports(dependencies)

get_integrator_info

codegen.templater.get_integrator_info(integrator)

get_model_info

codegen.templater.get_model_info(model)

get_param_info

codegen.templater.get_param_info(param_class)

get_statevariable_equations

codegen.templater.get_statevariable_equations(model)

get_sv_info

codegen.templater.get_sv_info(sv_class)

integrator2class

codegen.templater.integrator2class(integrator, return_instance=True, **kwargs)

is_derived

codegen.templater.is_derived(obs, experiment)

Return True if obs derives from other observations in experiment.

An Observation is derived when any item in its multivalued source slot names ANOTHER observation in the same experiment. Source entries may be bare strings, objects with a name attribute, or inlined Observation/StateVariable instances.

A SELF-reference (an observation whose source names itself — e.g. an observation r_A with source: [r_A] that simply observes the model variable r_A) is NOT derived: an observation cannot derive from itself. Without this exclusion such observations are mis-routed to the derived path, where they have no pipeline and are never computed, so the generated observations.r_A = _all_obs.r_A extraction raises AttributeError.

model2class

codegen.templater.model2class(
    model,
    fout=None,
    print_source=False,
    split_nonintegrated_variables=False,
    return_instance=True,
    sub_ninvars=False,
    bifmodel=False,
    **kwargs,
)

source_observations

codegen.templater.source_observations(obs, experiment)

Return the source names of obs that resolve to other observations.

A filtered view of obs.source keeping only entries whose name matches a key in experiment.observations.