{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Run your first MESA HMS-HMS binary simulation with POSYDON" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you haven't done it already, export all the relevan POSYDON and MESA enviroment variables.\n", "\n", "Tip: create a file called `.bash_posydon` with the following content:\n", "```bash\n", "export PATH_TO_POSYDON=/srv/beegfs/scratch/shares/astro/posydon/simone/documentation/POSYDON/\n", "export PATH_TO_POSYDON_DATA=/srv/beegfs/scratch/shares/astro/posydon/POSYDON_GRIDS_v2/POSYDON_data/230914/\n", "\n", "export MESA_DIR=/srv/beegfs/scratch/shares/astro/posydon/software/mesa-r11701-posydon-v2-fiximplicit\n", "export OMP_NUM_THREADS=4\n", "export MESASDK_ROOT=/srv/beegfs/scratch/shares/astro/posydon/software/mesasdk-r11701\n", "source $MESASDK_ROOT/bin/mesasdk_init.sh\n", "```\n", "so that every time you open a new terminal you can just run:\n", "```bash\n", "source .bash_posydon\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you haven't done it already, please download the `development` branch of the `POSYDON-MESA-INLISTS` submodule. This is the branch that contains the simulation properties of all POSYDON MESA grids." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating the Initialization File for the POSYDON MESA Submission Script" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From the submodule, you can now copy in your working directory the API ini file configuration of HMS-HMS binaries: `$PATH_TO_POSYDON/grid_params/POSYDON-MESA-INLISTS/r11701/running_scripts/HMS-HMS_yggdrasil.ini`. \n", "\n", "For each grid we support two ini file configured to the Northwestern and UNIGE HPC clusters." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'./HMS-HMS_yggdrasil.ini'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "import shutil\n", "from posydon.config import PATH_TO_POSYDON\n", "\n", "path_to_ini = os.path.join(PATH_TO_POSYDON, \"grid_params/POSYDON-MESA-INLISTS/r11701/running_scripts/HMS-HMS_yggdrasil.ini\")\n", "shutil.copyfile(path_to_ini, './HMS-HMS_yggdrasil.ini')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Open the file and edit the following parameters:\n", "- `user=your_username`\n", "- `account=your_account`\n", "- `email=your_email`\n", "- `posydon_github_root=your_path_to_POSYDON`\n", "\n", "The `scanrio` parameter of the ini file is where the magic happens. This parameter let's us decide which simulation we want to run. The syntax is the following:\n", "- the first argument is the name of the submodule `posydon` which points to the POSYDON-MESA-INLISTS submodule (other options are avaialble, e.g. `user` which points to a private submodule)\n", "- the second argument is the name of the branch and commit of the submodule we want to use connected by a dash `-`. In this case we want to use the `development` branch of the submodule and it's latest commit, so we write `development-c4f90ce2d93595f66751011d2002fc3ab3d090ec`\n", "- the third argument is the name of the simulation grid we want to run, in this case we want to run a HMS-HMS grid. The name of the grid is `HMS-HMS`.\n", "\n", "To summarize, you should have `scenario = ['posydon', 'development-c4f90ce2d93595f66751011d2002fc3ab3d090ec', 'HMS-HMS']`\n", "\n", "The `zams_file` points to the ZAMS model used to generate the HMS stars in the binary system. POSYDON v2.0.0 supports 8 different metallicities, here we use the default value that points to the 0.1Zsun POSYDON MESA ZAMS model `$PATH_TO_POSYDON/grid_params/POSYDON-MESA-INLISTS/r11701/ZAMS_models/zams_z1.42m3_y0.2511.data`\n", "\n", "The last parameter of this file is `grid` and points to the `csv` file containing the initial coditions of the grid. In this case we want to run a `HMS-HMS` grid consisting of one system, so we keep `grid = grid_test.csv` and generate such file specifying the metallicity, the two star masses and the initial orbital period." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Craeting the Initial Simulation Points CSV File" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note: a notebook showing you how all the grid points of v2.0.0 are generated is available in the `POSYDON-MESA-INLISTS` submodule at `$PATH_TO_POSYDON/grid_params/POSYDON-MESA-INLISTS/r11701/running_scripts/parameter_space_v2/create_csv.ipynb`" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import csv\n", "import numpy as np\n", "import pandas as pd\n", "\n", "with open('./grid_test.csv', 'w', newline='') as file:\n", " writer = csv.writer(file)\n", " writer.writerow(['initial_z','Zbase','m1','m2','initial_period_in_days'])\n", " writer.writerow([0.00142, 0.00142, 30., 21., 10.])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You should now have the following files in your working directory:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1_hms_hms.ipynb grid_test.csv\tHMS-HMS_yggdrasil.ini\n" ] } ], "source": [ "!ls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's now use the magic of POSYDON to set up the MESA simulation. In your termianal run\n", "\n", "```bash\n", "posydon-setup-grid --grid-type fixed --inifile HMS-HMS_yggdrasil.ini --submission-type slurm\n", "```\n", "\n", "The following files will be created:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1_hms_hms.ipynb grid_test.csv\t\tmk\t\t\t\tstar1\n", "binary\t\t HMS-HMS_yggdrasil.ini\tslurm_job_array_grid_submit.sh\tstar2\n" ] } ], "source": [ "!ls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running the MESA Model and Exploring the Simulaiton Output" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You are now ready to submit the simulation to the cluster with the following command:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Submitted batch job 28453658\n" ] } ], "source": [ "!sbatch slurm_job_array_grid_submit.sh" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)\n", " 28453658_[0] private-a mesa_gri bavera PD 0:00 1 (Priority)\n" ] } ], "source": [ "!squeue -u bavera" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After the job is finished, we can check the output files:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1_hms_hms.ipynb\n", "binary\n", "grid_test.csv\n", "HMS-HMS_yggdrasil.ini\n", "mesa_grid.28453658_0.out\n", "mk\n", "slurm_job_array_grid_submit.sh\n", "star1\n", "star2\n", "Zbase_0.0014_m1_30.0000_m2_21.0000_initial_z_1.4200e-03_initial_period_in_days_1.0000e+01_grid_index_0\n" ] } ], "source": [ "!ls" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "binary_history_columns.list inlist_grid_points\n", "binary_history.data\t inlist_grid_star1_binary_controls\n", "final_star1.mod\t\t inlist_grid_star2_binary_controls\n", "final_star2.mod\t\t LOGS1\n", "history_columns.list\t LOGS2\n", "initial_star1.mod\t out.txt\n", "initial_star2.mod\t profile_columns.list\n", "inlist\t\t\t tmp.hdf5\n" ] } ], "source": [ "!ls Zbase_0.0014_m1_30.0000_m2_21.0000_initial_z_1.4200e-03_initial_period_in_days_1.0000e+01_grid_index_0" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", " read /srv/beegfs/scratch/shares/astro/posydon/simone/documentation/running_mesa/running_1_hms_hms/binary/inlist_project\n", " read inlist_grid_points\n", " version_number 11701\n", " read inlist_grid_star1_binary_controls\n", " set_eos_PC_parameters\n", " mass_fraction_limit_for_PC 1.0000000000000000D-03\n", " logRho1_PC_limit 2.9990000000000001D+00\n", " logRho2_PC_limit 2.7999999999999998D+00\n", " log_Gamma_all_HELM 1.0000000000000000D+00\n", " log_Gamma_all_PC 1.3010299956000000D+00\n", " PC_Gamma_start_crystal 1.5000000000000000D+02\n", " PC_Gamma_full_crystal 1.7500000000000000D+02\n", " PC_min_Z 9.9900000000000000D-01\n", " change rates preference to 2\n", " set_initial_age 0.0000000000000000D+00\n", " set_initial_model_number 0\n", " change to \"approx21.net\"\n", " number of species 21\n", " new_rotation_flag T\n", " new_surface_rotation_v 0 0.0000000000000000D+00 0.0000000000000000D+00\n", " net name approx21.net\n", " rotation_flag T\n", " species\n", " 1 neut \n", " 2 h1 \n", " 3 prot \n", " 4 he3 \n", " 5 he4 \n", " 6 c12 \n", " 7 n14 \n", " 8 o16 \n", " 9 ne20 \n", " 10 mg24 \n", " 11 si28 \n", " 12 s32 \n", " 13 ar36 \n", " 14 ca40 \n", " 15 ti44 \n", " 16 cr48 \n", " 17 cr56 \n", " 18 fe52 \n", " 19 fe54 \n", " 20 fe56 \n", " 21 ni56 \n", "\n", " kappa_file_prefix gs98\n", " kappa_lowT_prefix lowT_fa05_gs98\n", " OMP_NUM_THREADS 4\n", "\n", "\n", "\n", "\n", " read inlist_grid_star2_binary_controls\n", " set_eos_PC_parameters\n", " mass_fraction_limit_for_PC 1.0000000000000000D-03\n", " logRho1_PC_limit 2.9990000000000001D+00\n", " logRho2_PC_limit 2.7999999999999998D+00\n", " log_Gamma_all_HELM 1.0000000000000000D+00\n", " log_Gamma_all_PC 1.3010299956000000D+00\n", " PC_Gamma_start_crystal 1.5000000000000000D+02\n", " PC_Gamma_full_crystal 1.7500000000000000D+02\n", " PC_min_Z 9.9900000000000000D-01\n", " change rates preference to 2\n", " set_initial_age 0.0000000000000000D+00\n", " set_initial_model_number 0\n", " change to \"approx21.net\"\n", " number of species 21\n", " new_rotation_flag T\n", " new_surface_rotation_v 0 0.0000000000000000D+00 0.0000000000000000D+00\n", " net name approx21.net\n", " rotation_flag T\n", " species\n", " 1 neut \n", " 2 h1 \n", " 3 prot \n", " 4 he3 \n", " 5 he4 \n", " 6 c12 \n", " 7 n14 \n", " 8 o16 \n", " 9 ne20 \n", " 10 mg24 \n", " 11 si28 \n", " 12 s32 \n", " 13 ar36 \n", " 14 ca40 \n", " 15 ti44 \n", " 16 cr48 \n", " 17 cr56 \n", " 18 fe52 \n", " 19 fe54 \n", " 20 fe56 \n", " 21 ni56 \n", "\n", " kappa_file_prefix gs98\n", " kappa_lowT_prefix lowT_fa05_gs98\n", " OMP_NUM_THREADS 4\n", "\n", "\n", "\n", "\n", "\n", " m2 2.1000000000000000D+01\n", " m1 3.0000000000000000D+01\n", " initial_period_in_days 1.0000000000000000D+01\n", " initial_separation_in_Rsun 7.2417496333000003D+01\n", " jdot_multiplier 1.0000000000000000D+00\n", " fr 1.0000000000000000D-02\n", "\n", "\n", "\n", " The binary terminal output contains the following information\n", "\n", " 'step' is the number of steps since the start of the run,\n", " 'lg_dt' is log10 timestep in years,\n", " 'age_yr' is the simulated years since the start run,\n", " 'M1+M2' is the total mass of the system (Msun),\n", " 'M1' is the mass of the primary (Msun)\n", " 'M2' is the mass of the secondary (Msun)\n", " 'separ' is the semi-major axis of the orbit (Rsun),\n", " 'R1' is the radius of the primary (Rsun)\n", " 'R2' is the radius of the secondary (Rsun)\n", " 'Porb' is the orbital period (days),\n", " 'P1' is the rotation period of star 1 (days, zero if not modeling rotation),\n", " 'P2' is the rotation period of star 2 (days, zero if not modeling rotation),\n", " 'e' orbital eccentricity,\n", " 'dot_e' time derivative of e (1/yr),\n", " 'Eorb' orbital energy G*M1*M2/2*separation (ergs),\n", " 'M2/M1' mass ratio,\n", " 'vorb1' orbital velocity of star 1 (km/s),\n", " 'vorb2' orbital velocity of star 2 (km/s),\n", " 'pm_i' index of star evolved as point mass, zero if both stars are modeled,\n", " 'RL1' Roche lobe radius of star 1 (Rsun),\n", " 'Rl2' Roche lobe radius of star 2 (Rsun),\n", " 'donor_i' index of star taken as donor,\n", " 'RL_gap1' (R1-Rl1)/Rl1,\n", " 'RL_gap2' (R2-Rl2)/Rl2,\n", " 'dot_Mmt', mass transfer rate (Msun/yr),\n", " 'dot_M1', time derivative for the mass of star 1 (Msun/yr),\n", " 'dot_M2', time derivative for the mass of star 2 (Msun/yr),\n", " 'eff', mass transfer efficiency, computed as -dot_M2/dot_M1 (zero if dot_M1=0),\n", " 'dot_Medd', Eddington accretion rate (Msun/yr),\n", " 'L_acc', accretion luminosity when accreting to a point mass (ergs/s),\n", " 'Jorb', orbital angular momentum (g*cm^2/s)\n", " 'spin1', spin angular momentum of star 1 (g*cm^2/s),\n", " 'spin2', spin angular momentum of star 2 (g*cm^2/s),\n", " 'dot_J', time derivative of Jorb (g*cm^2/s^2),\n", " 'dot_Jgr', time derivative of Jorb due to gravitational waves (g*cm^2/s^2),\n", " 'dot_Jml', time derivative of Jorb due to mass loss (g*cm^2/s^2),\n", " 'dot_Jmb', time derivative of Jorb due to magnetic braking (g*cm^2/s^2),\n", " 'dot_Jls', time derivative of Jorb due to spin-orbit coupling (g*cm^2/s^2),\n", " 'rlo_iters', number of iterations for implicit calculation of mass transfer,\n", "\n", " All this and more can be saved in binary_history.data during the run.\n", " num_steps_to_relax_rotation 50\n", " relax to omega: wanted-current, current, wanted 1 7.2722052166430393D-06 0.0000000000000000D+00 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 2 7.1239371671217664D-06 1.4826804952127298D-07 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 3 6.9775031537422630D-06 2.9470206290077610D-07 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 4 6.8325228134160023D-06 4.3968240322703724D-07 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 5 6.6880335934326623D-06 5.8417162321037739D-07 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 6 6.5429720944820478D-06 7.2923312216099155D-07 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 7 6.3960414376057951D-06 8.7616377903724423D-07 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 8 6.2481185101766360D-06 1.0240867064664032D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 9 6.0988144371784416D-06 1.1733907794645978D-06 7.2722052166430393D-06\n", " 10 7.649681 4.541E+04 5.083637 5.083787 30.000000 30.000000 0.746765 0.000508 0.251100 0.747141 -6.159624 2598 0\n", " 3.021836 0.768039 0.749893 -23.011309 3.935137 -99.000000 0.000000 0.251795 0.000441 0.001420 0.251427 0.009963 3 0\n", " 2.3543E+03 16.667399 5.081908 1.622938 4.361599 -8.707435 0.000000 0.000004 0.000133 0.000071 1.432E-03 0.000E+00 max increase\n", "\n", " relax to omega: wanted-current, current, wanted 10 5.9494923842667907D-06 1.3227128323762491D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 11 5.8047902383525235D-06 1.4674149782905158D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 12 5.6656472219130140D-06 1.6065579947300258D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 13 5.5253850379006039D-06 1.7468201787424357D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 14 5.3813998139082310D-06 1.8908054027348084D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 15 5.2360332812183832D-06 2.0361719354246558D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 16 5.0905569484589031D-06 2.1816482681841367D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 17 4.9451036922867509D-06 2.3271015243562889D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 18 4.7996593421142631D-06 2.4725458745287766D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 19 4.6542152662843934D-06 2.6179899503586464D-06 7.2722052166430393D-06\n", " 20 7.648797 4.525E+04 5.069089 5.069239 30.000000 30.000000 0.746765 0.000508 0.251100 0.747141 -6.164975 2613 0\n", " 6.032136 0.764405 0.746596 -23.057888 3.920548 -99.000000 0.000000 0.251795 0.000441 0.001420 0.251427 0.009955 2 0\n", " 2.1539E+06 16.663052 5.069239 1.607921 4.359365 -8.704639 0.000000 0.000004 0.000133 0.000071 1.432E-03 0.000E+00 max increase\n", "\n", " relax to omega: wanted-current, current, wanted 20 4.5087711728839026D-06 2.7634340437591372D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 21 4.3633267819036798D-06 2.9088784347393599D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 22 4.2178823225008446D-06 3.0543228941421948D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 23 4.0724377789053992D-06 3.1997674377376405D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 24 3.9269931252400189D-06 3.3452120914030209D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 25 3.7815483288686108D-06 3.4906568877744285D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 26 3.6361034654341649D-06 3.6361017512088744D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 27 3.4906587737615971D-06 3.7815464428814422D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 28 3.3452144110082463D-06 3.9269908056347930D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 29 3.1997702456217982D-06 4.0724349710212411D-06 7.2722052166430393D-06\n", " 30 7.648797 4.525E+04 5.069078 5.069228 30.000000 30.000000 0.746765 0.000508 0.251100 0.747141 -6.164960 2610 0\n", " 9.042435 0.764409 0.746606 -23.057923 3.920536 -99.000000 0.000000 0.251795 0.000441 0.001420 0.251427 0.009955 2 0\n", " 2.2053E+09 16.663054 5.069228 1.607910 4.359335 -8.704658 0.000000 0.000004 0.000133 0.000071 1.432E-03 0.000E+00 max increase\n", "\n", " relax to omega: wanted-current, current, wanted 30 3.0543261335993711D-06 4.2178790830436683D-06 7.2722052166430393D-06\n", " relax to omega: wanted-current, current, wanted 31 2.9088820289801618D-06 4.3633231876628776D-06 7.2722052166430393D-06\n" ] } ], "source": [ "!head -n 200 Zbase_0.0014_m1_30.0000_m2_21.0000_initial_z_1.4200e-03_initial_period_in_days_1.0000e+01_grid_index_0/out.txt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Congratulation, you now know how to harvast the power of POSYDON to run a grid of simulations on a supercomputer!" ] } ], "metadata": { "kernelspec": { "display_name": "posydon_env", "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.11.5" } }, "nbformat": 4, "nbformat_minor": 2 }