def run_iteration(self, case_uuid=None): """Runs workflow.""" wf = self.workflow if not wf._ordering: self._logger.warning("'%s': workflow is empty!" % self.get_pathname()) if not wf._system.is_active(): return self._stop = False self.workflow._exec_count += 1 iterbase = wf._iterbase() if not case_uuid: # We record the case and are responsible for unique case ids. record_case = True case_uuid = Case.next_uuid() else: record_case = False err = None try: uvec = wf._system.vec['u'] fvec = wf._system.vec['f'] if wf._need_prescatter: wf._system.scatter('u', 'p') # save old value of u to compute resids for node in wf._cycle_vars: fvec[node][:] = uvec[node][:] wf._system.run(iterbase=iterbase, case_uuid=case_uuid) # update resid vector for cyclic vars for node in wf._cycle_vars: fvec[node][:] -= uvec[node][:] if self._stop: raise RunStopped('Stop requested') except Exception: err = sys.exc_info() if record_case and wf._rec_required: try: wf._record_case(case_uuid, err) except Exception as exc: if err is None: err = sys.exc_info() self._logger.error("Can't record case: %s", exc) # reraise exception with proper traceback if one occurred if err is not None: # NOTE: cannot use 'raise err' here for some reason. Must separate # the parts of the tuple. raise err[0], err[1], err[2]
def run(self, ffd_order=0, case_uuid=None): """ Run the Components in this Workflow. """ self._stop = False self._exec_count += 1 iterbase = self._iterbase() if case_uuid is None: # We record the case and are responsible for unique case ids. record_case = True case_uuid = Case.next_uuid() else: record_case = False err = None scope = self.scope try: for comp in self: # before the workflow runs each component, update that # component's inputs based on the graph scope.update_inputs(comp.name, graph=self._var_graph) if isinstance(comp, PseudoComponent): comp.run(ffd_order=ffd_order) else: comp.set_itername('%s-%s' % (iterbase, comp.name)) comp.run(ffd_order=ffd_order, case_uuid=case_uuid) if self._stop: raise RunStopped('Stop requested') except Exception: err = sys.exc_info() if record_case and self._rec_required: try: self._record_case(case_uuid, err) except Exception as exc: if err is None: err = sys.exc_info() self.parent._logger.error("Can't record case: %s", exc) # reraise exception with proper traceback if one occurred if err is not None: # NOTE: cannot use 'raise err' here for some reason. Must separate # the parts of the tuple. raise err[0], err[1], err[2]
def run(self, ffd_order=0, case_uuid=None): """ Run the Components in this Workflow. """ self._stop = False self._exec_count += 1 iterbase = self._iterbase() if case_uuid is None: # We record the case and are responsible for unique case ids. record_case = True case_uuid = Case.next_uuid() else: record_case = False err = None scope = self.scope try: for comp in self: # before the workflow runs each component, update that # component's inputs based on the graph scope.update_inputs(comp.name, graph=self._var_graph) if isinstance(comp, PseudoComponent): comp.run(ffd_order=ffd_order) else: comp.set_itername('%s-%s' % (iterbase, comp.name)) comp.run(ffd_order=ffd_order, case_uuid=case_uuid) if self._stop: raise RunStopped('Stop requested') except Exception as exc: err = TracedError(exc, format_exc()) if record_case and self._rec_required: try: self._record_case(case_uuid, err) except Exception as exc: if err is None: err = TracedError(exc, format_exc()) self.parent._logger.error("Can't record case: %s", exc) if err is not None: err.reraise(with_traceback=False)
def execute(self): """ General Newton's method. """ if MPI: if self.workflow._system.mpi.comm == MPI.COMM_NULL: return system = self.workflow._system options = self.gradient_options fvec = system.vec['f'] dfvec = system.vec['df'] uvec = system.vec['u'] iterbase = self.workflow._iterbase() nstring = 'NEWTON' # perform an initial run system.evaluate(iterbase, case_uuid=Case.next_uuid()) f_norm = get_norm(fvec) f_norm0 = f_norm if self.iprint > 0: self.print_norm(nstring, 0, f_norm, f_norm0) itercount = 0 alpha = self.alpha while itercount < self.max_iteration and f_norm > self.atol and \ f_norm/f_norm0 > self.rtol: system.calc_newton_direction(options=options) #print "LS 1", uvec.array, '+', dfvec.array uvec.array += alpha*dfvec.array # Just evaluate the model with the new points system.evaluate(iterbase, case_uuid=Case.next_uuid()) f_norm = get_norm(fvec) if self.iprint > 0: self.print_norm(nstring, itercount+1, f_norm, f_norm0) itercount += 1 ls_itercount = 0 # Backtracking Line Search while ls_itercount < self.ls_max_iteration and \ f_norm > self.ls_atol and \ f_norm/f_norm0 > self.ls_rtol: alpha *= 0.5 uvec.array -= alpha*dfvec.array # Just evaluate the model with the new points system.evaluate(iterbase, case_uuid=Case.next_uuid()) f_norm = get_norm(fvec) if self.iprint> 1: self.print_norm('BK_TKG', itercount+1, f_norm, f_norm/f_norm0, indent=1, solver='LS') ls_itercount += 1 # Reset backtracking alpha = self.alpha # Need to make sure the whole workflow is executed at the final # point, not just evaluated. self.pre_iteration() self.run_iteration() self.post_iteration() if self.iprint > 0: self.print_norm(nstring, itercount, f_norm, f_norm0, msg='Converged')
def execute(self): """ General Newton's method. """ if MPI: if self.workflow._system.mpi.comm == MPI.COMM_NULL: return system = self.workflow._system options = self.gradient_options fvec = system.vec['f'] dfvec = system.vec['df'] uvec = system.vec['u'] iterbase = self.workflow._iterbase() # perform an initial run self.workflow._system.evaluate(iterbase, case_uuid=Case.next_uuid()) f_norm = self.norm() f_norm0 = f_norm if self.iprint == 1: print self.name, "Norm: ", f_norm, 0 itercount = 0 alpha = self.alpha while itercount < self.max_iteration and f_norm > self.atol and \ f_norm/f_norm0 > self.rtol: system.calc_newton_direction(options=options) #print "LS 1", uvec.array, '+', dfvec.array uvec.array += alpha*dfvec.array # Just evaluate the model with the new points self.workflow._system.evaluate(iterbase, case_uuid=Case.next_uuid()) f_norm = self.norm() if self.iprint == 1: print self.name, "Norm: ", f_norm, itercount+1 itercount += 1 ls_itercount = 0 # Backtracking Line Search while ls_itercount < self.ls_max_iteration and \ f_norm > self.ls_atol and \ f_norm/f_norm0 > self.ls_rtol: alpha *= 0.5 uvec.array -= alpha*dfvec.array # Just evaluate the model with the new points self.workflow._system.evaluate(iterbase, case_uuid=Case.next_uuid()) f_norm = self.norm() if self.iprint == 2: print "Backtracking Norm: %f, Alpha: %f" % (f_norm, alpha) ls_itercount += 1 # Reset backtracking alpha = self.alpha # Need to make sure the whole workflow is executed at the final # point, not just evaluated. self.pre_iteration() self.run_iteration() self.post_iteration() if self.iprint == 1: print self.name, "converged"