Code Generation/Execution

Python

class dagrt.codegen.python.CodeGenerator(class_name, class_preamble=None, function_registry=None)
__init__(class_name, class_preamble=None, function_registry=None)
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)
Returns

a class adhering to StepperInterface.

class dagrt.codegen.python.StepperInterface

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)
abstract run(t_end=None, max_steps=None)

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()

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=None, exclude=None, **kwargs)

Base class for kinds encountered in the dagrt language.

class dagrt.data.Boolean(valuedict=None, exclude=None, **kwargs)

A boolean.

class dagrt.data.Integer(valuedict=None, exclude=None, **kwargs)

An integer.

class dagrt.data.Scalar(is_real_valued)

A (real or complex) floating-point value.

is_real_valued

Whether the value is definitely real-valued

class dagrt.data.Array(is_real_valued)

A variable-sized one-dimensional scalar array.

is_real_valued

Whether the value is definitely real-valued

class dagrt.data.UserType(identifier)

Represents user state belonging to a normed vector space.

identifier

A unique identifier for this type

Symbol kind inference

class dagrt.data.SymbolKindTable

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
class dagrt.data.SymbolKindFinder(function_registry)
__call__(names, phases, forced_kinds=None)

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)

Run kind inference on a dagrt.language.DAGCode.

Parameters
Returns

a SymbolKindTable

dagrt.data.collect_user_types(skt)

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)
dagrt.codegen.transform.isolate_function_arguments(phase_ast)
dagrt.codegen.transform.isolate_function_calls(phase_ast)
dagrt.codegen.transform.expand_IfThenElse(phase_ast)

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)

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)
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)

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
exception dagrt.utils.TODO
class dagrt.utils.TemporaryDirectory(suffix='', prefix='tmp', dirname=None)

Create and return a temporary directory. This has the same behavior as mkdtemp but can be used as a context manager. For example:

with TemporaryDirectory() as tmpdir:

Upon exiting the context, the directory and everything contained in it are removed.

dagrt.utils.get_unique_name(prefix, *name_sets)

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)

Returns the set of names of variables used in the expression.

dagrt.utils.is_state_variable(var)

Check if the given name corresponds to a state variable.

dagrt.utils.resolve_args(arg_names, default_dict, arg_dict)

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)
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)
dt

Size of next time step.

t

Approximate integrator time at end of step.

current_state
next_phase
class dagrt.exec_numpy.StepFailed(t)
t

Floating point number.

exception dagrt.exec_numpy.FailStepException
class dagrt.exec_numpy.TransitionEvent(next_phase)
class dagrt.exec_numpy.NumpyInterpreter(code, function_map)

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

Implements

next_phase
StateComputed
StepCompleted
StepFailed
set_up(t_start, dt_start, context)
Parameters

context – a dictionary mapping identifiers to their values

run(t_end=None, max_steps=None)

Generates events.

run_single_step()