diff --git a/examples/implicit_euler/implicit_euler.py b/examples/implicit_euler/implicit_euler.py index 2a073b508e3a9ec498a943354edd47316a10a540..f52e9190a8a7133115b1a6f265f18d52a5335bdb 100644 --- a/examples/implicit_euler/implicit_euler.py +++ b/examples/implicit_euler/implicit_euler.py @@ -53,8 +53,8 @@ class ImplicitEulerMethod(Method): with CodeBuilder(label="primary") as cb: self._make_primary(cb) - code = DAGCode.create_with_steady_state( - dep_on=cb.state_dependencies, + code = DAGCode.create_with_steady_phase( + dep_on=cb.phase_dependencies, instructions=cb.instructions) from leap.implicit import replace_AssignSolved diff --git a/examples/implicit_euler/test_implicit_euler.py b/examples/implicit_euler/test_implicit_euler.py index 0ad7c6c537547ea65b3be53b26d9012b4063366d..8066452bee23f7ce87ab2a1062ee36e2fed5b79c 100755 --- a/examples/implicit_euler/test_implicit_euler.py +++ b/examples/implicit_euler/test_implicit_euler.py @@ -131,5 +131,5 @@ if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1]) else: - from py.test.cmdline import main + from pytest import main main([__file__]) diff --git a/examples/stability/mr-max-eigvals.py b/examples/stability/mr-max-eigvals.py index 4c784b7f996b46231c20fbffd3094e7fc4ecc82f..f8055e648bb235d3204b061ae627d405bf7a15c5 100644 --- a/examples/stability/mr-max-eigvals.py +++ b/examples/stability/mr-max-eigvals.py @@ -47,7 +47,7 @@ def main(): }, exclude_variables=["

bootstrap_step"]) - mat = finder.get_state_step_matrix("primary") + mat = finder.get_phase_step_matrix("primary") left = -3 right = 1 diff --git a/examples/stability/mr-stability-diagram.py b/examples/stability/mr-stability-diagram.py index 74b8f61e1c5a3af76b55b263887895af46210ea1..2cb1fe9244b5ea4c411c5fa046e6b82861ce8240 100644 --- a/examples/stability/mr-stability-diagram.py +++ b/examples/stability/mr-stability-diagram.py @@ -38,7 +38,7 @@ def main(): }, exclude_variables=["

bootstrap_step"]) - mat = finder.get_state_step_matrix("primary") + mat = finder.get_phase_step_matrix("primary") if 0: print('Variables: %s' % finder.variables) diff --git a/examples/stability/multirate-step-matrix.py b/examples/stability/multirate-step-matrix.py index c321c00e034e08ddbcd6ecbb57cb3ba2b2e6b8df..1c60cb569a3362ad7b33e165d4844cb3b53d07c9 100644 --- a/examples/stability/multirate-step-matrix.py +++ b/examples/stability/multirate-step-matrix.py @@ -33,7 +33,7 @@ def main(): }, exclude_variables=["

bootstrap_step"]) - mat = finder.get_state_step_matrix("primary") + mat = finder.get_phase_step_matrix("primary") if 0: print('Variables: %s' % finder.variables) diff --git a/examples/stability/step-matrix.py b/examples/stability/step-matrix.py index 2ad82bee0b0aa9f93180eb8552d20c045388d69d..2cb942a7c3312b512db8d6ffe0837796daa935f6 100644 --- a/examples/stability/step-matrix.py +++ b/examples/stability/step-matrix.py @@ -24,7 +24,7 @@ def main(): exclude_variables=["

step"]) print(finder.get_maxima_expressions("primary")) - mat = finder.get_state_step_matrix("primary") + mat = finder.get_phase_step_matrix("primary") print('Variables: %s' % finder.variables) np.set_printoptions(formatter={"all": str}) diff --git a/leap/implicit.py b/leap/implicit.py index 79f7021fa6aa52934878ba88767d64217a772972..f7d891e6e50f2d2d96ef93ea2fef958a80b3f5b0 100644 --- a/leap/implicit.py +++ b/leap/implicit.py @@ -53,10 +53,10 @@ def replace_AssignSolved(dag, solver_hooks): from dagrt.language import AssignExpression, AssignSolved - new_states = {} + new_phases = {} - for state_name, state in dag.states.items(): - for insn in state.instructions: + for phase_name, phase in dag.phases.items(): + for insn in phase.instructions: if not isinstance(insn, AssignSolved): new_instructions.append(insn) @@ -81,6 +81,6 @@ def replace_AssignSolved(dag, solver_hooks): condition=insn.condition, depends_on=insn.depends_on)) - new_states[state_name] = state.copy(instructions=new_instructions) + new_phases[phase_name] = phase.copy(instructions=new_instructions) - return dag.copy(states=new_states) + return dag.copy(phases=new_phases) diff --git a/leap/multistep/__init__.py b/leap/multistep/__init__.py index 0787df3b6a76b13e6bbffd05d58f58daa6a181ec..3eff65bbd425a9cdb3a10d7d6a87e64125080bca 100644 --- a/leap/multistep/__init__.py +++ b/leap/multistep/__init__.py @@ -328,11 +328,11 @@ class AdamsBashforthMethod(Method): if self.hist_length == 1: # The first order method requires no bootstrapping. return DAGCode( - states={ - "initial": cb_init.as_execution_state(next_state="primary"), - "primary": cb_primary.as_execution_state(next_state="primary") + phases={ + "initial": cb_init.as_execution_phase(next_phase="primary"), + "primary": cb_primary.as_execution_phase(next_phase="primary") }, - initial_state="initial") + initial_phase="initial") # Bootstrap with CodeBuilder(label="bootstrap") as cb_bootstrap: @@ -343,15 +343,15 @@ class AdamsBashforthMethod(Method): time_id='', time=self.t) cb_bootstrap(self.step, self.step + 1) with cb_bootstrap.if_(self.step, "==", self.hist_length): - cb_bootstrap.state_transition("primary") + cb_bootstrap.phase_transition("primary") return DAGCode( - states={ - "initialization": cb_init.as_execution_state("bootstrap"), - "bootstrap": cb_bootstrap.as_execution_state("bootstrap"), - "primary": cb_primary.as_execution_state("primary"), + phases={ + "initialization": cb_init.as_execution_phase("bootstrap"), + "bootstrap": cb_bootstrap.as_execution_phase("bootstrap"), + "primary": cb_primary.as_execution_phase("primary"), }, - initial_state="initialization") + initial_phase="initialization") def eval_rhs(self, t, y): """Return a node that evaluates the RHS at the given time and diff --git a/leap/multistep/multirate/__init__.py b/leap/multistep/multirate/__init__.py index 421e670ed53fae0d8a1cfa3635301be33cac7cfd..6c55997b87b7f90140ab6a0928eaebf07bd8a535 100644 --- a/leap/multistep/multirate/__init__.py +++ b/leap/multistep/multirate/__init__.py @@ -729,7 +729,7 @@ class MultiRateMultiStepMethod(Method): if isubstep == 0: with cb.if_(self.bootstrap_step, "==", bootstrap_steps): - cb.state_transition("primary") + cb.phase_transition("primary") cb.exit_step() cb.fence() @@ -1167,12 +1167,12 @@ class MultiRateMultiStepMethod(Method): self.emit_rk_bootstrap(cb_bootstrap) return DAGCode( - states={ - "initialization": cb_init.as_execution_state("bootstrap"), - "bootstrap": cb_bootstrap.as_execution_state("bootstrap"), - "primary": cb_primary.as_execution_state("primary"), + phases={ + "initialization": cb_init.as_execution_phase("bootstrap"), + "bootstrap": cb_bootstrap.as_execution_phase("bootstrap"), + "primary": cb_primary.as_execution_phase("primary"), }, - initial_state="initialization") + initial_phase="initialization") # }}} diff --git a/leap/rk/__init__.py b/leap/rk/__init__.py index 408d40413a75853fdfa00452892bd496564aff0d..c421e1c6694a091e63aeee8a8aae7d24a241de4c 100644 --- a/leap/rk/__init__.py +++ b/leap/rk/__init__.py @@ -149,6 +149,7 @@ class ButcherTableauMethod(Method): coeff_sum = sum(stage_coeff_sets[name][istage]) assert abs(coeff_sum - self.c[istage]) < 1e-12, ( name, istage, coeff_sum, self.c[istage]) + # }}} # {{{ initialization @@ -340,11 +341,11 @@ class ButcherTableauMethod(Method): # }}} return DAGCode( - states={ - "initial": cb_init.as_execution_state(next_state="primary"), - "primary": cb_primary.as_execution_state(next_state="primary") + phases={ + "initial": cb_init.as_execution_phase(next_phase="primary"), + "primary": cb_primary.as_execution_phase(next_phase="primary") }, - initial_state="initial") + initial_phase="initial") def finish(self, cb, estimate_names, estimate_vars): cb(self.state, estimate_vars[0]) @@ -769,11 +770,11 @@ class LSRK4Method(Method): from dagrt.language import DAGCode return DAGCode( - states={ - "initial": cb_init.as_execution_state(next_state="primary"), - "primary": cb_primary.as_execution_state(next_state="primary") + phases={ + "initial": cb_init.as_execution_phase(next_phase="primary"), + "primary": cb_primary.as_execution_phase(next_phase="primary") }, - initial_state="initial") + initial_phase="initial") # }}} diff --git a/leap/step_matrix.py b/leap/step_matrix.py index 2c000f7571daed7dea4cbb17f2a95d0569658ff7..693666ccdd41c27129389323f6ce86767188fb6d 100644 --- a/leap/step_matrix.py +++ b/leap/step_matrix.py @@ -94,8 +94,8 @@ class StepMatrixFinder(object): def _get_state_variables(self): """Extract all state-related variables from the code.""" all_var_ids = set() - for state in six.itervalues(self.code.states): - for inst in state.instructions: + for phase in six.itervalues(self.code.phases): + for inst in phase.instructions: all_var_ids |= inst.get_written_variables() all_var_ids |= inst.get_read_variables() @@ -112,11 +112,11 @@ class StepMatrixFinder(object): VectorComponent = namedtuple("VectorComponent", "name, index") - def run_symbolic_step(self, state_name, shapes={}): + def run_symbolic_step(self, phase_name, shapes={}): """ `shapes` maps variable names to vector lengths. """ - state = self.code.states[state_name] + phase = self.code.phases[phase_name] from pymbolic import var @@ -143,14 +143,14 @@ class StepMatrixFinder(object): self.context[""] = 0 self.exec_controller.reset() - self.exec_controller.update_plan(state, state.depends_on) - for event in self.exec_controller(state, self): + self.exec_controller.update_plan(phase, phase.depends_on) + for event in self.exec_controller(phase, self): pass return components, initial_vals - def get_maxima_expressions(self, state_name, shapes={}): - components, initial_vals = self.run_symbolic_step(state_name, shapes) + def get_maxima_expressions(self, phase_name, shapes={}): + components, initial_vals = self.run_symbolic_step(phase_name, shapes) lines = [] @@ -184,7 +184,7 @@ class StepMatrixFinder(object): return "\n".join(lines) - def get_state_step_matrix(self, state_name, shapes={}, sparse=False): + def get_phase_step_matrix(self, phase_name, shapes={}, sparse=False): """ `shapes` maps variable names to vector lengths. @@ -193,7 +193,7 @@ class StepMatrixFinder(object): Otherwise returns a numpy object array. """ - components, initial_vals = self.run_symbolic_step(state_name, shapes) + components, initial_vals = self.run_symbolic_step(phase_name, shapes) from pymbolic.mapper.differentiator import DifferentiationMapper from pymbolic.mapper.dependency import DependencyMapper @@ -270,7 +270,7 @@ class StepMatrixFinder(object): def exec_FailStep(self, insn): raise FailStepException() - def exec_StateTransition(self, insn): + def exec_PhaseTransition(self, insn): pass # }}} diff --git a/leap/transform.py b/leap/transform.py index e0fdc68f47d20fa40aaa61b940dfdf865faee1e7..9e21ffd8a9ddd13dc71c1c4cdeefd832bcb88334 100644 --- a/leap/transform.py +++ b/leap/transform.py @@ -58,14 +58,14 @@ def _update_t_by_dt_factor(factor, instructions): for insn in instructions] -def strang_splitting(dag1, dag2, stepping_state): +def strang_splitting(dag1, dag2, stepping_phase): """Given two time advancement routines (in *dag1* and *dag2*), returns a single second-order accurate time advancement routine representing the sum of both of those advancements. :arg dag1: a :class:`dagrt.language.DAGCode` :arg dag2: a :class:`dagrt.language.DAGCode` - :arg stepping_state: the name of the state in *dag1* and *dag2* that carries + :arg stepping_phase: the name of the phase in *dag1* and *dag2* that carries out time stepping to which Strang splitting is to be applied. :returns: a :class:`dagrt.language.DAGCode` """ @@ -91,39 +91,39 @@ def strang_splitting(dag1, dag2, stepping_state): # }}} - all_states = frozenset(dag1.states) | frozenset(dag2.states) - from dagrt.language import DAGCode, ExecutionState - new_states = {} - for state_name in all_states: - state1 = dag1.states.get(state_name) - state2 = dag2.states.get(state_name) + all_phases = frozenset(dag1.phases) | frozenset(dag2.phases) + from dagrt.language import DAGCode, ExecutionPhase + new_phases = {} + for phase_name in all_phases: + phase1 = dag1.phases.get(phase_name) + phase2 = dag2.phases.get(phase_name) substed_s2_insns = [ insn.map_expressions(subst2_mapper) - for insn in state2.instructions] + for insn in phase2.instructions] - if state_name == stepping_state: - assert state1 is not None - assert state2 is not None + if phase_name == stepping_phase: + assert phase1 is not None + assert phase2 is not None from pymbolic import var dt_half = SubstitutionMapper( make_subst_func({"

": var("
") / 2})) - state1_half_dt = [ + phase1_half_dt = [ insn.map_expressions(dt_half) - for insn in state1.instructions] + for insn in phase1.instructions] - if state1.next_state != state2.next_state: + if phase1.next_phase != phase2.next_phase: raise ValueError("DAGs don't agree on default " - "state transition out of state '%s'" - % state_name) + "phase transition out of phase '%s'" + % phase_name) - s2_name = state_name + "_s2" - s3_name = state_name + "_s3" + s2_name = phase_name + "_s2" + s3_name = phase_name + "_s3" - assert s2_name not in all_states - assert s3_name not in all_states + assert s2_name not in all_phases + assert s3_name not in all_phases """ du/dt = A + B @@ -133,31 +133,31 @@ def strang_splitting(dag1, dag2, stepping_state): 3. Starting with u2, solve du / dt = A from t = 1/2 to 1, get u3 4. Return u3 """ - new_states[state_name] = ExecutionState( - next_state=s2_name, - depends_on=state1.depends_on, + new_phases[phase_name] = ExecutionPhase( + next_phase=s2_name, + depends_on=phase1.depends_on, instructions=( _update_t_by_dt_factor(0, _elide_yield_state( - state1_half_dt)))) - new_states[s2_name] = ExecutionState( - next_state=s3_name, - depends_on=state2.depends_on, + phase1_half_dt)))) + new_phases[s2_name] = ExecutionPhase( + next_phase=s3_name, + depends_on=phase2.depends_on, instructions=( _update_t_by_dt_factor(1/2, _elide_yield_state( substed_s2_insns)))) - new_states[s3_name] = ExecutionState( - next_state=state1.next_state, - depends_on=state1.depends_on, - instructions=state1_half_dt) + new_phases[s3_name] = ExecutionPhase( + next_phase=phase1.next_phase, + depends_on=phase1.depends_on, + instructions=phase1_half_dt) else: - from dagrt.transform import fuse_two_states - new_states[state_name] = fuse_two_states(state_name, - state1, - state2.copy(instructions=substed_s2_insns)) + from dagrt.transform import fuse_two_phases + new_phases[phase_name] = fuse_two_phases(phase_name, + phase1, + phase2.copy(instructions=substed_s2_insns)) - if dag1.initial_state != dag2.initial_state: - raise ValueError("DAGs don't agree on initial state") + if dag1.initial_phase != dag2.initial_phase: + raise ValueError("DAGs don't agree on initial phase") - return DAGCode(new_states, dag1.initial_state) + return DAGCode(new_phases, dag1.initial_phase) diff --git a/leap/version.py b/leap/version.py index 1da70a1e09bc16f4b7e677505af6cf4dd4502b86..aac009869c50439ea6faf456d7ab641f1f8e915d 100644 --- a/leap/version.py +++ b/leap/version.py @@ -1,2 +1,2 @@ -VERSION = (2015, 1) +VERSION = (2018, 1) VERSION_TEXT = ".".join(str(i) for i in VERSION) diff --git a/setup.py b/setup.py index a104777f897f95756719adf55d7f8bb0a99a2c10..9d4bceb6eea142b0796ffe2afb4ca264bdb3da67 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ def main(): "pytools>=2014.1", "pymbolic>=2014.1", "pytest>=2.3", - "dagrt", + "dagrt>=2018.1", "mako", "six", ], diff --git a/test/test_step_matrix.py b/test/test_step_matrix.py index ed70271bd30245c3b09d75a079dcff4d2a9834e1..d077d21f6e0d7fd2775141e091a63a13176fe693 100755 --- a/test/test_step_matrix.py +++ b/test/test_step_matrix.py @@ -63,7 +63,7 @@ def test_step_matrix(method, show_matrix=True, show_dag=False): finder = StepMatrixFinder(code, function_map={"" + component_id: rhs_sym}) - mat = finder.get_state_step_matrix("primary") + mat = finder.get_phase_step_matrix("primary") if show_matrix: print('Variables: %s' % finder.variables) @@ -82,17 +82,17 @@ def test_step_matrix(method, show_matrix=True, show_dag=False): interp = NumpyInterpreter(code, function_map={"" + component_id: rhs}) interp.set_up(t_start=0, dt_start=dt, context={component_id: 15}) - assert interp.next_state == "initial" + assert interp.next_phase == "initial" for event in interp.run_single_step(): pass - assert interp.next_state == "primary" + assert interp.next_phase == "primary" start_values = np.array( [interp.context[v] for v in finder.variables]) for event in interp.run_single_step(): pass - assert interp.next_state == "primary" + assert interp.next_phase == "primary" stop_values = np.array( [interp.context[v] for v in finder.variables]) @@ -139,7 +139,7 @@ def test_step_matrix_vector_state(show_matrix=True, show_dag=False): code, function_map={"" + component_id: rhs_sym}, variables=["" + component_id]) - mat = finder.get_state_step_matrix("primary", + mat = finder.get_phase_step_matrix("primary", shapes={"" + component_id: 3}) if show_matrix: @@ -168,7 +168,7 @@ def test_step_matrix_fast_eval(): code, function_map={"" + component_id: rhs_sym}, variables=["" + component_id]) - mat = finder.get_state_step_matrix("primary", + mat = finder.get_phase_step_matrix("primary", shapes={"" + component_id: 3}) eval_mat = fast_evaluator(mat) @@ -192,7 +192,7 @@ def test_step_matrix_sparse(): dt = var("
") - mat = finder.get_state_step_matrix("primary", + mat = finder.get_phase_step_matrix("primary", shapes={"" + component_id: 3}, sparse=True)