{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Advanced Configuration" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial demonstrates alternative ways of configuring `wakeflow` models not covered in the _Quickstart Tutorial_, including from files, dictionaries, and altering developer parameters. It is assumed that you have read the _Quickstart Tutorial_." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configuring model from .yaml file" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the _Quickstart Tutorial_, running our model generated a `.yaml` file with all of the model parameters we used:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m\u001b[34m0.5Mj\u001b[m\u001b[m quickstart_tutorial_config.yaml\n" ] } ], "source": [ "!ls HD_163296/quickstart_tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you would like to configure `wakeflow` from a `.yaml` file, the easiest way is to modify one that is created automatically by `wakeflow` such as the above, to ensure you get the formatting correct. Note that this configuration method requires that you specify ALL `wakeflow` parameters, it will NOT set unprovided values to default." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this example, we will simply run an identical model to the tutorial using the above `.yaml` parameter file. We initialise the model as usual:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Model initialised.\n" ] } ], "source": [ "from wakeflow import WakeflowModel\n", "\n", "hd163_model = WakeflowModel()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we use the `configure_from_file` method to configure using `quickstart_tutorial_config.yaml` instead of using the usual `configure` method:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Model configured.\n", "Model configuration read from file: HD_163296/quickstart_tutorial/quickstart_tutorial_config.yaml\n" ] } ], "source": [ "file_path = \"HD_163296/quickstart_tutorial/quickstart_tutorial_config.yaml\"\n", "\n", "hd163_model.configure_from_file(file_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And we are done. Running the model then proceeds as usual by the `run` method." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configuring model from dictionary" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "You may also configure `wakeflow` using dictionaries, which is the easiest option if you are wanting to do a parameter space scan. This is because it is easy to iteratively create dictionaries with different model parameters. We can do this easily using the usual `configure` method and some `Python` magic. First, let's assemble our dictionary. We can include as many or few `wakeflow` parameters as we want, those unspecified will be left as default values.\n", "\n", "Lets create the dictionary. We need to ensure that each key corresponds exactly to an argument of the `configure` method. For the sake of the example we will stick to specifying only a few parameters and leaving the rest as default:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "my_model_config = dict(\n", " name = \"advanced_config_tutorial\",\n", " system = \"HD_163296\",\n", " m_star = 1.9,\n", " m_planet = 0.1\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we initialise our model as ususal:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Model initialised.\n" ] } ], "source": [ "from wakeflow import WakeflowModel\n", "\n", "hd163_model_2 = WakeflowModel()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And now we give the dictionary to the `configure` method, prepended by two asterisks:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Model configured.\n" ] } ], "source": [ "hd163_model_2.configure(**my_model_config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That's it! Very simple. Again, you could now run this model by using the `run` method." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configuring developer parameters" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Lastly, we cover here how to change the developer and numerical parameters (hereafter referred to as developer parameters). A full list/description of what these parameters are and do is available in the _Reference_ section of the documentation under _Wakeflow Parameters_.\n", "\n", "Please don't change these parameters unless you have a good understanding of how it will effect your results. Some of these options if changed can completely invalidate or break the results. If you are interested in models that do not use the default values of the developer parameters please contact the lead developer Thomas Hilder at Thomas.Hilder@monash.edu to discuss what you are trying to achieve and if it is valid. It is very likely that these parameters do not do quite what you think they do.\n", "\n", "For the reasons described above, these parameters are deliberately a little more obtuse to change. You cannot set them using either the `configure` or the `configure_from_file` methods.\n", "\n", "We can find and change the developer parameters after configuring the model, so let us do that. We stick to the default values for the example:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Model initialised.\n", "Model configured.\n" ] } ], "source": [ "from wakeflow import WakeflowModel\n", "\n", "hd163_model_3 = WakeflowModel()\n", "\n", "hd163_model_3.configure()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we can find all parameters in a dictionary under the `WakeflowModel.model_params` attribute. Printing this:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'name': 'default_results_dir', 'system': 'default_parent_dir', 'm_star': 1.0, 'm_planet': 0.1, 'r_outer': 500, 'r_inner': 100, 'r_planet': 250, 'phi_planet': 0, 'r_ref': None, 'r_c': 0, 'z_max': 3, 'q': 0.25, 'p': 1.0, 'hr': 0.1, 'dens_ref': 1.0, 'cw_rotation': False, 'grid_type': 'cartesian', 'n_x': 400, 'n_y': 400, 'n_r': 200, 'n_phi': 160, 'n_z': 50, 'r_log': False, 'make_midplane_plots': True, 'show_midplane_plots': True, 'dimensionless': False, 'include_planet': True, 'include_linear': True, 'save_perturbations': True, 'save_total': True, 'write_FITS': False, 'run_mcfost': False, 'inclination': -225, 'PA': 45, 'PAp': 45, 'temp_star': 9250, 'distance': 101.5, 'v_max': 3.2, 'n_v': 40, 'adiabatic_index': 1.6666667, 'damping_malpha': 0.0, 'CFL': 0.5, 'scale_box_l': 1.0, 'scale_box_r': 1.0, 'scale_box_ang_t': 1.0, 'scale_box_ang_b': 1.0, 'tf_fac': 1.0, 'show_teta_debug_plots': False, 'box_warp': True, 'use_box_IC': False, 'use_old_vel': False}\n" ] } ], "source": [ "print(hd163_model_3.model_params)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is also a nice and quick way of checking the default parameter values to see if you want to change them, without having to refer to the documentation. The developer parameters of the above are\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Suppose we wish to change `CFL` to a lower value, which has the effect of taking smaller time steps in the Burger's equation solver for the wake propagation. We can do this by just overriding the value in the `model_params` dictionary:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "hd163_model_3.model_params[\"CFL\"] = 0.1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we would simply run the model as usual using the `run` method.\n", "\n", "Changing the developer parameters must occur after calling `configure` or `configure_from_file`, and before calling `run`." ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "2ac3d5d3a4336f34c662130573d1ea696fb4dfcbf6baf7c9925b84262e1f6ae2" } } }, "nbformat": 4, "nbformat_minor": 2 }