diff --git a/README.rst b/README.rst index 85a8d0ada1cdf11053b71381f07907454b205b88..3698aba8569bed28d04998d727d8c3613f2b399e 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ leap leap describes both implicit and explicit `time stepping methods `_. Methods are -described using a small virtual machine whose instructions can +described using a small virtual machine whose statements can then be used to either generate code or simply execute the time integrator. diff --git a/examples/implicit_euler/implicit_euler.py b/examples/implicit_euler/implicit_euler.py index f52e9190a8a7133115b1a6f265f18d52a5335bdb..405b38229f8678eb4d13a0dce64a66e42bc1ba9d 100644 --- a/examples/implicit_euler/implicit_euler.py +++ b/examples/implicit_euler/implicit_euler.py @@ -55,7 +55,7 @@ class ImplicitEulerMethod(Method): code = DAGCode.create_with_steady_phase( dep_on=cb.phase_dependencies, - instructions=cb.instructions) + statements=cb.statements) from leap.implicit import replace_AssignSolved diff --git a/insn-to-statement.sh b/insn-to-statement.sh new file mode 100644 index 0000000000000000000000000000000000000000..320bc6b7bf3d2ad92bee7000c5a40d8617861a89 --- /dev/null +++ b/insn-to-statement.sh @@ -0,0 +1,7 @@ +set -x +set -e +sed -i s/Instruction/Statement/g $(git ls-files | grep -v insn-to-statement.sh | grep -v .txt ) +sed -i s/instruction/statement/g $(git ls-files | grep -v insn-to-statement.sh | grep -v .txt ) +sed -i s/INSTRUCTION/STATEMENT/g $(git ls-files | grep -v insn-to-statement.sh | grep -v .txt ) +sed -i s/insn/stmt/g $(git ls-files | grep -v insn-to-statement.sh | grep -v .txt ) +#patch -p1 < ./stmt-compat-fixes.patch diff --git a/leap/implicit.py b/leap/implicit.py index f7d891e6e50f2d2d96ef93ea2fef958a80b3f5b0..0527066f936d9b491e7dc7e89b1e024fac11fa53 100644 --- a/leap/implicit.py +++ b/leap/implicit.py @@ -49,38 +49,38 @@ def replace_AssignSolved(dag, solver_hooks): :arg solver_hooks: A map from solver names to expression generators """ - new_instructions = [] + new_statements = [] from dagrt.language import AssignExpression, AssignSolved new_phases = {} for phase_name, phase in dag.phases.items(): - for insn in phase.instructions: + for stmt in phase.statements: - if not isinstance(insn, AssignSolved): - new_instructions.append(insn) + if not isinstance(stmt, AssignSolved): + new_statements.append(stmt) continue - if len(insn.assignees) != 1: + if len(stmt.assignees) != 1: from dagrt.utils import TODO - raise TODO("Implement lowering for AssignSolved instructions " + raise TODO("Implement lowering for AssignSolved statements " "returning multiple values.") - expression = insn.expressions[0] - other_params = insn.other_params + expression = stmt.expressions[0] + other_params = stmt.other_params - solver = solver_hooks[insn.solver_id] + solver = solver_hooks[stmt.solver_id] - new_instructions.append( + new_statements.append( AssignExpression( - assignee=insn.assignees[0], + assignee=stmt.assignees[0], assignee_subscript=(), expression=solver(expression, **other_params), - id=insn.id, - condition=insn.condition, - depends_on=insn.depends_on)) + id=stmt.id, + condition=stmt.condition, + depends_on=stmt.depends_on)) - new_phases[phase_name] = phase.copy(instructions=new_instructions) + new_phases[phase_name] = phase.copy(statements=new_statements) return dag.copy(phases=new_phases) diff --git a/leap/step_matrix.py b/leap/step_matrix.py index 693666ccdd41c27129389323f6ce86767188fb6d..9088beaa1be020fcd0fd6a6c1d64362cfd115db1 100644 --- a/leap/step_matrix.py +++ b/leap/step_matrix.py @@ -60,7 +60,7 @@ class StepMatrixFinder(object): """Constructs a step matrix on-the-fly while interpreting code. Assumes that all function evaluations occur as the root node of - a separate assignment instruction. + a separate assignment statement. """ def __init__(self, code, function_map, variables=None, @@ -95,7 +95,7 @@ class StepMatrixFinder(object): """Extract all state-related variables from the code.""" all_var_ids = set() for phase in six.itervalues(self.code.phases): - for inst in phase.instructions: + for inst in phase.statements: all_var_ids |= inst.get_written_variables() all_var_ids |= inst.get_read_variables() @@ -236,41 +236,41 @@ class StepMatrixFinder(object): else: return SparseStepMatrix(shape, indices, data) - def evaluate_condition(self, insn): - if insn.condition is not True: + def evaluate_condition(self, stmt): + if stmt.condition is not True: raise RuntimeError("matrices don't represent conditionals well, " "so StepMatrixFinder cannot support them") return True # {{{ exec methods - def exec_AssignExpression(self, insn): - self.context[insn.assignee] = self.eval_mapper(insn.expression) + def exec_AssignExpression(self, stmt): + self.context[stmt.assignee] = self.eval_mapper(stmt.expression) - def exec_AssignFunctionCall(self, insn): - results = self.eval_mapper(insn.as_expression()) + def exec_AssignFunctionCall(self, stmt): + results = self.eval_mapper(stmt.as_expression()) - if len(insn.assignees) == 1: + if len(stmt.assignees) == 1: results = (results,) - assert len(results) == len(insn.assignees) + assert len(results) == len(stmt.assignees) - for assignee, res in zip(insn.assignees, results): + for assignee, res in zip(stmt.assignees, results): self.context[assignee] = res - def exec_Nop(self, insn): + def exec_Nop(self, stmt): pass - def exec_YieldState(self, insn): + def exec_YieldState(self, stmt): pass - def exec_Raise(self, insn): - raise insn.error_condition(insn.error_message) + def exec_Raise(self, stmt): + raise stmt.error_condition(stmt.error_message) - def exec_FailStep(self, insn): + def exec_FailStep(self, stmt): raise FailStepException() - def exec_PhaseTransition(self, insn): + def exec_PhaseTransition(self, stmt): pass # }}} diff --git a/leap/transform.py b/leap/transform.py index 9e21ffd8a9ddd13dc71c1c4cdeefd832bcb88334..fdc2ad9eedeb1aa29c174a6ba21e083e95506eb6 100644 --- a/leap/transform.py +++ b/leap/transform.py @@ -30,15 +30,15 @@ __doc__ = """ """ -def _elide_yield_state(instructions): +def _elide_yield_state(statements): from dagrt.language import YieldState, Nop - return [insn - if not isinstance(insn, YieldState) - else Nop(id=insn.id, depends_on=insn.depends_on) - for insn in instructions] + return [stmt + if not isinstance(stmt, YieldState) + else Nop(id=stmt.id, depends_on=stmt.depends_on) + for stmt in statements] -def _update_t_by_dt_factor(factor, instructions): +def _update_t_by_dt_factor(factor, statements): from dagrt.language import AssignExpression, Nop from pymbolic import var from pymbolic.mapper.substitutor import make_subst_func, SubstitutionMapper @@ -46,16 +46,16 @@ def _update_t_by_dt_factor(factor, instructions): mapper = SubstitutionMapper( make_subst_func({"
": factor * var("
")})) - def updater(insn): + def updater(stmt): if factor == 0: - return Nop(id=insn.id, depends_on=insn.depends_on) - return insn.map_expressions(mapper) + return Nop(id=stmt.id, depends_on=stmt.depends_on) + return stmt.map_expressions(mapper) - return [insn - if (not isinstance(insn, AssignExpression) - or insn.lhs != var("")) - else updater(insn) - for insn in instructions] + return [stmt + if (not isinstance(stmt, AssignExpression) + or stmt.lhs != var("")) + else updater(stmt) + for stmt in statements] def strang_splitting(dag1, dag2, stepping_phase): @@ -98,9 +98,9 @@ def strang_splitting(dag1, dag2, stepping_phase): phase1 = dag1.phases.get(phase_name) phase2 = dag2.phases.get(phase_name) - substed_s2_insns = [ - insn.map_expressions(subst2_mapper) - for insn in phase2.instructions] + substed_s2_stmts = [ + stmt.map_expressions(subst2_mapper) + for stmt in phase2.statements] if phase_name == stepping_phase: assert phase1 is not None @@ -111,8 +111,8 @@ def strang_splitting(dag1, dag2, stepping_phase): make_subst_func({"
": var("
") / 2})) phase1_half_dt = [ - insn.map_expressions(dt_half) - for insn in phase1.instructions] + stmt.map_expressions(dt_half) + for stmt in phase1.statements] if phase1.next_phase != phase2.next_phase: raise ValueError("DAGs don't agree on default " @@ -136,26 +136,26 @@ def strang_splitting(dag1, dag2, stepping_phase): new_phases[phase_name] = ExecutionPhase( next_phase=s2_name, depends_on=phase1.depends_on, - instructions=( + statements=( _update_t_by_dt_factor(0, _elide_yield_state( phase1_half_dt)))) new_phases[s2_name] = ExecutionPhase( next_phase=s3_name, depends_on=phase2.depends_on, - instructions=( + statements=( _update_t_by_dt_factor(1/2, _elide_yield_state( - substed_s2_insns)))) + substed_s2_stmts)))) new_phases[s3_name] = ExecutionPhase( next_phase=phase1.next_phase, depends_on=phase1.depends_on, - instructions=phase1_half_dt) + statements=phase1_half_dt) else: from dagrt.transform import fuse_two_phases new_phases[phase_name] = fuse_two_phases(phase_name, phase1, - phase2.copy(instructions=substed_s2_insns)) + phase2.copy(statements=substed_s2_stmts)) if dag1.initial_phase != dag2.initial_phase: raise ValueError("DAGs don't agree on initial phase")