From c0377aace19e0599f9ba666458fa2f65aee7d922 Mon Sep 17 00:00:00 2001 From: Carl Recine Date: Tue, 28 May 2024 11:59:21 -0700 Subject: [PATCH 1/2] fixed bugs related to specifying phase_info from the CLI phase_info was being treated as a dict when it was passed to run_aviary, added a preprocessor to run_level_1 that extracts phase_info and phase_info_parameterization (if present) from the file path that is specified through the CLI and then passes them to run_aviary. Also prevented the FileNotFoundError raised in get_model from causing get_path to fail prematurely. --- aviary/interface/methods_for_level1.py | 10 ++++++++++ aviary/interface/test/test_cmd_entry_points.py | 6 ++++++ aviary/utils/functions.py | 13 ++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/aviary/interface/methods_for_level1.py b/aviary/interface/methods_for_level1.py index 58378d71e..ee1dc518f 100644 --- a/aviary/interface/methods_for_level1.py +++ b/aviary/interface/methods_for_level1.py @@ -2,11 +2,13 @@ This file contains functions needed to run Aviary using the Level 1 interface. """ import os +from importlib.machinery import SourceFileLoader from pathlib import Path import openmdao.api as om from aviary.variable_info.enums import AnalysisScheme, Verbosity from aviary.interface.methods_for_level2 import AviaryProblem +from aviary.utils.functions import get_path def run_aviary(aircraft_filename, phase_info, optimizer=None, @@ -122,6 +124,14 @@ def run_level_1( # else: kwargs['optimizer'] = optimizer + if isinstance(phase_info, str): + phase_info_path = get_path(phase_info) + phase_info_file = SourceFileLoader( + "phase_info_file", str(phase_info_path)).load_module() + phase_info = getattr(phase_info_file, 'phase_info') + kwargs['phase_info_parameterization'] = getattr( + phase_info_file, 'phase_info_parameterization', None) + prob = run_aviary(input_deck, phase_info, **kwargs) if n2: diff --git a/aviary/interface/test/test_cmd_entry_points.py b/aviary/interface/test/test_cmd_entry_points.py index 1ae378f7e..035a743d8 100644 --- a/aviary/interface/test/test_cmd_entry_points.py +++ b/aviary/interface/test/test_cmd_entry_points.py @@ -34,6 +34,12 @@ def bench_test_IPOPT_cmd(self): ' --optimizer IPOPT --max_iter 1 --shooting' self.run_and_test_cmd(cmd) + @require_pyoptsparse(optimizer="SNOPT") + def bench_test_phase_info_cmd(self): + cmd = 'aviary run_mission models/test_aircraft/aircraft_for_bench_GwGm.csv --optimizer SNOPT --max_iter 1' \ + ' --phase_info interface/default_phase_info/two_dof.py' + self.run_and_test_cmd(cmd) + def test_diff_configuration_conversion(self): filepath = pkg_resources.resource_filename('aviary', 'models/test_aircraft/converter_configuration_test_data_GwGm.dat') diff --git a/aviary/utils/functions.py b/aviary/utils/functions.py index a28dd7316..51189b515 100644 --- a/aviary/utils/functions.py +++ b/aviary/utils/functions.py @@ -357,11 +357,14 @@ def get_path(path: [str, Path], verbose: bool = False) -> Path: # If the path still doesn't exist, attempt to find it in the models directory. if not path.exists(): - hangar_based_path = get_model(original_path) - if verbose: - print( - f"Unable to locate '{aviary_based_path}' as an Aviary package path, checking built-in models") - path = hangar_based_path + try: + hangar_based_path = get_model(original_path) + if verbose: + print( + f"Unable to locate '{aviary_based_path}' as an Aviary package path, checking built-in models") + path = hangar_based_path + except FileNotFoundError: + pass # If the path still doesn't exist in any of the prioritized locations, raise an error. if not path.exists(): From 04286bf2ce4bcc61bebd2919d8d70355d0cadfb9 Mon Sep 17 00:00:00 2001 From: Carl Recine Date: Tue, 28 May 2024 14:51:19 -0700 Subject: [PATCH 2/2] using IPOPT for CI --- aviary/interface/test/test_cmd_entry_points.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aviary/interface/test/test_cmd_entry_points.py b/aviary/interface/test/test_cmd_entry_points.py index 035a743d8..b8df65de8 100644 --- a/aviary/interface/test/test_cmd_entry_points.py +++ b/aviary/interface/test/test_cmd_entry_points.py @@ -34,9 +34,9 @@ def bench_test_IPOPT_cmd(self): ' --optimizer IPOPT --max_iter 1 --shooting' self.run_and_test_cmd(cmd) - @require_pyoptsparse(optimizer="SNOPT") + @require_pyoptsparse(optimizer="IPOPT") def bench_test_phase_info_cmd(self): - cmd = 'aviary run_mission models/test_aircraft/aircraft_for_bench_GwGm.csv --optimizer SNOPT --max_iter 1' \ + cmd = 'aviary run_mission models/test_aircraft/aircraft_for_bench_GwGm.csv --optimizer IPOPT --max_iter 1' \ ' --phase_info interface/default_phase_info/two_dof.py' self.run_and_test_cmd(cmd)