Skip to content

Commit

Permalink
Merge pull request OpenMDAO#287 from crecine/level1_phase_info_fix
Browse files Browse the repository at this point in the history
fixed bugs related to specifying phase_info from the CLI
  • Loading branch information
crecine authored May 28, 2024
2 parents 6f260ec + 04286bf commit 14c0a6d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 10 additions & 0 deletions aviary/interface/methods_for_level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions aviary/interface/test/test_cmd_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="IPOPT")
def bench_test_phase_info_cmd(self):
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)

def test_diff_configuration_conversion(self):
filepath = pkg_resources.resource_filename('aviary',
'models/test_aircraft/converter_configuration_test_data_GwGm.dat')
Expand Down
13 changes: 8 additions & 5 deletions aviary/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 14c0a6d

Please sign in to comment.