posydon.CLI.popsyn

posydon.CLI.popsyn.check

Module for checking the status of a population synthesis run.

posydon.CLI.popsyn.check.analyze_missing_batch_logs(run_folder, str_met, missing_indices)[source]

Analyze log files for missing batches to determine failure reasons.

Parameters:
  • run_folder (str) – Path to the run folder

  • str_met (str) – String representation of metallicity

  • missing_indices (set) – Set of missing batch indices

posydon.CLI.popsyn.check.check_batch(run_folder, metallicity, batch_folder_name)[source]

Check batch files for a specific metallicity when the population file is missing.

Parameters:
  • run_folder (str) – Path to the folder where the population run is located

  • metallicity (float) – Metallicity to check

  • batch_folder_name (str) – Name of the folder containing batch files

Returns:

Dictionary with batch information including: - status: str (‘complete’, ‘incomplete’, ‘folder_missing’, etc.) - expected_count: int or None - found_count: int - metallicity: float - batch_folder: str - missing_indices: set or None

Return type:

dict

posydon.CLI.popsyn.check.check_binary_counts(run_folder, metallicities, expected_count)[source]

Check if each population file has the expected number of binaries.

Parameters:
  • run_folder (str) – Path to the folder where the population run is located

  • metallicities (list of floats) – List of metallicities to check in solar units

  • expected_count (int) – Expected number of binaries per file

Returns:

  • bool – True if all counts match, False otherwise

  • dict – Dictionary with metallicity as key and binary count as value

posydon.CLI.popsyn.check.check_popsyn_function(args)[source]

Function to check the status of a population run.

Parameters:

args (argparse.Namespace) – The arguments passed to the function

posydon.CLI.popsyn.check.check_population_files(run_folder, metallicities)[source]

Check if all merged population files exist.

Parameters:
  • run_folder (str) – Path to the folder where the population run is located

  • metallicities (list of floats) – List of metallicities to check in solar units

Returns:

  • bool – True if all files exist, False otherwise

  • dict – Dictionary with metallicity as key and existence status as value

posydon.CLI.popsyn.check.check_run_status(run_folder, metallicities, number_of_binaries)[source]

Check whether the population files exist and if they have the expected number of binary counts.

Parameters:
  • run_folder (str) – Path to the run folder

  • metallicities (list) – List of metallicities to check

  • number_of_binaries (int) – Expected number of binaries

Returns:

(files_exist, counts_match, file_status)

Return type:

tuple

posydon.CLI.popsyn.check.find_missing_batch_indices(batch_folder, expected_count)[source]

Find which batch indices are missing.

Parameters:
  • batch_folder (str) – Path to the batch folder

  • expected_count (int) – Expected number of batches

Returns:

Set of missing batch indices

Return type:

set

posydon.CLI.popsyn.check.get_batches_status(run_folder, missing_files, synpop_params)[source]

Get the status of batch files for missing populations.

Parameters:
  • run_folder (str) – Path to the run folder

  • missing_files (dict) – Dictionary of metallicities with missing files

  • synpop_params (dict) – Population synthesis parameters

Returns:

Batch status information for each metallicity

Return type:

dict

posydon.CLI.popsyn.check.get_binary_params(ini_file)[source]

Read the binary population parameters from the INI file

Parameters:

ini_file (str) – The path to the INI file

Returns:

  • int – The number of metallicities

  • int – The number of binaries

  • list of floats – The list of metallicities in solar units

  • dict – The dictionary of population synthesis parameters from the INI file

posydon.CLI.popsyn.check.get_expected_batch_count(run_folder, str_met)[source]

Parse SLURM script to get expected batch count.

Parameters:
  • run_folder (str) – Path to the run folder

  • str_met (str) – String representation of metallicity

Returns:

Expected batch count, or None if not found

Return type:

int or None

posydon.CLI.popsyn.check.get_ini_file(args)[source]

Find and select the INI file for the population synthesis run.

Parameters:

args (argparse.Namespace) – Command line arguments that needs to containing the run_folder path.

Returns:

Path to the selected INI file.

Return type:

str

Raises:

FileNotFoundError – If no INI file is found in the run folder.

posydon.CLI.popsyn.check.get_run_configuration(args)[source]

Get and validate the run configuration from the run folder.

Parameters:

args (argparse.Namespace) – Arguments containing run_folder path

Returns:

(ini_file, num_metallicities, number_of_binaries, metallicities, synpop_params)

Return type:

tuple

Raises:

FileNotFoundError – If folder validation or INI file retrieval fails

posydon.CLI.popsyn.check.get_user_confirmation(prompt, valid_yes=None, valid_no=None)[source]

Get user confirmation with validation.

Parameters:
  • prompt (str) – The prompt to show the user

  • valid_yes (list, optional) – List of strings considered as “yes” (default: [‘yes’, ‘y’])

  • valid_no (list, optional) – List of strings considered as “no” (default: [‘no’, ‘n’])

Returns:

True if user confirmed, False otherwise

Return type:

bool

posydon.CLI.popsyn.check.handle_batches_complete(args, missing_files, batch_status)[source]

Handle the case where all batch files are complete.

Parameters:
  • args (argparse.Namespace) – Command line arguments

  • missing_files (dict) – Dictionary of metallicities with missing files

  • batch_status (dict) – Batch status information

Returns:

True if merge jobs were handled (resubmitted or user declined), False if batches incomplete

Return type:

bool

posydon.CLI.popsyn.check.print_batch_status(str_met, expected_count, actual_count, missing_indices)[source]

Print the batch comparison status.

Parameters:
  • str_met (str) – String representation of metallicity

  • expected_count (int or None) – Expected number of batches

  • actual_count (int) – Actual number of batches found

  • missing_indices (set) – Set of missing batch indices

Returns:

Status string: ‘unknown_expected_count’, ‘incomplete’, ‘complete’, or ‘extra_files’

Return type:

str

posydon.CLI.popsyn.check.read_batch_log_file(log_file_path, batch_index, str_met, jobID)[source]

Read and analyze a batch log file to determine failure reason.

Parameters:
  • log_file_path (str) – Path to the log file

  • batch_index (int) – Index of the batch being analyzed

  • str_met (str) – String representation of the metallicity

  • jobID (int) – SLURM job ID

Returns:

Prints the analysis results directly

Return type:

None

posydon.CLI.popsyn.check.select_job_id(run_folder, str_met)[source]

Find and select a job ID from available log files.

Parameters:
  • run_folder (str) – Path to the run folder

  • str_met (str) – String representation of metallicity

Returns:

Selected job ID, or None if no logs found

Return type:

int or None

posydon.CLI.popsyn.check.submit_slurm_job(script_path)[source]

Submit a SLURM job and handle errors.

Parameters:
  • script_path (str) – Path to the SLURM script to submit

  • description (str, optional) – Description of the job for error messages

Returns:

True if submission succeeded, False otherwise

Return type:

bool

posydon.CLI.popsyn.check.validate_run_folder(run_folder)[source]

Validate that the run folder exists and is not empty.

Parameters:

run_folder (str) – Path to the run folder to validate

posydon.CLI.popsyn.setup

Utility functions for POSYDON population synthesis command line interface.

posydon.CLI.popsyn.setup.check_SN_MODEL_validity(ini_file, verbose_on_fail=True)[source]

Checks if the step_SN model is valid for this script

Parameters:
  • ini_file (str) – the path to the ini file

  • verbose_on_fail (bool (default: True)) – if True rerun the model selection with verbose mode if this failed

Returns:

True if the model is valid or use_interp_values=False, False otherwise

Return type:

bool

posydon.CLI.popsyn.setup.setup_popsyn_function(args)[source]

Function to setup the population synthesis run

Parameters:

args (argparse.Namespace) – the arguments passed to the function

posydon.CLI.popsyn.setup.validate_ini_file(ini_file)[source]

Validates the ini file for population synthesis

Parameters:

ini_file (str) – the path to the ini file

Raises: