Skip to content

Commit

Permalink
Initial conversion from debug_mode to verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
crecine committed Jan 31, 2024
1 parent c86f157 commit 46f0bc8
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 113 deletions.
6 changes: 3 additions & 3 deletions aviary/examples/level2_shooting_traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from aviary.api import AviaryProblem
from aviary.api import AnalysisScheme, SpeedType, AlphaModes
from aviary.api import AnalysisScheme, SpeedType, AlphaModes, Verbosity
from aviary.api import FlexibleTraj
from aviary.api import create_2dof_based_ascent_phases
from aviary.api import SGMCruise, SGMDescent
Expand Down Expand Up @@ -57,7 +57,7 @@ def run_aviary(aircraft_filename, phase_info, optimizer=None, analysis_scheme=An
ode_args=prob.ode_args,
alpha_mode=AlphaModes.REQUIRED_LIFT,
simupy_args=dict(
DEBUG=True,
verbosity=Verbosity.DEBUG,
),
)
cruise_vals = {
Expand All @@ -71,7 +71,7 @@ def run_aviary(aircraft_filename, phase_info, optimizer=None, analysis_scheme=An
speed_trigger_units='kn',
ode_args=prob.ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
descent1_vals = {
Expand Down
22 changes: 11 additions & 11 deletions aviary/interface/default_phase_info/two_dof_fiti.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from aviary.variable_info.enums import SpeedType
from aviary.variable_info.enums import SpeedType, Verbosity
from aviary.mission.gasp_based.phases.time_integration_phases import SGMGroundroll, \
SGMRotation, SGMAscentCombined, SGMAccel, SGMClimb, SGMCruise, SGMDescent
from aviary.variable_info.variables import Aircraft, Mission, Dynamic
Expand All @@ -16,7 +16,7 @@ def create_2dof_based_ascent_phases(
groundroll_kwargs = dict(
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
groundroll_vals = {
Expand All @@ -27,15 +27,15 @@ def create_2dof_based_ascent_phases(
rotation_kwargs = dict(
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
rotation_vals = {}

ascent_kwargs = dict(
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
ascent_vals = {
Expand All @@ -49,7 +49,7 @@ def create_2dof_based_ascent_phases(
accel_kwargs = dict(
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
accel_vals = {}
Expand All @@ -59,7 +59,7 @@ def create_2dof_based_ascent_phases(
input_speed_units='kn',
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
DEverbosity=Verbosity.QUIET,
),
)
climb1_vals = {
Expand All @@ -73,7 +73,7 @@ def create_2dof_based_ascent_phases(
input_speed_units='kn',
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
climb2_vals = {
Expand All @@ -87,7 +87,7 @@ def create_2dof_based_ascent_phases(
input_speed_units='unitless',
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
climb3_vals = {
Expand Down Expand Up @@ -142,7 +142,7 @@ def create_2dof_based_descent_phases(
speed_trigger_units='kn',
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
descent1_vals = {
Expand All @@ -157,7 +157,7 @@ def create_2dof_based_descent_phases(
speed_trigger_units='kn',
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
descent2_vals = {
Expand All @@ -172,7 +172,7 @@ def create_2dof_based_descent_phases(
speed_trigger_units='kn',
ode_args=ode_args,
simupy_args=dict(
DEBUG=False,
verbosity=Verbosity.QUIET,
),
)
descent3_vals = {
Expand Down
20 changes: 10 additions & 10 deletions aviary/interface/methods_for_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

from aviary.variable_info.functions import setup_trajectory_params, override_aviary_vars
from aviary.variable_info.variables import Aircraft, Mission, Dynamic, Settings
from aviary.variable_info.enums import AnalysisScheme, ProblemType, SpeedType, AlphaModes, EquationsOfMotion, LegacyCode
from aviary.variable_info.enums import AnalysisScheme, ProblemType, SpeedType, AlphaModes, EquationsOfMotion, LegacyCode, Verbosity
from aviary.variable_info.variable_meta_data import _MetaData as BaseMetaData
from aviary.variable_info.variables_in import VariablesIn

Expand Down Expand Up @@ -936,7 +936,7 @@ def add_phases(self, phase_info_parameterization=None):
ode_args=self.ode_args,
alpha_mode=AlphaModes.REQUIRED_LIFT,
simupy_args=dict(
DEBUG=True,
verbosity=Verbosity.DEBUG,
),
)
cruise_vals = {
Expand Down Expand Up @@ -1456,7 +1456,7 @@ def connect_with_common_params(self, source, target):
for source, target in connect_map.items():
connect_with_common_params(self, source, target)

def add_driver(self, optimizer=None, use_coloring=None, max_iter=50, debug_print=False):
def add_driver(self, optimizer=None, use_coloring=None, max_iter=50, verbosity=Verbosity.QUIET):
"""
Add an optimization driver to the Aviary problem.
Expand All @@ -1477,8 +1477,8 @@ def add_driver(self, optimizer=None, use_coloring=None, max_iter=50, debug_print
The maximum number of iterations allowed for the optimization process. Default is 50. This option is
applicable to "SNOPT", "IPOPT", and "SLSQP" optimizers.
debug_print : bool or list, optional
If True, default debug print options ['desvars','ln_cons','nl_cons','objs'] will be set. If a list is
verbosity : Verbosity or list, optional
If Verbosity.DEBUG, debug print options ['desvars','ln_cons','nl_cons','objs'] will be set. If a list is
provided, it will be used as the debug print options.
Returns
Expand Down Expand Up @@ -1520,9 +1520,9 @@ def add_driver(self, optimizer=None, use_coloring=None, max_iter=50, debug_print
driver.options["maxiter"] = max_iter
driver.options["disp"] = True

if debug_print:
if isinstance(debug_print, list):
driver.options['debug_print'] = debug_print
if verbosity != Verbosity.QUIET:
if isinstance(verbosity, list):
driver.options['debug_print'] = verbosity
else:
driver.options['debug_print'] = ['desvars', 'ln_cons', 'nl_cons', 'objs']

Expand Down Expand Up @@ -2223,7 +2223,7 @@ def run_aviary_problem(self,
If True (default), Dymos html plots will be generated as part of the output.
"""

if self.aviary_inputs.get_val('debug_mode'):
if self.aviary_inputs.get_val('verbosity').value >= 2:
self.final_setup()
with open('input_list.txt', 'w') as outfile:
self.model.list_inputs(out_stream=outfile)
Expand All @@ -2245,7 +2245,7 @@ def run_aviary_problem(self,
failed = self.run_model()
warnings.filterwarnings('default', category=UserWarning)

if self.aviary_inputs.get_val('debug_mode'):
if self.aviary_inputs.get_val('verbosity').value >= 2:
with open('output_list.txt', 'w') as outfile:
self.model.list_outputs(out_stream=outfile)

Expand Down
31 changes: 16 additions & 15 deletions aviary/mission/gasp_based/ode/time_integration_base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from simupy.systems import DynamicalSystem

from aviary.mission.gasp_based.ode.params import ParamPort
from aviary.variable_info.enums import Verbosity


def add_SGM_required_inputs(group: om.Group, inputs_to_add: dict):
Expand Down Expand Up @@ -34,7 +35,7 @@ def __init__(
controls=None,
include_state_outputs=False,
rate_suffix="_rate",
DEBUG=False,
verbosity=Verbosity.QUIET,
max_allowable_time=1_000_000,
adjoint_int_opts=DEFAULT_INTEGRATOR_OPTIONS.copy(),

Expand All @@ -55,7 +56,7 @@ def __init__(
default_om_list_args = dict(prom_name=True, val=False,
out_stream=None, units=True)

self.DEBUG = DEBUG
self.verbosity = verbosity
self.max_allowable_time = max_allowable_time
self.adjoint_int_opts = adjoint_int_opts
self.adjoint_int_opts['nsteps'] = 5000
Expand Down Expand Up @@ -186,7 +187,7 @@ def __init__(
# TODO: add defensive checks to make sure dimensions match in both setup and
# calls

if DEBUG or True:
if verbosity is Verbosity.DEBUG or True:
om.n2(prob, outfile="n2_simupy_problem.html", show_browser=False)
with open('input_list_simupy.txt', 'w') as outfile:
prob.model.list_inputs(out_stream=outfile,)
Expand Down Expand Up @@ -347,7 +348,7 @@ def initialize(self):
# TODO: param_dict
self.options.declare("param_dict",
default=ParamPort.param_data)
self.DEBUG = False
self.verbosity = Verbosity.QUIET
self.max_allowable_time = 1_000_000
self.adjoint_int_opts = DEFAULT_INTEGRATOR_OPTIONS.copy()
self.adjoint_int_opts['nsteps'] = 5000
Expand Down Expand Up @@ -474,7 +475,7 @@ def compute_params(self, inputs):
try:
ode.set_val(input, inputs[input])
except KeyError:
if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print(
"*** Input not found:",
ode,
Expand All @@ -483,7 +484,7 @@ def compute_params(self, inputs):
pass

def compute_traj_loop(self, first_problem, inputs, outputs, t0=0., state0=None):
if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("initializing compute_traj_loop")
sim_results = []
sim_problems = [first_problem]
Expand Down Expand Up @@ -517,7 +518,7 @@ def compute_traj_loop(self, first_problem, inputs, outputs, t0=0., state0=None):
try:
try_next_problem = (yield current_problem, sim_result)
except GeneratorExit:
if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("stop iteration 1")
break

Expand All @@ -527,11 +528,11 @@ def compute_traj_loop(self, first_problem, inputs, outputs, t0=0., state0=None):
try:
next_problem = (yield current_problem, sim_result)
except GeneratorExit:
if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("stop iteration 2")
break

if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print(" was on problem:", current_problem,
"\n got back:", next_problem)
# compute the output at the final condition to make sure all outputs are current
Expand All @@ -544,7 +545,7 @@ def compute_traj_loop(self, first_problem, inputs, outputs, t0=0., state0=None):
).squeeze()
sim_problems.append(next_problem)

if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("ended loop")

# wrap main loop
Expand Down Expand Up @@ -803,7 +804,7 @@ def compute_partials(self, inputs, J):
else:
df_dparams.append(None)

if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("data....")
print("dgs", dg_dxs)
print("f-", f_minuses)
Expand All @@ -822,7 +823,7 @@ def compute_partials(self, inputs, J):
lamda_dot_plus = np.zeros_like(costate)

# self.sim_results[-1].x[-1, next_prob.state_names.index(output)]
if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("\nstarting partial for %s" % output, costate)

dg_dt = 0.
Expand Down Expand Up @@ -872,7 +873,7 @@ def compute_partials(self, inputs, J):
if channel_name != prob.t_name:
lamda_dot = df_dx(res.t[-1]) @ costate
# lamda_dot_plus = lamda_dot
if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
if np.any(state_disc):
print("update is non-zero!", prob, prob.states.keys(),
state_disc, costate, lamda_dot)
Expand Down Expand Up @@ -904,7 +905,7 @@ def compute_partials(self, inputs, J):
in self.traj_event_trigger_input
):
event_trigger_name = self.traj_event_trigger_input[event_key]["name"]
if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("setting event trigger data", event_trigger_name)
J[output_name, event_trigger_name] = (
+ costate[None, :] @ (f_minus - f_plus) /
Expand All @@ -921,7 +922,7 @@ def compute_partials(self, inputs, J):
def co_state_rate(t, costate, *args):
return df_dx(t) @ costate

if self.DEBUG:
if self.verbosity is Verbosity.DEBUG:
print('dim_state:', prob.dim_state, "ic:", costate)

costate_sys = DynamicalSystem(state_equation_function=co_state_rate,
Expand Down
8 changes: 3 additions & 5 deletions aviary/mission/gasp_based/phases/time_integration_phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
from aviary.mission.gasp_based.ode.rotation_ode import RotationODE
from aviary.mission.gasp_based.ode.time_integration_base_classes import SimuPyProblem
from aviary.utils.aviary_values import AviaryValues
from aviary.variable_info.enums import AlphaModes, AnalysisScheme, SpeedType
from aviary.variable_info.enums import AlphaModes, AnalysisScheme, SpeedType, Verbosity
from aviary.variable_info.variables import Aircraft, Dynamic, Mission

DEBUG = 0


class SGMGroundroll(SimuPyProblem):
'''
Expand Down Expand Up @@ -179,11 +177,11 @@ def update_equation_function(self, t, x, event_channels=None):
self.output_nan = True
return x
elif 1 in event_channels:
if DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("flaps!", t)
self.set_val("t_init_flaps", t)
elif 2 in event_channels:
if DEBUG:
if self.verbosity is Verbosity.DEBUG:
print("gear!", t)
self.set_val("t_init_gear", t)
else:
Expand Down
Loading

0 comments on commit 46f0bc8

Please sign in to comment.