RSP Workflow

mesalab.rsptools.rsp_inlist_generator.generate_mesa_rsp_inlists(detail_df: DataFrame, mesa_output_base_dir: str, rsp_inlist_template_path: str, rsp_output_subdir: str) list[str][source]

Generates MESA inlist files for RSP simulations, each loading a specific MESA profile from the provided detail_df.

Parameters:
  • detail_df (pd.DataFrame) – DataFrame containing ‘initial_mass’, ‘initial_Z’, ‘model_number’, ‘log_Teff’, ‘log_L’, ‘run_dir_path’, and ‘initial_Y’.

  • mesa_output_base_dir (str) – The root directory where MESA run output folders are. (e.g., ‘output/mesa_runs’) - This parameter is not directly used if RSP is creating a model from scratch based on parameters.

  • rsp_inlist_template_path (str) – Path to the MESA RSP inlist template file.

  • rsp_output_subdir (str) – Base directory for generated MESA RSP runs.

Returns:

A list of paths to the generated MESA RSP inlist files.

Return type:

list[str]

Example

>>> import pandas as pd
>>> import os
>>> from mesalab.rsptools.rsp_inlist_generator import generate_mesa_rsp_inlists
>>>
>>> # 1. Create a mock DataFrame with the required data.
>>> data = {
...     'initial_mass': [1.0, 1.2],
...     'initial_Z': [0.014, 0.003],
...     'model_number': [500, 750],
...     'log_Teff': [3.75, 3.82],
...     'log_L': [1.5, 2.1],
...     'initial_Y': [0.27, 0.28],
...     'run_dir_path': ['/path/to/run1', '/path/to/run2']
... }
>>> detail_df = pd.DataFrame(data)
>>>
>>> # 2. Define your paths. Ensure these directories and files exist on your system.
>>> mesa_out_dir = '/path/to/your/mesa_output'
>>> template_path = '/path/to/your/inlist_rsp_template'
>>> rsp_out_dir = './rsp_inlists'
>>>
>>> # 3. Call the function to generate the inlist files.
>>> generated_inlists = generate_mesa_rsp_inlists(
...     detail_df=detail_df,
...     mesa_output_base_dir=mesa_out_dir,
...     rsp_inlist_template_path=template_path,
...     rsp_output_subdir=rsp_out_dir
... )
>>>
>>> # 4. Check the results.
>>> for inlist in generated_inlists:
...     print(f"Generated: {inlist}")
Generated: ./rsp_inlists/run_1.0MSUN_z0.0140/model0500/inlist_rsp
Generated: ./rsp_inlists/run_1.2MSUN_z0.0030/model0750/inlist_rsp
mesalab.rsptools.rsp_runner.run_mesa_rsp_single(inlist_path: str, mesa_binary_dir: str, num_threads: int, output_dir: str, timeout: int) dict[source]

Runs the MESA RSP module with a single inlist file.

This function executes the MESA ‘star’ module for a single input file, managing the run environment and capturing the result.

Parameters:
  • inlist_path (str) – The full path to the inlist_rsp file.

  • mesa_binary_dir (str) – The directory where the ‘star’ executable is located.

  • num_threads (int) – The number of OpenMP threads to use for this run.

  • output_dir (str) – The dedicated output directory for this specific run. All log files and outputs will be stored here.

  • timeout (int) – The maximum time in seconds the run is allowed to take before being terminated.

Returns:

A dictionary containing the run status (success/failure) and other relevant information.

Return type:

dict

Example

>>> # This example assumes you have a valid MESA installation and the required files.
>>>
>>> import os
>>> from mesalab.rsp_modules import run_mesa_rsp_single
>>>
>>> # 1. Define the paths to your MESA executable and inlist file.
>>> #    Replace these with your actual paths.
>>> mesa_binary_path = "/path/to/your/mesa/star/work"
>>> inlist_file_path = "/path/to/your/inlist_rsp"
>>>
>>> # 2. Define the output directory for this specific run.
>>> output_directory = "./my_single_run_output"
>>>
>>> # 3. Call the function.
>>> result = run_mesa_rsp_single(
...    inlist_path=inlist_file_path,
...    mesa_binary_dir=mesa_binary_path,
...    num_threads=1,
...    output_dir=output_directory
... )
mesalab.rsptools.rsp_runner.run_mesa_rsp_workflow(inlist_paths: list[str], config_data: dict, rsp_output_subdir: str) dict[source]

Runs the MESA RSP workflow on all provided inlist files, in parallel or sequentially.

This function automates the execution of the MESA ‘star’ executable for multiple inlist files, handling parallel processing, output organization, and error logging.

Note: This function requires a working MESA installation with the ‘star’ executable compiled and accessible. It is intended to be called from a main script that handles file generation and configuration loading.

Parameters:
  • inlist_paths (list[str]) – A list of full paths to the generated inlist_rsp files.

  • config_data (dict) – The full configuration object (e.g., addict.Dict) containing all paths and settings, including mesa_binary_dir, enable_rsp_parallel, etc.

  • rsp_output_subdir (str) – The base output directory for all RSP runs.

Returns:

A summary of the run results, including lists of successful, failed,

and timed-out runs.

Return type:

dict

Example

>>> # This example shows how to run the workflow from a main script.
>>> from mesalab.rsp_modules import run_mesa_rsp_workflow
>>> from addict import Dict
>>> import os
>>> # 1. Define your configuration. This would typically be loaded from a YAML file.
>>> config = Dict({
...     'general_settings': {
...         'mesa_binary_dir': '/path/to/your/mesa/star/work'
...     },
...     'rsp_workflow': {
...         'enable_rsp_parallel': True,
...         'max_concurrent_rsp_runs': 4,
...         'num_rsp_threads': 1
...     }
... })
>>> # 2. Create a list of inlist files you want to run.
>>> #    (This step assumes you have already generated them.)
>>> my_inlist_files = [
...     './my_inlists/inlist_rsp_run1',
...     './my_inlists/inlist_rsp_run2',
...     './my_inlists/inlist_rsp_run3'
... ]
>>> # 3. Define the output directory for your RSP runs.
>>> output_dir = './my_rsp_results'
>>> os.makedirs(output_dir, exist_ok=True)
>>> # 4. Run the workflow.
>>> results = run_mesa_rsp_workflow(
...     inlist_paths=my_inlist_files,
...     config_data=config,
...     rsp_output_subdir=output_dir
... )
>>> # 5. Check the results.
>>> if not results['failed'] and not results['timeout']:
...     print("All RSP runs were successful!")
>>> else:
...     print("Some RSP runs failed or timed out. Check the logs for details.")