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 and run. See dagrt.exec_numpy.StateComputed.

StepCompleted¶

An event yielded by run_single_step and run. See dagrt.exec_numpy.StepCompleted.

StepFailed¶

An event yielded by run_single_step and run. See dagrt.exec_numpy.StepFailed.

abstract set_up(t_start, dt_start, context)[source]¶
abstract run(t_end=None, max_steps=None)[source]¶

Execute the stepper until either time reaches t_end or max_steps have been taken. Generates (in the Python yield sense) events that occurred during execution along the way.

abstract run_single_step()[source]¶

Execute a single phase of the stepper. Generates (in the Python yield sense) events that occurred during execution along the way.

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

class dagrt.data.Array(is_real_valued)[source]¶

A variable-sized one-dimensional scalar array.

is_real_valued¶

Whether the value is definitely real-valued

class dagrt.data.UserType(identifier)[source]¶

Represents user state belonging to a normed vector space.

identifier¶

A unique identifier for this type

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] to SymbolKind instances

class dagrt.data.UnableToInferKind[source]¶
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:

a SymbolKindTable

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:
Returns:

a SymbolKindTable

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¶

dagrt.codegen.transform.eliminate_self_dependencies(phase_ast)[source]¶
dagrt.codegen.transform.isolate_function_arguments(phase_ast)[source]¶
dagrt.codegen.transform.isolate_function_calls(phase_ast)[source]¶
dagrt.codegen.transform.expand_IfThenElse(phase_ast)[source]¶

Turn IfThenElse expressions into values that are computed as a result of an If statement. This is useful for targets that do not support ternary operators.

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.

exception dagrt.utils.DebuggerExit[source]¶
exception dagrt.utils.TODO[source]¶
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.StepFailed(t)[source]¶
t¶

Floating point number.

exception dagrt.exec_numpy.FailStepException[source]¶
class dagrt.exec_numpy.TransitionEvent(next_phase)[source]¶
class dagrt.exec_numpy.NumpyInterpreter(code, function_map)[source]¶

A numpy-targeting interpreter for the time integration language defined in dagrt.language.

Implements

next_phase¶
StateComputed[source]¶
StepCompleted[source]¶
StepFailed[source]¶
set_up(t_start, dt_start, context)[source]¶
Parameters:

context – a dictionary mapping identifiers to their values

run(t_end=None, max_steps=None)[source]¶

Generates events.

run_single_step()[source]¶