Code Generation/Execution¶
Python¶
- class dagrt.codegen.python.CodeGenerator(class_name, class_preamble=None, function_registry=None)[source]¶
- __init__(class_name, class_preamble=None, function_registry=None)[source]¶
- Parameters:
class_name – The name of the class to generate
class_preamble – A string to include at the beginning of the the class (in class scope)
function_registry – An instance of
dagrt.function_registry.FunctionRegistry
- __call__(dag)[source]¶
- Returns:
a class adhering to
StepperInterface
.
- class dagrt.codegen.python.StepperInterface[source]¶
The interface adhered to by
dagrt
steppers expressed in Python.- next_phase¶
- StateComputed¶
An event yielded by
run_single_step
andrun
. Seedagrt.exec_numpy.StateComputed
.
- StepCompleted¶
An event yielded by
run_single_step
andrun
. Seedagrt.exec_numpy.StepCompleted
.
- StepFailed¶
An event yielded by
run_single_step
andrun
. Seedagrt.exec_numpy.StepFailed
.
Fortran¶
Types¶
Code Generator¶
Data¶
The module dagrt.data
provides symbol kind information and kind
inference.
Symbol kinds¶
- class dagrt.data.SymbolKind(valuedict: Mapping[str, Any] | None = None, exclude: Sequence[str] | None = None, **kwargs: Any)[source]¶
Base class for kinds encountered in the
dagrt
language.
- class dagrt.data.Boolean(valuedict: Mapping[str, Any] | None = None, exclude: Sequence[str] | None = None, **kwargs: Any)[source]¶
A boolean.
- class dagrt.data.Integer(valuedict: Mapping[str, Any] | None = None, exclude: Sequence[str] | None = None, **kwargs: Any)[source]¶
An integer.
- class dagrt.data.Scalar(is_real_valued)[source]¶
A (real or complex) floating-point value.
- is_real_valued¶
Whether the value is definitely real-valued
Symbol kind inference¶
- class dagrt.data.SymbolKindTable[source]¶
A mapping from symbol names to kinds for a program.
- global_table¶
a mapping from symbol names to
SymbolKind
instances, for global symbols
- per_phase_table¶
a nested mapping
[phase_name][symbol_name]
toSymbolKind
instances
- class dagrt.data.SymbolKindFinder(function_registry)[source]¶
- __call__(names, phases, forced_kinds=None)[source]¶
Infer the kinds of all the symbols in a program.
- Parameters:
names – a list of phase names
phases – a list of iterables, each yielding the statements in a phase
- Returns:
- Raises:
UnableToInferKind – kind inference could not complete sucessfully
Helper functions¶
- dagrt.data.infer_kinds(dag, function_registry=None)[source]¶
Run kind inference on a
dagrt.language.DAGCode
.- Parameters:
dag – a
dagrt.language.DAGCode
function_registry – if not None, the function registry to use
- Returns:
- dagrt.data.collect_user_types(skt)[source]¶
Collect all of the of
UserType
identifiers in a table.- Parameters:
skt – a
SymbolKindTable
- Returns:
a set of strings
Transformations¶
Utilities¶
Random usefulness
- class dagrt.codegen.utils.KeyToUniqueNameMap(start=None, forced_prefix='', key_translate_func=<function make_identifier_from_name>, name_generator=None)[source]¶
Maps keys to unique names that are created on-the-fly.
Before a unique name is created, a base name is first created. The base name consists of a forced prefix followed by a string that results from translating the key with a supplied function. The mapped value is then created from the base name.
- dagrt.codegen.utils.remove_common_indentation(text)[source]¶
- Parameters:
text – a multi-line string
- Returns:
a list of lines
- dagrt.codegen.utils.wrap_line_base(line, level=0, width=80, indentation=' ', pad_func=<function <lambda>>, lex_func=None)[source]¶
The input is a line of code at the given indentation level. Return the list of lines that results from wrapping the line to the given width. Lines subsequent to the first line in the returned list are padded with extra indentation. The initial indentation level is not included in the input or output lines.
The pad_func argument is a function that adds line continuations. The lex_func argument returns the list of tokens in the line.
Dumping ground of miscellaneous helpfulness.
- dagrt.utils.get_unique_name(prefix, *name_sets)[source]¶
Return a name that begins with prefix and is not found in any of the name sets.
- dagrt.utils.get_variables(expr, include_function_symbols=False)[source]¶
Returns the set of names of variables used in the expression.
- dagrt.utils.is_state_variable(var)[source]¶
Check if the given name corresponds to a state variable.
- dagrt.utils.resolve_args(arg_names, default_dict, arg_dict)[source]¶
Resolve positional and keyword arguments to a single argument list.
- Parameters:
arg_dict – a dictionary mapping numbers (for positional arguments) or identifiers (for keyword arguments) to values
default_dict – a dictionary mapping argument names to default values
arg_names – names of the positional arguments
numpy
-based interpretation¶
- class dagrt.exec_numpy.StateComputed(t, time_id, component_id, state_component)[source]¶
- t¶
- time_id¶
- component_id¶
Identifier of the state component being returned.
- state_component¶
- class dagrt.exec_numpy.StepCompleted(dt, t, current_state, next_phase)[source]¶
- dt¶
Size of next time step.
- t¶
Approximate integrator time at end of step.
- current_state¶
- next_phase¶
- class dagrt.exec_numpy.NumpyInterpreter(code, function_map)[source]¶
A
numpy
-targeting interpreter for the time integration language defined indagrt.language
.Implements
- next_phase¶