From 49a331ad7eed67b6483a3c7491203395fc0c4f35 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 11 Mar 2018 17:19:35 -0500 Subject: [PATCH 1/4] Point dagrt ref at insn-to-statement branch --- insn-to-statement.sh | 7 +++++++ requirements.txt | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 insn-to-statement.sh diff --git a/insn-to-statement.sh b/insn-to-statement.sh new file mode 100644 index 0000000..84e67ee --- /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) +sed -i s/instruction/statement/g $(git ls-files | grep -v insn-to-statement.sh) +sed -i s/INSTRUCTION/STATEMENT/g $(git ls-files | grep -v insn-to-statement.sh) +sed -i s/insn/stmt/g $(git ls-files | grep -v insn-to-statement.sh) +#patch -p1 < ./stmt-compat-fixes.patch diff --git a/requirements.txt b/requirements.txt index e22f333..ea3efa8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ git+git://github.com/inducer/pytools git+git://github.com/inducer/pymbolic -git+https://gitlab.tiker.net/inducer/dagrt.git \ No newline at end of file +git+https://gitlab.tiker.net/inducer/dagrt.git@insn-to-statement -- GitLab From 7b160080e88f760961b8885198885ceeb8e77e2f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 11 Mar 2018 17:29:51 -0500 Subject: [PATCH 2/4] Prevent i2s script from breaking requirements.txt --- insn-to-statement.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/insn-to-statement.sh b/insn-to-statement.sh index 84e67ee..320bc6b 100644 --- a/insn-to-statement.sh +++ b/insn-to-statement.sh @@ -1,7 +1,7 @@ set -x set -e -sed -i s/Instruction/Statement/g $(git ls-files | grep -v insn-to-statement.sh) -sed -i s/instruction/statement/g $(git ls-files | grep -v insn-to-statement.sh) -sed -i s/INSTRUCTION/STATEMENT/g $(git ls-files | grep -v insn-to-statement.sh) -sed -i s/insn/stmt/g $(git ls-files | grep -v insn-to-statement.sh) +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 -- GitLab From 0f6154951cd5f1db13da6b03e37db0beb1439813 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 11 Mar 2018 17:30:03 -0500 Subject: [PATCH 3/4] Apply insn-to-statement rename --- README.rst | 2 +- examples/implicit_euler/implicit_euler.py | 2 +- leap/implicit.py | 30 +++++++------- leap/step_matrix.py | 34 ++++++++-------- leap/transform.py | 48 +++++++++++------------ 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/README.rst b/README.rst index 85a8d0a..3698aba 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 f52e919..405b382 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/leap/implicit.py b/leap/implicit.py index f7d891e..0527066 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 693666c..9088bea 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 9e21ffd..fdc2ad9 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") -- GitLab From 4bec9c41901ede63b572ab3c81d79434b8ff3af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Sun, 11 Mar 2018 19:01:45 -0400 Subject: [PATCH 4/4] Point requirements.txt back at dagrt master --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ea3efa8..e22f333 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ git+git://github.com/inducer/pytools git+git://github.com/inducer/pymbolic -git+https://gitlab.tiker.net/inducer/dagrt.git@insn-to-statement +git+https://gitlab.tiker.net/inducer/dagrt.git \ No newline at end of file -- GitLab