Skip to content

Commit

Permalink
modify jupyter notebooks based on Carl's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
xjjiang committed Jan 16, 2025
1 parent acebb0c commit 6b3b6c3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 45 deletions.
2 changes: 1 addition & 1 deletion aviary/docs/developer_guide/doctape_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "latest_env",
"display_name": "av1",
"language": "python",
"name": "python3"
},
Expand Down
16 changes: 7 additions & 9 deletions aviary/docs/getting_started/onboarding_ext_subsystem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
"# Testing Cell\n",
"from aviary.interface.methods_for_level2 import AviaryGroup\n",
"from aviary.utils.doctape import glue_variable\n",
"#from aviary.interface.default_phase_info.two_dof_fiti import\n",
"\n",
"ag = AviaryGroup()\n",
"opts = list(ag.options)\n",
"for opt in opts:\n",
" if opt == 'phase_info': # only need this option to glue\n",
" glue_variable('phase_info', md_code=True)"
" glue_variable(opt, md_code=True)\n"
]
},
{
Expand Down Expand Up @@ -56,18 +55,17 @@
"outputs": [],
"source": [
"# Testing Cell\n",
"import aviary.api as av\n",
"from aviary.utils.functions import get_model, get_path\n",
"from aviary.utils.doctape import glue_variable, get_variable_name\n",
"from aviary.api import Aircraft\n",
"from pathlib import Path\n",
"import pkg_resources\n",
"\n",
"aviary_base_path = Path(pkg_resources.resource_filename('aviary', '.')).parent\n",
"path = get_path('examples/external_subsystems').relative_to(aviary_base_path)\n",
"aviary_top_dir = av.get_path('docs').parent.parent\n",
"path = get_path('examples/external_subsystems').relative_to(aviary_top_dir)\n",
"glue_variable(str(path), md_code=True)\n",
"path = get_path('examples/external_subsystems/battery').relative_to(aviary_base_path)\n",
"path = get_path('examples/external_subsystems/battery').relative_to(aviary_top_dir)\n",
"glue_variable(str(path.stem), md_code=True)\n",
"path = get_path('examples/external_subsystems/simple_weight').relative_to(aviary_base_path)\n",
"path = get_path('examples/external_subsystems/simple_weight').relative_to(aviary_top_dir)\n",
"glue_variable(str(path.stem), md_code=True)\n",
"\n",
"glue_variable(get_variable_name(Aircraft.Wing.MASS), md_code=True)\n",
Expand Down
24 changes: 13 additions & 11 deletions aviary/docs/getting_started/onboarding_level1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
"# Testing Cell\n",
"from aviary.interface.methods_for_level2 import AviaryGroup\n",
"from aviary.utils.doctape import glue_variable\n",
"#from aviary.interface.default_phase_info.two_dof_fiti import\n",
"\n",
"ag = AviaryGroup()\n",
"opts = list(ag.options)\n",
"for opt in opts:\n",
" if opt == 'phase_info': # only need this option to glue\n",
" glue_variable('phase_info', md_code=True)"
" glue_variable(opt, md_code=True)\n"
]
},
{
Expand Down Expand Up @@ -61,8 +60,6 @@
"source": [
"# Testing Cell\n",
"import inspect\n",
"import pkg_resources\n",
"from pathlib import Path\n",
"\n",
"import aviary.api as av\n",
"from aviary.utils.functions import get_model, get_path\n",
Expand All @@ -86,10 +83,10 @@
"glue_dos2unix = 'dos2unix ' + csv_file_name\n",
"glue_variable('dos2unix aircraft_for_bench_GwGm.csv', glue_dos2unix, md_code=False)\n",
"\n",
"aviary_base_path = Path(pkg_resources.resource_filename('aviary', '.')).parent\n",
"path=get_path('models').relative_to(aviary_base_path)\n",
"aviary_top_dir = av.get_path('docs').parent.parent\n",
"path=get_path('models').relative_to(aviary_top_dir)\n",
"glue_variable(str(path), md_code=True)\n",
"path=get_path('models/test_aircraft').relative_to(aviary_base_path)\n",
"path=get_path('models/test_aircraft').relative_to(aviary_top_dir)\n",
"glue_variable(str(path), md_code=True)\n",
"\n",
"check_value(av.EquationsOfMotion.HEIGHT_ENERGY.value, 'height_energy')\n",
Expand Down Expand Up @@ -419,7 +416,7 @@
"\n",
"# Get the path of variables.py within the aviary package\n",
"file_path = av.get_path('variable_info/variables.py')\n",
"glue_variable('aviary/variable_info/variables.py', md_code=True)\n",
"glue_variable(str(file_path.relative_to(aviary_top_dir)), md_code=True)\n",
"\n",
"# Read and print the first 17 lines of the file\n",
"with open(file_path, 'r') as file:\n",
Expand Down Expand Up @@ -764,6 +761,7 @@
"outputs": [],
"source": [
"# Testing Cell\n",
"import os\n",
"#from aviary.interface.default_phase_info.height_energy import phase_info\n",
"from aviary.interface.utils.check_phase_info import check_phase_info, HEIGHT_ENERGY, TWO_DEGREES_OF_FREEDOM\n",
"from aviary.utils.doctape import check_value, get_variable_name, get_all_keys\n",
Expand All @@ -772,8 +770,12 @@
"for str_phase_info in str_phase_infos:\n",
" file_path = av.get_path('interface/default_phase_info/' + str_phase_info + '.py')\n",
" # Now the file exists. Glue it.\n",
" glue_variable('aviary/interface/default_phase_info/' + str_phase_info + '.py', md_code=True)\n",
" glue_variable('default_phase_info/' + str_phase_info + '.py', md_code=True)\n",
" file_path = file_path.relative_to(aviary_top_dir)\n",
" glue_variable(str(file_path), md_code=True)\n",
" # remove \"aviary/interface\" from file_path\n",
" parts = os.path.normpath(file_path).split(os.sep)\n",
" file_path = os.sep.join(parts[2:])\n",
" glue_variable(str(file_path), md_code=True)\n",
"\n",
"glue_variable(get_variable_name(HEIGHT_ENERGY), md_code=True)\n",
"glue_variable(get_variable_name(TWO_DEGREES_OF_FREEDOM), md_code=True)\n",
Expand Down
59 changes: 37 additions & 22 deletions aviary/docs/getting_started/onboarding_level2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@
"outputs": [],
"source": [
"# Testing Cell\n",
"import os\n",
"import inspect\n",
"import aviary.api as av\n",
"from aviary.api import Dynamic, Mission\n",
"from aviary.interface.methods_for_level1 import run_aviary\n",
"from aviary.utils.doctape import glue_variable, glue_keys, get_variable_name\n",
"\n",
"glue_variable('interface/methods_for_level1.py', md_code=True)\n",
"glue_variable('methods_for_level1.py', md_code=True)\n",
"glue_variable('run_aviary()', md_code=True)\n",
"aviary_top_dir = av.get_path('docs').parent\n",
"file_path = av.get_path('interface/methods_for_level1.py').relative_to(aviary_top_dir)\n",
"glue_variable(str(file_path), md_code=True)\n",
"glue_variable(os.path.basename(file_path), md_code=True)\n",
"\n",
"glue_variable(get_variable_name(run_aviary)+'()', md_code=True)\n",
"AviaryValues = av.AviaryValues\n",
"glue_variable('AviaryValues', f'{AviaryValues=}'.split('=')[0], md_code=True)\n",
"glue_variable(get_variable_name(AviaryValues), md_code=True)\n",
"\n",
"# glue all argument of function run_aviary()\n",
"sigs = inspect.signature(run_aviary)\n",
Expand All @@ -45,7 +49,7 @@
"\n",
"glue_keys(dict(av.ProblemType.__members__))\n",
"ProblemType = av.ProblemType\n",
"glue_variable('ProblemType', f'{ProblemType=}'.split('=')[0], md_code=True)\n",
"glue_variable(get_variable_name(ProblemType), md_code=True)\n",
"\n",
"glue_variable(get_variable_name(Mission.Objectives.FUEL), md_code=True)\n",
"glue_variable(get_variable_name(Mission.Objectives.RANGE), md_code=True)\n",
Expand Down Expand Up @@ -75,16 +79,21 @@
"source": [
"# Testing Cell\n",
"import aviary.api as av\n",
"from aviary.utils.functions import get_path\n",
"from aviary.utils.doctape import glue_variable, run_command_no_file_error\n",
"command = 'aviary run_mission models/test_aircraft/aircraft_for_bench_GwGm.csv --max_iter 0 --optimizer IPOPT'\n",
"\n",
"file_path = 'models/test_aircraft/aircraft_for_bench_GwGm.csv'\n",
"get_path(file_path)\n",
"command = 'aviary run_mission ' + file_path\n",
"glue_variable(command, md_code=True)\n",
"command += ' --max_iter 0 --optimizer IPOPT'\n",
"run_command_no_file_error(command)\n",
"\n",
"glue_variable('aviary run_mission models/test_aircraft/aircraft_for_bench_GwGm.csv', md_code=True)\n",
"glue_variable('aircraft_for_bench_GwGm.csv', md_code=True)\n",
"glue_variable('aircraft_for_bench_GwGm', md_code=True)\n",
"glue_variable(os.path.basename(file_path), md_code=True)\n",
"glue_variable(get_path(file_path).stem, md_code=True)\n",
"\n",
"phase_info_path = av.get_path('interface/default_phase_info/two_dof.py')\n",
"glue_variable('interface/default_phase_info/two_dof.py', md_code=True)"
"phase_info_path = av.get_path('interface/default_phase_info/two_dof.py').relative_to(aviary_top_dir)\n",
"glue_variable(str(phase_info_path), md_code=True)"
]
},
{
Expand Down Expand Up @@ -148,7 +157,9 @@
" objectives = dummy_prob.model._responses.keys()\n",
" check_contains(obj, objectives)\n",
"\n",
"glue_variable('methods_for_level2.py', md_code=True)\n",
"file_path = 'aviary/interface/methods_for_level2.py'\n",
"file_path = os.path.basename(file_path)\n",
"glue_variable(file_path, md_code=True)\n",
"\n",
"# Get all functions of class AviaryProblem\n",
"methods = inspect.getmembers(AviaryProblem, predicate=inspect.isfunction)\n",
Expand Down Expand Up @@ -330,8 +341,8 @@
"source": [
"# Testing Cell\n",
"AnalysisScheme = av.AnalysisScheme\n",
"glue_variable(f'{AnalysisScheme.COLLOCATION=}'.split('=')[0], md_code=True)\n",
"glue_variable(f'{AnalysisScheme.SHOOTING=}'.split('=')[0], md_code=True)\n",
"glue_variable(get_variable_name(AnalysisScheme.COLLOCATION), md_code=True)\n",
"glue_variable(get_variable_name(AnalysisScheme.SHOOTING), md_code=True)\n",
"glue_variable('COLLOCATION', av.AnalysisScheme.COLLOCATION.name, md_code=True)\n",
"glue_variable('SHOOTING', av.AnalysisScheme.SHOOTING.name, md_code=True)"
]
Expand Down Expand Up @@ -412,18 +423,23 @@
"\n",
"from aviary.utils.functions import get_model\n",
"filename = 'aircraft_for_bench_GwGm.csv'\n",
"# read 'aircraft:engine:data_file' from .csv file\n",
"turbofan_file = 'models/engines/turbofan_23k_1.deck'\n",
"data_var_name = 'aircraft:engine:data_file' # read its value from .csv file\n",
"with open(get_model(filename)) as f_in:\n",
" lines = f_in.readlines()\n",
" n = len(lines)\n",
" for idx in range(n):\n",
" sLine = lines[idx]\n",
" if 'aircraft:engine:data_file' in sLine:\n",
" check_value(sLine.strip(), 'aircraft:engine:data_file,models/engines/turbofan_23k_1.deck,unitless')\n",
" if data_var_name in sLine:\n",
" check_value(sLine.strip(), 'aircraft:engine:data_file,'+turbofan_file+',unitless')\n",
" s ='```\\n'\n",
" s += sLine.strip()\n",
" glue_variable('models/engines/turbofan_23k_1.deck,unitless', md_code=True)\n",
" glue_variable(turbofan_file, md_code=True)\n",
" glue_variable('engine_data_file_line', s, md_code=False)\n",
" data = s.split(',')\n",
" data_var_value = data[1]\n",
" data_var_units = data[2]\n",
" glue_variable('models/engines/turbofan_28k.deck,unitless', data[1]+data[2], md_code=False)\n",
" break"
]
},
Expand Down Expand Up @@ -482,13 +498,12 @@
"\n",
"Aircraft.Engine.DATA_FILE;\n",
"EngineModel\n",
"glue_variable('EngineModel', md_code=True)\n",
"glue_variable(get_variable_name(EngineModel), md_code=True)\n",
"\n",
"# build the top rows of turbofan_28k.deck from that file\n",
"file_path = get_path('models/engines/turbofan_28k.deck')\n",
"df = pd.read_csv(file_path, nrows=5, skiprows=2, header=0)\n",
"glue('top_rows_of_engine_deck', df)\n",
"glue_variable('models/engines/turbofan_28k.deck,unitless', md_code=False)\n"
"glue('top_rows_of_engine_deck', df)\n"
]
},
{
Expand Down Expand Up @@ -1272,7 +1287,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
8 changes: 6 additions & 2 deletions aviary/docs/getting_started/onboarding_level3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
"from aviary.interface.methods_for_level2 import AviaryProblem\n",
"from aviary.utils.doctape import glue_variable\n",
"\n",
"glue_variable('aviary/interface/methods_for_level2.py', md_code=True)\n",
"aviary_top_dir = av.get_path('docs').parent.parent\n",
"\n",
"file_path = 'interface/methods_for_level2.py'\n",
"file_path = av.get_path(file_path).relative_to(aviary_top_dir)\n",
"glue_variable(str(file_path), md_code=True)\n",
"glue_variable('solved_2DOF', av.EquationsOfMotion.SOLVED_2DOF.value, md_code=True)\n",
"\n",
"# Get all functions of class AviaryProblem\n",
Expand Down Expand Up @@ -762,7 +766,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 6b3b6c3

Please sign in to comment.