def _pre_run_model_debug_print(self): """ Optionally print some debugging information before the model runs. """ debug_opt = self.options['debug_print'] if not debug_opt or debug_opt == ['totals']: return if not MPI or MPI.COMM_WORLD.rank == 0: header = 'Driver debug print for iter coord: {}'.format( recording_iteration.get_formatted_iteration_coordinate()) print(header) print(len(header) * '-') if 'desvars' in debug_opt: desvar_vals = self.get_design_var_values(unscaled=True, ignore_indices=True) if not MPI or MPI.COMM_WORLD.rank == 0: print("Design Vars") if desvar_vals: pprint.pprint(desvar_vals) else: print("None") print() sys.stdout.flush()
def record_iteration(self, recording_requester, data, metadata, **kwargs): """ Route the record_iteration call to the proper method. Parameters ---------- recording_requester : object System, Solver, Driver in need of recording. metadata : dict, optional Dictionary containing execution metadata. data : dict Dictionary containing desvars, objectives, constraints, responses, and System vars. **kwargs : keyword args Some implementations of record_iteration need additional args. """ if not self._parallel: if MPI and MPI.COMM_WORLD.rank > 0: raise RuntimeError( "Non-parallel recorders should not be recording on ranks > 0" ) self._counter += 1 self._iteration_coordinate = recording_iteration.get_formatted_iteration_coordinate( ) if isinstance(recording_requester, Driver): self.record_iteration_driver(recording_requester, data, metadata) elif isinstance(recording_requester, System): self.record_iteration_system(recording_requester, data, metadata) elif isinstance(recording_requester, Solver): self.record_iteration_solver(recording_requester, data, metadata) else: raise ValueError( "Recorders must be attached to Drivers, Systems, or Solvers.")
def record_derivatives(self, recording_requester, data, metadata, **kwargs): """ Route the record_derivatives call to the proper method. Parameters ---------- recording_requester : object System, Solver, Driver in need of recording. data : dict Dictionary containing derivatives keyed by 'of,wrt' to be recorded. metadata : dict Dictionary containing execution metadata. **kwargs : keyword args Some implementations of record_derivatives need additional args. """ if not self._parallel: if MPI and MPI.COMM_WORLD.rank > 0: raise RuntimeError( "Non-parallel recorders should not be recording on ranks > 0" ) self._iteration_coordinate = recording_iteration.get_formatted_iteration_coordinate( ) self.record_derivatives_driver(recording_requester, data, metadata)
def solve(self): """ Run the solver. Returns ------- boolean Failure flag; True if failed to converge, False is successful. float absolute error. float relative error. """ fail, abs_err, rel_err = self._run_iterator() if fail and self.options['debug_print']: coord = recording_iteration.get_formatted_iteration_coordinate() out_str = "\n# Inputs and outputs at start of iteration '%s':\n" % coord for vec_type, vec in iteritems(self._err_cache): out_str += '\n' out_str += '# %s %ss\n' % (vec._name, vec._typ) out_str += pprint.pformat(vec._views) out_str += '\n' print(out_str) filename = coord.replace('._solve_nonlinear', '') filename = re.sub('[^0-9a-zA-Z]', '_', filename) + '.dat' with open(filename, 'w') as f: f.write(out_str) print("Inputs and outputs at start of iteration have been " "saved to '%s'." % filename) sys.stdout.flush() return fail, abs_err, rel_err