def write_n2(configuration_file_path: str, n2_file_path: str = None, overwrite: bool = False): """ Write the N2 diagram of the problem in file n2.html :param configuration_file_path: :param n2_file_path: :param overwrite: """ if not n2_file_path: n2_file_path = pth.join(pth.dirname(configuration_file_path), "n2.html") n2_file_path = pth.abspath(n2_file_path) if not overwrite and pth.exists(n2_file_path): raise FastFileExistsError( "N2-diagram file %s not written because it already exists. " "Use overwrite=True to bypass." % n2_file_path, n2_file_path, ) make_parent_dir(n2_file_path) problem = FASTOADProblemConfigurator(configuration_file_path).get_problem() problem.setup() problem.final_setup() om.n2(problem, outfile=n2_file_path, show_browser=False) _LOGGER.info("N2 diagram written in %s", n2_file_path)
def _run_problem( configuration_file_path: str, overwrite: bool = False, mode="run_model", auto_scaling: bool = False, ) -> FASTOADProblem: """ Runs problem according to provided file :param configuration_file_path: problem definition :param overwrite: if True, output file will be overwritten :param mode: 'run_model' or 'run_driver' :param auto_scaling: if True, automatic scaling is performed for design variables and constraints :return: the OpenMDAO problem after run """ problem = FASTOADProblemConfigurator(configuration_file_path).get_problem( read_inputs=True, auto_scaling=auto_scaling) outputs_path = pth.normpath(problem.output_file_path) if not overwrite and pth.exists(outputs_path): raise FastFileExistsError( "Problem not run because output file %s already exists. " "Use overwrite=True to bypass." % outputs_path, outputs_path, ) problem.setup() start_time = time() if mode == "run_model": problem.run_model() problem.optim_failed = False # Actually, we don't know else: problem.optim_failed = problem.run_driver() end_time = time() computation_time = round(end_time - start_time, 2) problem.write_outputs() if problem.optim_failed: _LOGGER.error("Optimization failed after " + str(computation_time) + " seconds") else: _LOGGER.info("Computation finished after " + str(computation_time) + " seconds") _LOGGER.info("Problem outputs written in %s", outputs_path) return problem
def write_xdsm( configuration_file_path: str, xdsm_file_path: str = None, overwrite: bool = False, depth: int = 2, wop_server_url=None, api_key=None, ): """ :param configuration_file_path: :param xdsm_file_path: :param overwrite: :param depth: :param wop_server_url: :param api_key: :return: """ if not xdsm_file_path: xdsm_file_path = pth.join(pth.dirname(configuration_file_path), "xdsm.html") xdsm_file_path = pth.abspath(xdsm_file_path) if not overwrite and pth.exists(xdsm_file_path): raise FastFileExistsError( "XDSM-diagram file %s not written because it already exists. " "Use overwrite=True to bypass." % xdsm_file_path, xdsm_file_path, ) make_parent_dir(xdsm_file_path) problem = FASTOADProblemConfigurator(configuration_file_path).get_problem() problem.setup() problem.final_setup() wop = WhatsOpt(url=wop_server_url, login=False) try: ok = wop.login(api_key=api_key, echo=False) except requests.exceptions.ConnectionError: if not wop_server_url and wop.url == PROD_URL: used_url = wop.url # If connection failed while attempting to reach the wop default URL, # that is the internal ONERA server, try with the external server try: wop = WhatsOpt(url=DEFAULT_WOP_URL) ok = wop.login(api_key=api_key, echo=False) except requests.exceptions.ConnectionError: _LOGGER.warning("Failed to connect to %s and %s", used_url, DEFAULT_WOP_URL) return else: _LOGGER.warning("Failed to connect to %s", wop.url) return if ok: xdsm = wop.push_mda(problem, { "--xdsm": True, "--name": None, "--dry-run": False, "--depth": depth }) generate_xdsm_html(xdsm, xdsm_file_path) else: wop.logout() _LOGGER.warning("Could not login to %s", wop.url)