From 1c6368378497d41762e2417748d88d9c25adfe67 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 15 Apr 2019 17:15:35 -0500 Subject: [PATCH 1/2] Rename statement classes for paper I propose the following statement renamings for the paper: AssignExpression -> Assign AssignSolved -> AssignImplicit Reason: "AssignExpression" sounds like a type of expression, so I would avoid that. Also, I don't think the prior names capture the relationship between the two statements well. One option would be to call them AssignExplicit/AssignImplicit, but I think AssignExplicit is too complicated of a name, so I shortened it to Assign. ExitStep -> RestartStep Reason: "Exit" misleadingly implies termination PhaseTransition -> SwitchPhase Reason: Isn't a verb, like the other statements I've made the necessary changes and bumped the version to 2019.1 --- dagrt/codegen/analysis.py | 10 ++--- dagrt/codegen/data.py | 6 +-- dagrt/codegen/fortran.py | 8 ++-- dagrt/codegen/python.py | 12 +++--- dagrt/codegen/transform.py | 20 +++++----- dagrt/exec_numpy.py | 16 ++++---- dagrt/language.py | 77 +++++++++++++++++++------------------ dagrt/version.py | 2 +- examples/adaptive_rk.py | 4 +- test/test_builtins.py | 12 +++--- test/test_code_builder.py | 4 +- test/test_codegen.py | 14 +++---- test/test_codegen_python.py | 22 +++++------ 13 files changed, 104 insertions(+), 103 deletions(-) diff --git a/dagrt/codegen/analysis.py b/dagrt/codegen/analysis.py index 8d61bc1..70bf4c5 100644 --- a/dagrt/codegen/analysis.py +++ b/dagrt/codegen/analysis.py @@ -24,7 +24,7 @@ THE SOFTWARE. import six from pymbolic.mapper import Collector -from dagrt.language import YieldState, PhaseTransition, AssignFunctionCall +from dagrt.language import YieldState, SwitchPhase, AssignFunctionCall # {{{ verifier @@ -34,9 +34,9 @@ def _quote(string): return "\"{0}\"".format(string) -def verify_phase_transitions(phases, errors): +def verify_switch_phases(phases, errors): """ - Ensure that phases referenced by PhaseTransition exist. + Ensure that phases referenced by SwitchPhase exist. :arg statements: A set of statements to verify :arg phases: A map from phase names to phases @@ -45,7 +45,7 @@ def verify_phase_transitions(phases, errors): phase_names = [key for key in phases.keys()] for phase in six.itervalues(phases): for inst in phase.statements: - if not isinstance(inst, PhaseTransition): + if not isinstance(inst, SwitchPhase): continue if inst.next_phase not in phase_names: errors.append( @@ -157,7 +157,7 @@ def verify_code(code): for phase in six.itervalues(code.phases): verify_no_circular_dependencies(phase.statements, errors) - verify_phase_transitions(code.phases, errors) + verify_switch_phases(code.phases, errors) for phase in six.itervalues(code.phases): verify_single_definition_cond_rule(phase.statements, errors) diff --git a/dagrt/codegen/data.py b/dagrt/codegen/data.py index 11b6a9a..45fa46d 100644 --- a/dagrt/codegen/data.py +++ b/dagrt/codegen/data.py @@ -443,7 +443,7 @@ class SymbolKindFinder(object): kim = make_kim(func_name, check=False) try: - if isinstance(stmt, lang.AssignExpression): + if isinstance(stmt, lang.Assign): kim(stmt.expression) elif isinstance(stmt, lang.AssignFunctionCall): @@ -474,7 +474,7 @@ class SymbolKindFinder(object): func_name, stmt = stmt_queue.pop() - if isinstance(stmt, lang.AssignExpression): + if isinstance(stmt, lang.Assign): kim = make_kim(func_name, check=False) for ident, _, _ in stmt.loops: @@ -521,7 +521,7 @@ class SymbolKindFinder(object): kim = make_kim(func_name, check=True) for stmt in get_statements_in_ast(func): - if isinstance(stmt, lang.AssignExpression): + if isinstance(stmt, lang.Assign): kim(stmt.expression) elif isinstance(stmt, lang.AssignFunctionCall): diff --git a/dagrt/codegen/fortran.py b/dagrt/codegen/fortran.py index 535779c..329408a 100644 --- a/dagrt/codegen/fortran.py +++ b/dagrt/codegen/fortran.py @@ -2099,9 +2099,9 @@ class CodeGenerator(StructuredCodeGenerator): self.emit("! }}}") self.emit("") - # {{{ emit_inst_AssignExpression + # {{{ emit_inst_Assign - def emit_inst_AssignExpression(self, inst): + def emit_inst_Assign(self, inst): start_em = self.emitter for iloop, (ident, start, stop) in enumerate(inst.loops): @@ -2286,10 +2286,10 @@ class CodeGenerator(StructuredCodeGenerator): self.emit("goto 999") - def emit_inst_ExitStep(self, inst): + def emit_inst_RestartStep(self, inst): self.emit("goto 999") - def emit_inst_PhaseTransition(self, inst): + def emit_inst_SwitchPhase(self, inst): self.emit( 'dagrt_state%dagrt_next_phase = ' + self.phase_name_to_phase_sym(inst.next_phase)) diff --git a/dagrt/codegen/python.py b/dagrt/codegen/python.py index a749e0e..3f6ed3b 100644 --- a/dagrt/codegen/python.py +++ b/dagrt/codegen/python.py @@ -88,7 +88,7 @@ class FailStepException(RuntimeError): pass -class ExitStepException(RuntimeError): +class RestartStepException(RuntimeError): pass @@ -335,7 +335,7 @@ class CodeGenerator(StructuredCodeGenerator): yield self.StepFailed(t=self.t) continue - except self.ExitStepException: + except self.RestartStepException: continue except self.TransitionEvent as evt: @@ -406,7 +406,7 @@ class CodeGenerator(StructuredCodeGenerator): # {{{ statements - def emit_inst_AssignExpression(self, inst): + def emit_inst_Assign(self, inst): emitter = self._emitter for ident, start, stop in inst.loops: managed_ident = self._name_manager[ident] @@ -478,12 +478,12 @@ class CodeGenerator(StructuredCodeGenerator): if not self._has_yield_inst: self._emit('yield') - def emit_inst_ExitStep(self, inst): - self._emit('raise self.ExitStepException()') + def emit_inst_RestartStep(self, inst): + self._emit('raise self.RestartStepException()') if not self._has_yield_inst: self._emit('yield') - def emit_inst_PhaseTransition(self, inst): + def emit_inst_SwitchPhase(self, inst): assert '\'' not in inst.next_phase self._emit('raise self.TransitionEvent(\'' + inst.next_phase + '\')') if not self._has_yield_inst: diff --git a/dagrt/codegen/transform.py b/dagrt/codegen/transform.py index 026832f..ef8dcca 100644 --- a/dagrt/codegen/transform.py +++ b/dagrt/codegen/transform.py @@ -48,7 +48,7 @@ def eliminate_self_dependencies(dag): substs = [] tmp_stmt_ids = [] - from dagrt.language import AssignExpression + from dagrt.language import Assign from pymbolic import var for var_name in read_and_written: tmp_var_name = var_name_gen( @@ -59,7 +59,7 @@ def eliminate_self_dependencies(dag): tmp_stmt_id = stmt_id_gen("temp") tmp_stmt_ids.append(tmp_stmt_id) - new_tmp_stmt = AssignExpression( + new_tmp_stmt = Assign( tmp_var_name, (), var(var_name), condition=stmt.condition, id=tmp_stmt_id, @@ -109,8 +109,8 @@ class FunctionArgumentIsolator(IdentityMapper): rec_result = self.rec( expr, base_condition, base_deps, sub_extra_deps) - from dagrt.language import AssignExpression - new_stmt = AssignExpression( + from dagrt.language import Assign + new_stmt = Assign( tmp_var_name, (), rec_result, condition=base_condition, depends_on=base_deps | frozenset(sub_extra_deps), @@ -243,8 +243,8 @@ def isolate_function_calls_in_phase(phase, stmt_id_gen, var_name_gen): for stmt in sorted(phase.statements, key=lambda stmt: stmt.id): new_deps = [] - from dagrt.language import AssignExpression - if isinstance(stmt, AssignExpression): + from dagrt.language import Assign + if isinstance(stmt, Assign): new_statements.append( stmt .map_expressions( @@ -324,17 +324,17 @@ class IfThenElseExpander(IdentityMapper): rec_else = self.rec(expr.else_, else_condition, base_deps | frozenset([if_stmt_id]), sub_else_deps) - from dagrt.language import AssignExpression + from dagrt.language import Assign self.new_statements.extend([ - AssignExpression( + Assign( assignee=flag.name, assignee_subscript=(), expression=rec_condition, condition=base_condition, id=if_stmt_id, depends_on=base_deps | frozenset(sub_condition_deps)), - AssignExpression( + Assign( assignee=tmp_result, assignee_subscript=(), condition=then_condition, @@ -344,7 +344,7 @@ class IfThenElseExpander(IdentityMapper): base_deps | frozenset(sub_then_deps) | frozenset([if_stmt_id]))), - AssignExpression( + Assign( assignee=tmp_result, assignee_subscript=(), condition=else_condition, diff --git a/dagrt/exec_numpy.py b/dagrt/exec_numpy.py index 8c3a5d9..0e15304 100644 --- a/dagrt/exec_numpy.py +++ b/dagrt/exec_numpy.py @@ -31,7 +31,7 @@ class FailStepException(Exception): pass -class ExitStepException(Exception): +class RestartStepException(Exception): pass @@ -152,7 +152,7 @@ class NumpyInterpreter(object): yield StepFailed(t=self.context[""]) continue - except ExitStepException: + except RestartStepException: continue except TransitionEvent as evt: @@ -195,8 +195,8 @@ class NumpyInterpreter(object): # {{{ execution methods - def exec_AssignSolved(self, stmt): - raise NotImplementedError("Encountered AssignSolved.") + def exec_AssignImplicit(self, stmt): + raise NotImplementedError("Encountered AssignImplicit.") def exec_YieldState(self, stmt): return StateComputed( @@ -205,7 +205,7 @@ class NumpyInterpreter(object): component_id=stmt.component_id, state_component=self.eval_mapper(stmt.expression)), [] - def exec_AssignExpression(self, stmt): + def exec_Assign(self, stmt): if not stmt.loops: if stmt.assignee_subscript: self.context[stmt.assignee][ @@ -268,13 +268,13 @@ class NumpyInterpreter(object): def exec_FailStep(self, stmt): raise FailStepException() - def exec_ExitStep(self, stmt): - raise ExitStepException() + def exec_RestartStep(self, stmt): + raise RestartStepException() def exec_Nop(self, stmt): pass - def exec_PhaseTransition(self, stmt): + def exec_SwitchPhase(self, stmt): raise TransitionEvent(stmt.next_phase) # }}} diff --git a/dagrt/language.py b/dagrt/language.py index 71769ea..1167bf3 100644 --- a/dagrt/language.py +++ b/dagrt/language.py @@ -28,7 +28,7 @@ THE SOFTWARE. from pytools import RecordWithoutPickling, memoize_method from pymbolic.imperative.statement import ( ConditionalStatement as StatementBase, - ConditionalAssignment as AssignExpressionBase, + ConditionalAssignment as AssignBase, Nop as NopBase) from dagrt.utils import get_variables @@ -108,8 +108,8 @@ Assignment Statements These statements perform updates to the execution state, i.e. the variables. -.. autoclass:: AssignSolved -.. autoclass:: AssignExpression +.. autoclass:: AssignImplicit +.. autoclass:: Assign .. autoclass:: AssignFunctionCall Control Statements @@ -121,8 +121,8 @@ with user code. .. autoclass:: YieldState .. autoclass:: Raise .. autoclass:: FailStep -.. autoclass:: ExitStep -.. autoclass:: PhaseTransition +.. autoclass:: RestartStep +.. autoclass:: SwitchPhase Miscellaneous Statements ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +197,7 @@ class AssignmentBase(Statement): pass -class AssignExpression(Statement, AssignExpressionBase): +class Assign(Statement, AssignBase): """ .. attribute:: loops @@ -238,7 +238,7 @@ class AssignExpression(Statement, AssignExpressionBase): else: rhs = kwargs.pop("rhs") - super(AssignExpression, self).__init__( + super(Assign, self).__init__( lhs=lhs, rhs=rhs, loops=loops, @@ -270,7 +270,7 @@ class AssignExpression(Statement, AssignExpressionBase): return self.rhs def map_expressions(self, mapper, include_lhs=True): - return (super(AssignExpression, self) + return (super(Assign, self) .map_expressions(mapper, include_lhs=include_lhs) .copy( loops=[ @@ -278,7 +278,7 @@ class AssignExpression(Statement, AssignExpressionBase): for ident, start, end in self.loops])) def __str__(self): - result = super(AssignExpression, self).__str__() + result = super(Assign, self).__str__() for ident, start, end in self.loops: result += " [{ident}={start}..{end}]".format( @@ -288,10 +288,10 @@ class AssignExpression(Statement, AssignExpressionBase): return result - exec_method = "exec_AssignExpression" + exec_method = "exec_Assign" -class AssignSolved(AssignmentBase): +class AssignImplicit(AssignmentBase): """ .. attribute:: assignees @@ -330,7 +330,7 @@ class AssignSolved(AssignmentBase): solver_id=solver_id, **kwargs) - exec_method = six.moves.intern("exec_AssignSolved") + exec_method = six.moves.intern("exec_AssignImplicit") def get_written_variables(self): return frozenset(self.assignees) @@ -345,7 +345,7 @@ class AssignSolved(AssignmentBase): def flatten(iter_arg): return chain(*list(iter_arg)) - variables = super(AssignSolved, self).get_read_variables() + variables = super(AssignImplicit, self).get_read_variables() variables |= set(flatten(get_variables(expr) for expr in self.expressions)) variables -= set(self.solve_variables) variables |= set(flatten(get_variables(expr) for expr @@ -362,7 +362,7 @@ class AssignSolved(AssignmentBase): else: assignees = self.assignees - return (super(AssignSolved, self) + return (super(AssignImplicit, self) .map_expressions(mapper, include_lhs=include_lhs) .copy( assignees=assignees, @@ -370,7 +370,7 @@ class AssignSolved(AssignmentBase): def __str__(self): lines = [] - lines.append("AssignSolved") + lines.append("AssignImplicit") lines.append("solver_id = " + str(self.solver_id)) for assignee_index, assignee in enumerate(self.assignees): lines.append(assignee + " <- " + self.solve_variables[assignee_index]) @@ -556,7 +556,7 @@ class Raise(Statement): exec_method = six.moves.intern("exec_Raise") -class PhaseTransition(Statement): +class SwitchPhase(Statement): """ .. attribute:: next_phase @@ -573,7 +573,7 @@ class PhaseTransition(Statement): return "Transition to {state}{cond}".format(state=self.next_phase, cond=self._condition_printing_suffix()) - exec_method = six.moves.intern("exec_PhaseTransition") + exec_method = six.moves.intern("exec_SwitchPhase") class FailStep(Statement): @@ -590,7 +590,7 @@ class FailStep(Statement): exec_method = six.moves.intern("exec_FailStep") -class ExitStep(Statement): +class RestartStep(Statement): """Exits the current step. Execution resumes with the next step as normal. """ @@ -598,9 +598,9 @@ class ExitStep(Statement): return frozenset() def __str__(self): - return "ExitStep{cond}".format(cond=self._condition_printing_suffix()) + return "RestartStep{cond}".format(cond=self._condition_printing_suffix()) - exec_method = six.moves.intern("exec_ExitStep") + exec_method = six.moves.intern("exec_RestartStep") # }}} @@ -825,13 +825,13 @@ class CodeBuilder(object): .. automethod:: __call__ .. automethod:: fresh_var_name .. automethod:: fresh_var - .. automethod:: assign_solved - .. automethod:: assign_solved_1 + .. automethod:: assign_implicit + .. automethod:: assign_implicit_1 .. automethod:: yield_state .. automethod:: fail_step - .. automethod:: exit_step + .. automethod:: restart_step .. automethod:: raise_ - .. automethod:: phase_transition + .. automethod:: switch_phase .. automethod:: __enter__ """ @@ -925,7 +925,7 @@ class CodeBuilder(object): # Create an statement as a lead statement to assign a logical flag. cond_var = self.fresh_var("") - cond_assignment = AssignExpression( + cond_assignment = Assign( assignee=cond_var.name, assignee_subscript=(), expression=condition) @@ -1048,7 +1048,7 @@ class CodeBuilder(object): "variable or a subscribted variable, not '%s'" % type(assignee)) - self._add_inst_to_context(AssignExpression( + self._add_inst_to_context(Assign( assignee=aname, assignee_subscript=asub, expression=expression, @@ -1076,7 +1076,7 @@ class CodeBuilder(object): # multiple assignments with subscript are OK and not ( - isinstance(inst, AssignExpression) + isinstance(inst, Assign) and inst.assignee_subscript is not None)): raise ValueError("multiple assignments to " + assignee) @@ -1091,7 +1091,7 @@ class CodeBuilder(object): for def_inst_id in context.definition_map.get(used_variable, []): def_inst = self._statement_map[def_inst_id] if ( - not isinstance(def_inst, AssignExpression) + not isinstance(def_inst, Assign) or def_inst.assignee_subscript is None): dependencies.add(def_inst_id) @@ -1139,15 +1139,16 @@ class CodeBuilder(object): from pymbolic import var return var(self.fresh_var_name(prefix)) - def assign_solved_1(self, assignee, solve_component, expression, guess, + def assign_implicit_1(self, assignee, solve_component, expression, guess, solver_id=None): - """Special case of AssignSolved when there is 1 component to solve for.""" - self.assign_solved((assignee.name,), (solve_component.name,), (expression,), - {"guess": guess}, solver_id) + """Special case of AssignImplicit when there is 1 component to solve for.""" + self.assign_implicit( + (assignee.name,), (solve_component.name,), (expression,), + {"guess": guess}, solver_id) - def assign_solved(self, assignees, solve_components, expressions, + def assign_implicit(self, assignees, solve_components, expressions, other_params, solver_id): - self._add_inst_to_context(AssignSolved(assignees, solve_components, + self._add_inst_to_context(AssignImplicit(assignees, solve_components, expressions, other_params, solver_id)) def yield_state(self, expression, component_id, time, time_id): @@ -1168,17 +1169,17 @@ class CodeBuilder(object): self.fence() self._add_inst_to_context(FailStep()) - def exit_step(self): + def restart_step(self): self.fence() - self._add_inst_to_context(ExitStep()) + self._add_inst_to_context(RestartStep()) def raise_(self, error_condition, error_message=None): self.fence() self._add_inst_to_context(Raise(error_condition, error_message)) - def phase_transition(self, next_phase): + def switch_phase(self, next_phase): self.fence() - self._add_inst_to_context(PhaseTransition(next_phase)) + self._add_inst_to_context(SwitchPhase(next_phase)) def __enter__(self): self._contexts.append(CodeBuilder.Context()) diff --git a/dagrt/version.py b/dagrt/version.py index aac0098..78a7f0b 100644 --- a/dagrt/version.py +++ b/dagrt/version.py @@ -1,2 +1,2 @@ -VERSION = (2018, 1) +VERSION = (2019, 1) VERSION_TEXT = ".".join(str(i) for i in VERSION) diff --git a/examples/adaptive_rk.py b/examples/adaptive_rk.py index 0daf2ee..18f8a4c 100644 --- a/examples/adaptive_rk.py +++ b/examples/adaptive_rk.py @@ -78,8 +78,8 @@ def adaptive_rk_method(tol): cb(y, y_h) cb(t, t + dt_old) - return DAGCode.create_with_steady_phase(cb.phase_dependencies, - cb.statements) + return DAGCode.create_with_steady_phase(cb.phase_dependencies, cb.statements) + if __name__ == "__main__": from dagrt.codegen import PythonCodeGenerator diff --git a/test/test_builtins.py b/test/test_builtins.py index 5a90b40..c0ccf03 100755 --- a/test/test_builtins.py +++ b/test/test_builtins.py @@ -27,7 +27,7 @@ import numpy as np import pytest import sys -from dagrt.language import AssignExpression, YieldState +from dagrt.language import Assign, YieldState from dagrt.language import DAGCode from pymbolic import var @@ -45,7 +45,7 @@ from utils import ( # noqa def test_len(python_method_impl, obj, len_): cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression(id='assign_1', assignee='x', assignee_subscript=(), + Assign(id='assign_1', assignee='x', assignee_subscript=(), expression=var('len')(obj)), YieldState(id='return', time=0, time_id='final', expression=var('x'), component_id='', @@ -63,7 +63,7 @@ def test_len(python_method_impl, obj, len_): def test_isnan(python_method_impl, value): cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression(id='assign_1', assignee='x', assignee_subscript=(), + Assign(id='assign_1', assignee='x', assignee_subscript=(), expression=var('isnan')(value)), YieldState(id='return', time=0, time_id='final', expression=var('x'), component_id='', @@ -92,9 +92,9 @@ def test_norm(python_method_impl, order, norm_suffix, test_vector): cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression(id='assign_1', assignee='x', assignee_subscript=(), + Assign(id='assign_1', assignee='x', assignee_subscript=(), expression=test_vector), - AssignExpression(id='assign_2', assignee='n', assignee_subscript=(), + Assign(id='assign_2', assignee='n', assignee_subscript=(), expression=( var('norm_%s' % norm_suffix)(var('x'))), depends_on=['assign_1']), @@ -115,7 +115,7 @@ def test_norm(python_method_impl, order, norm_suffix, test_vector): def test_dot_product(python_method_impl, x, y): cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression(id='assign_1', assignee='x', assignee_subscript=(), + Assign(id='assign_1', assignee='x', assignee_subscript=(), expression=var('dot_product')(x, y)), YieldState(id='return', time=0, time_id='final', expression=var('x'), component_id='', diff --git a/test/test_code_builder.py b/test/test_code_builder.py index aa23faa..1ef7a66 100755 --- a/test/test_code_builder.py +++ b/test/test_code_builder.py @@ -143,10 +143,10 @@ def test_CodeBuilder_nested_condition_with_else_not_taken(python_method_impl): assert result == 3 -def test_CodeBuilder_exit_step(python_method_impl): +def test_CodeBuilder_restart_step(python_method_impl): with CodeBuilder() as builder1: builder1("

x", 1) - builder1.exit_step() + builder1.restart_step() builder1.fence() builder1("

x", 2) diff --git a/test/test_codegen.py b/test/test_codegen.py index 0835337..684f1bd 100755 --- a/test/test_codegen.py +++ b/test/test_codegen.py @@ -4,7 +4,7 @@ from __future__ import division, with_statement import pytest import sys -from dagrt.language import AssignExpression, YieldState +from dagrt.language import Assign, YieldState from dagrt.language import DAGCode from dagrt.codegen import CodeGenerationError from dagrt.codegen.analysis import verify_code @@ -42,13 +42,13 @@ def test_circular_dependency_detection(): dependency.""" cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression( + Assign( id='assign', assignee='y', assignee_subscript=(), expression=1, depends_on=['assign2']), - AssignExpression(id='assign2', + Assign(id='assign2', assignee='y', assignee_subscript=(), expression=1, @@ -68,7 +68,7 @@ def test_missing_dependency_detection(): """Check that the code generator detects that there is a missing dependency.""" statements = set([ - AssignExpression(id='assign', assignee='y', assignee_subscript=(), + Assign(id='assign', assignee='y', assignee_subscript=(), expression=1, depends_on=['assign2']), YieldState(id='return', time=0, time_id='final', expression=var('y'), component_id='', @@ -86,7 +86,7 @@ def test_missing_state_detection(): from dagrt.language import CodeBuilder with CodeBuilder(label="state_1") as cb: - cb.phase_transition("state_2") + cb.switch_phase("state_2") code = DAGCode.create_with_steady_phase( dep_on=cb.phase_dependencies, statements=cb.statements) @@ -98,13 +98,13 @@ def test_cond_detection(): """Check that the code generator detects a redefinition of a variable.""" cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression( + Assign( id='assign1', assignee='c', assignee_subscript=(), expression=1, depends_on=[]), - AssignExpression( + Assign( id='assign2', assignee='c', assignee_subscript=(), diff --git a/test/test_codegen_python.py b/test/test_codegen_python.py index 69c1e86..5df414f 100755 --- a/test/test_codegen_python.py +++ b/test/test_codegen_python.py @@ -29,7 +29,7 @@ import pytest import numpy.linalg as la import numpy as np -from dagrt.language import AssignExpression, YieldState, FailStep, Raise, Nop +from dagrt.language import Assign, YieldState, FailStep, Raise, Nop from dagrt.language import CodeBuilder, DAGCode from dagrt.codegen import PythonCodeGenerator from pymbolic import var @@ -70,11 +70,11 @@ def test_basic_conditional_codegen(): """Test whether the code generator generates branches properly.""" cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression( + Assign( id='then_branch', assignee='y', assignee_subscript=(), expression=1, condition=True), - AssignExpression(id='else_branch', + Assign(id='else_branch', assignee='y', assignee_subscript=(), expression=0, condition=False), Nop(id='branch', depends_on=['then_branch', 'else_branch']), @@ -101,12 +101,12 @@ def test_basic_assign_rhs_codegen(): properly.""" cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression(id='assign_rhs1', + Assign(id='assign_rhs1', assignee='y', assignee_subscript=(), expression=var('y')(t=var('')), depends_on=[]), - AssignExpression(id='assign_rhs2', + Assign(id='assign_rhs2', assignee='y', assignee_subscript=(), expression=var('yy')(t=var(''), y=var('y')), @@ -192,10 +192,10 @@ def test_local_name_distinctness(): """Test whether the code generator gives locals distinct names.""" cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression( + Assign( id='assign_y^', assignee='y^', assignee_subscript=(), expression=1), - AssignExpression( + Assign( id='assign_y*', assignee='y*', assignee_subscript=(), expression=0), YieldState(id='return', time=0, time_id='final', @@ -219,10 +219,10 @@ def test_global_name_distinctness(): """Test whether the code generator gives globals distinct names.""" cbuild = RawCodeBuilder() cbuild.add_and_get_ids( - AssignExpression( + Assign( id='assign_y^', assignee='

y^', assignee_subscript=(), expression=1), - AssignExpression( + Assign( id='assign_y*', assignee='

y*', assignee_subscript=(), expression=0), YieldState(id='return', time=0, time_id='final', @@ -264,12 +264,12 @@ def test_function_name_distinctness(): assert hist[1].state_component == 1 -def test_phase_transitions(python_method_impl): +def test_switch_phases(python_method_impl): from dagrt.language import CodeBuilder, ExecutionPhase with CodeBuilder(label="state_1") as builder_1: builder_1(var("x"), 1) - builder_1.phase_transition("state_2") + builder_1.switch_phase("state_2") with CodeBuilder(label="state_2") as builder_2: builder_2.yield_state(var("x"), 'x', 0, 'final') -- GitLab From 2cc0aaf0ff7f2e5dbfdfd5c79d9513928ec06478 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Tue, 16 Apr 2019 00:52:34 +0200 Subject: [PATCH 2/2] Apply suggestion to dagrt/codegen/analysis.py --- dagrt/codegen/analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dagrt/codegen/analysis.py b/dagrt/codegen/analysis.py index 70bf4c5..681b01c 100644 --- a/dagrt/codegen/analysis.py +++ b/dagrt/codegen/analysis.py @@ -36,7 +36,7 @@ def _quote(string): def verify_switch_phases(phases, errors): """ - Ensure that phases referenced by SwitchPhase exist. + Ensure that phases referenced by :class:`SwitchPhase` exist. :arg statements: A set of statements to verify :arg phases: A map from phase names to phases -- GitLab