Experiment

Scripts to perform the experiments

JSON Management

Setup


source

setup_new_experiment

 setup_new_experiment (params:Dict[str,Any], experiments_folder:str,
                       json_file:Optional[str]=None)

Sets up a new experiment by creating a new folder and updating the JSON file with experiment parameters.

Type Default Details
params Dict Dictionary of parameters for the new experiment.
experiments_folder str Path to the folder containing all experiments.
json_file Optional None Optional path to the JSON file tracking experiment parameters.
Returns str The path to the newly created experiment folder.

source

create_experiments_json

 create_experiments_json (parameter_sets, output_file='experiments.json')

*Create an experiments.json file from given parameter sets.

Args: parameter_sets (list): List of dictionaries containing parameters for each experiment. output_file (str): Name of the output JSON file. Defaults to ‘experiments.json’.

Returns: None*

Add Metrics


source

convert_numpy_types

 convert_numpy_types (obj)

Recursively convert numpy types and tensors to native Python types for JSON serialization.


source

add_experiment_metrics

 add_experiment_metrics (experiments_folder:str,
                         params:Optional[Dict[str,Any]]=None,
                         experiment_id:Optional[int]=None,
                         metrics:Optional[Dict[str,Any]]=None,
                         json_file:Optional[str]=None)

Adds metrics to an existing experiment in the JSON file based on the given parameters or ID.

Type Default Details
experiments_folder str Path to the folder containing all experiments.
params Optional None Optional dictionary of parameters identifying the experiment.
experiment_id Optional None Optional ID to identify the experiment.
metrics Optional None Optional dictionary of metrics to be added to the experiment.
json_file Optional None Optional path to the JSON file tracking experiment parameters and metrics.
Returns None

Get Metrics


source

get_experiment_parameters

 get_experiment_parameters (experiments_folder:str, experiment_id:int,
                            json_file:Optional[str]=None)

Retrieves the parameters of an experiment from the JSON file based on the given ID.

Type Default Details
experiments_folder str Path to the folder containing all experiments.
experiment_id int ID to identify the experiment.
json_file Optional None Optional path to the JSON file tracking experiment parameters and metrics.
Returns Dict

Get Data


source

get_experiment_data

 get_experiment_data (experiments_folder:str, experiment_id:int,
                      json_file:Optional[str]=None)

Retrieves all data for an experiment from the JSON file based on the given ID.

Type Default Details
experiments_folder str Path to the folder containing all experiments
experiment_id int ID to identify the experiment
json_file Optional None Optional path to the JSON file tracking experiment data
Returns Dict

source

read_json_to_dataframe

 read_json_to_dataframe (json_path:str)

Reads a JSON file containing experiment results and returns a DataFrame.

Type Details
json_path str Path to the JSON file containing experiment results
Returns DataFrame

Data Management

Get Paths


source

generate_image_paths

 generate_image_paths (folder_prefix:str, unique_ids:list[int],
                       file_suffix:str)

Generates a list of image file paths based on experiment IDs and folder structure.

Type Details
folder_prefix str Base folder path prefix for each experiment
unique_ids list List of experiment IDs
file_suffix str Suffix to append to the generated filenames
Returns list

Get Orbits


source

concatenate_orbits_from_experiment_folder

 concatenate_orbits_from_experiment_folder (experiments_folder:str,
                                            seq_len:int, file_suffix:str='
                                            _generated_orbits')

Concatenates orbit data from multiple experiment folders into a single array.

Type Default Details
experiments_folder str Root folder containing experiment subfolders
seq_len int Expected sequence length of orbit data
file_suffix str _generated_orbits Suffix for orbit data files
Returns ndarray

Get Tables


source

concatenate_csvs_from_experiment_folder

 concatenate_csvs_from_experiment_folder (experiments_folder:str,
                                          file_suffix:str)

Concatenates CSV files from multiple experiment folders into a single DataFrame.

Type Details
experiments_folder str Root folder containing experiment subfolders
file_suffix str Suffix for CSV files to concatenate
Returns DataFrame

Get Orbit and Table


source

concatenate_and_check_orbits_from_experiment_folder

 concatenate_and_check_orbits_from_experiment_folder
                                                      (experiments_folder:
                                                      str, csv_file_name:s
                                                      tr='_refined_orbits_
                                                      df.csv', np_file_nam
                                                      e:str='_refined_orbi
                                                      ts')

Concatenates orbit data from multiple experiment folders and checks for consistency between generated and refined orbits.

Type Default Details
experiments_folder str Root folder containing experiment subfolders
csv_file_name str _refined_orbits_df.csv Suffix for CSV files containing refined orbits
np_file_name str _refined_orbits Suffix for numpy files containing generated orbits
Returns Tuple

Parameters


source

generate_parameter_sets

 generate_parameter_sets (params:Dict[str,Union[Any,List[Any]]],
                          model_specific_params:Dict[str,Dict])

Generates all possible parameter combinations from the given parameter sets and merges them with model-specific parameters.

Type Details
params Dict Dictionary of parameter names and their values/value lists
model_specific_params Dict Dictionary mapping model names to their specific parameters
Returns List

Experiment Execution


source

execute_parameter_notebook

 execute_parameter_notebook (notebook_to_execute:str, output_dir:str,
                             i:int, params:Dict,
                             extra_parameters:Optional[Dict]=None,
                             checkpoint_file:Optional[str]=None)

Executes a Jupyter notebook with given parameters and saves the output. Returns the execution index if successful, None if failed.

Type Default Details
notebook_to_execute str Path to the notebook file to execute
output_dir str Directory to save output notebook
i int Execution index
params Dict Parameters to pass to the notebook
extra_parameters Optional None Additional parameters to merge with params
checkpoint_file Optional None Path to checkpoint file
Returns Optional

source

paralelize_notebook_experiment

 paralelize_notebook_experiment (parameter_sets:List[Dict],
                                 notebook_to_execute:str, output_dir:str,
                                 checkpoint_file:str, max_workers:int=3,
                                 extra_parameters:Optional[Dict]=None)

Executes a Jupyter notebook multiple times in parallel with different parameter sets, tracking progress with checkpoints.

Type Default Details
parameter_sets List List of parameter dictionaries to execute
notebook_to_execute str Path to the notebook file to execute
output_dir str Directory to save execution outputs
checkpoint_file str Path to checkpoint file tracking execution progress
max_workers int 3 Maximum number of parallel workers
extra_parameters Optional None Additional parameters to pass to each execution
Returns None

Functions


source

generate_file_paths

 generate_file_paths (experiment_id:Union[int,str], images_folder:str,
                      experiment_folder:str)

Generate a dictionary of file paths for an experiment.

Type Details
experiment_id Union Unique ID of the experiment
images_folder str Folder path where image files are stored
experiment_folder str Folder path where experiment-related files are stored
Returns Dict

source

prepare_experiment_data

 prepare_experiment_data (params:Dict[str,Any], experiments_folder:str,
                          data_path:str, want_to_discover:bool)

Prepare the experiment data based on the provided parameters and configurations.

Type Details
params Dict Dictionary containing experiment parameters
experiments_folder str Folder where experiments are stored
data_path str Path to the dataset file
want_to_discover bool Flag indicating whether to discover new families or use existing ones
Returns Tuple

source

prepare_and_train_model

 prepare_and_train_model (params:Dict[str,Any], scaled_data:torch.Tensor,
                          experiments_folder:str, experiment_id:int,
                          file_paths:Dict[str,str], want_to_train:bool)

Prepare the model and either train it or load a pre-trained version based on the provided parameters.

Type Details
params Dict Dictionary containing all experiment parameters
scaled_data Tensor Scaled data tensor for training/validation
experiments_folder str Folder where experiments are stored
experiment_id int Unique ID of current experiment
file_paths Dict Dictionary of paths for model/metrics files
want_to_train bool Whether to train model or load pre-trained
Returns Module