Skip to content

Commit

Permalink
nb
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Oct 14, 2024
1 parent 5ed84eb commit fbc7d78
Showing 1 changed file with 50 additions and 19 deletions.
69 changes: 50 additions & 19 deletions examples/parpeamici/steadystate/parpeExampleSteadystateBasic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,33 @@
"\n",
"Once parPE has been built with support for different optimizers, selecting a different optimizer is quite easy.\n",
"\n",
"(This part of the example requires a parPE build with `PARPE_ENABLE_CERES=ON`)"
"This part of the example requires a parPE build with `PARPE_ENABLE_CERES=ON`. We can check the available optimizers like this:"
]
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "!{example_binary_dir}/example_steadystate_multi -h"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"import subprocess\n",
"import re\n",
"\n",
"result = subprocess.run(\n",
" [f'{example_binary_dir}/example_steadystate_multi', '-h'],\n",
" capture_output=True,\n",
" text=True\n",
")\n",
"ceres_enabled = False\n",
"if result.returncode == 0:\n",
" ceres_enabled = re.search(r'OPTIMIZER_CERES.*enabled', result.stdout) is not None"
]
},
{
Expand Down Expand Up @@ -993,16 +1019,19 @@
}
],
"source": [
"# copy input file from above example\n",
"example_data_ceres = f'{example_data_dir}/example_data_ceres.h5'\n",
"!cp {example_data_dir}/example_data.h5 {example_data_ceres}\n",
"if ceres_enabled:\n",
" # copy input file from above example\n",
" example_data_ceres = f'{example_data_dir}/example_data_ceres.h5'\n",
" !cp {example_data_dir}/example_data.h5 {example_data_ceres}\n",
"\n",
"# Change optimizer to CERES\n",
"# NOTE: For this moment, optimizers are inconveniently selected based on numeric values, 0 is Ipopt, 1 is Ceres.\n",
"!{optimization_options_py} {example_data_ceres} -s optimizer 1\n",
" # Change optimizer to CERES\n",
" # NOTE: For this moment, optimizers are inconveniently selected based on numeric values, 0 is Ipopt, 1 is Ceres.\n",
" !{optimization_options_py} {example_data_ceres} -s optimizer 1\n",
"\n",
"# Run optimization\n",
"!PARPE_NO_DEBUG=1 {mpiexec} {example_binary_dir}/example_steadystate_multi -o deletemeceres/ {example_data_ceres} --mpi"
" # Run optimization\n",
" !PARPE_NO_DEBUG=1 {mpiexec} {example_binary_dir}/example_steadystate_multi -o deletemeceres/ {example_data_ceres} --mpi\n",
"else:\n",
" print('Ceres optimizer not enabled in this build')"
]
},
{
Expand All @@ -1024,14 +1053,15 @@
}
],
"source": [
"ceres_optimization_result_filename = 'deletemeceres/_rank00000.h5'\n",
"trajectories_ceres = parpe.getCostTrajectories(ceres_optimization_result_filename)\n",
"#print(repr(trajectories))\n",
"ax = parpe.plotting.plotCostTrajectory(trajectories_ipopt, log=False);\n",
"parpe.plotting.plotCostTrajectory(trajectories_ceres, log=False, ax=ax);\n",
"ax.autoscale(True)\n",
"ax.legend(['Ipopt', 'Ceres'])\n",
"ax.set_title('Convergence Ipopt vs. Ceres');"
"if ceres_enabled:\n",
" ceres_optimization_result_filename = 'deletemeceres/_rank00000.h5'\n",
" trajectories_ceres = parpe.getCostTrajectories(ceres_optimization_result_filename)\n",
" #print(repr(trajectories))\n",
" ax = parpe.plotting.plotCostTrajectory(trajectories_ipopt, log=False);\n",
" parpe.plotting.plotCostTrajectory(trajectories_ceres, log=False, ax=ax);\n",
" ax.autoscale(True)\n",
" ax.legend(['Ipopt', 'Ceres'])\n",
" ax.set_title('Convergence Ipopt vs. Ceres');"
]
},
{
Expand Down Expand Up @@ -1060,7 +1090,8 @@
}
],
"source": [
"parpe.compare_optimization_results_to_true_parameters(ceres_optimization_result_filename)"
"if ceres_enabled:\n",
" parpe.compare_optimization_results_to_true_parameters(ceres_optimization_result_filename)"
]
},
{
Expand Down Expand Up @@ -1110,4 +1141,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}

0 comments on commit fbc7d78

Please sign in to comment.