Simulation Module
- mmpp.simulation.upgrade_log_level(current_level, new_level)[source]
Pomocnicza funkcja do “promowania” poziomu logowania. Zwraca “najgorszy” (najwyższy priorytetem) z podanych. Priorytet: ERROR > WARNING > INFO
- class mmpp.simulation.SimulationManager(main_path, destination_path, prefix)[source]
Bases:
object
- static create_path_if_not_exists(file_path)[source]
Ensure the directory for a given file path exists.
- static verify_or_replace_file(new_file_path, existing_file_path)[source]
Check if a file needs replacing and replace if necessary.
- static find_status_file(path, sim_name, status)[source]
Locate a status file based on its name and type.
- static check_simulation_completion(zarr_path)[source]
Check if a simulation represented by a .zarr directory is complete and return a tuple (is_complete, file_count).
- is_complete: bool
True jeśli spełniony warunek >= 3000 plików w grupie ‘m’ oraz obecny ‘end_time’. False w przeciwnym razie, np. gdy brakuje ‘end_time’, ‘m’ albo jest < 3000 plików.
- file_count: int
Rzeczywista liczba plików (kroków) w grupie ‘m’; 0 w razie błędu lub braku danych.
- submit_python_code(code_to_execute, last_param_name=None, cleanup=False, sbatch=True, check=False, force=False, full_name=False, **kwargs)[source]
Submit a Python simulation based on provided parameters. Zmodyfikowana tak, aby wszystkie komunikaty na końcu łączyć w jeden raport.
- static replace_variables_in_template(file_path, variables)[source]
Replace placeholders in a template file with actual values.
- static raw_code(*args, **kwargs)[source]
Generate the raw code by filling in a template with parameters.
- submit_all_simulations(params, last_param_name, minsim=0, maxsim=None, sbatch=True, cleanup=False, template='template.mx3', check=False, force=False, pairs=False)[source]
Submit all simulations based on parameter combinations.
If pairs=False (default), generates all combinations using itertools.product. If pairs=True, generates paired values (par1[i], par2[i], …) where each parameter must have the same number of values.
- class mmpp.simulation.SimulationSwapper(config_file)[source]
Bases:
object
Klasa do obsługi swapowania symulacji na podstawie plików konfiguracyjnych. Parsuje pliki YAML z parametrami i zarządza wykonaniem symulacji.
- Parameters:
config_file (
str
)
- __init__(config_file)[source]
Inicjalizacja SwappeParsera z plikiem konfiguracyjnym.
- Parameters:
config_file (
str
) – Ścieżka do pliku konfiguracyjnego (YAML)
- get_simulation_manager()[source]
Stwórz instancję SimulationManager na podstawie konfiguracji.
- Return type:
- class mmpp.simulation.TemplateParser(template_path)[source]
Bases:
object
Klasa do parsowania plików template.mx3 i wyciągania parametrów do swapowania.
- Parameters:
template_path (
str
)
- __init__(template_path)[source]
Inicjalizacja parsera z ścieżką do pliku template.
- Parameters:
template_path (
str
) – Ścieżka do pliku template.mx3
Simulation Management
SimulationManager
- class mmpp.simulation.SimulationManager(main_path, destination_path, prefix)[source]
Bases:
object
- static create_path_if_not_exists(file_path)[source]
Ensure the directory for a given file path exists.
- static verify_or_replace_file(new_file_path, existing_file_path)[source]
Check if a file needs replacing and replace if necessary.
- static find_status_file(path, sim_name, status)[source]
Locate a status file based on its name and type.
- static check_simulation_completion(zarr_path)[source]
Check if a simulation represented by a .zarr directory is complete and return a tuple (is_complete, file_count).
- is_complete: bool
True jeśli spełniony warunek >= 3000 plików w grupie ‘m’ oraz obecny ‘end_time’. False w przeciwnym razie, np. gdy brakuje ‘end_time’, ‘m’ albo jest < 3000 plików.
- file_count: int
Rzeczywista liczba plików (kroków) w grupie ‘m’; 0 w razie błędu lub braku danych.
- submit_python_code(code_to_execute, last_param_name=None, cleanup=False, sbatch=True, check=False, force=False, full_name=False, **kwargs)[source]
Submit a Python simulation based on provided parameters. Zmodyfikowana tak, aby wszystkie komunikaty na końcu łączyć w jeden raport.
- static replace_variables_in_template(file_path, variables)[source]
Replace placeholders in a template file with actual values.
- static raw_code(*args, **kwargs)[source]
Generate the raw code by filling in a template with parameters.
- submit_all_simulations(params, last_param_name, minsim=0, maxsim=None, sbatch=True, cleanup=False, template='template.mx3', check=False, force=False, pairs=False)[source]
Submit all simulations based on parameter combinations.
If pairs=False (default), generates all combinations using itertools.product. If pairs=True, generates paired values (par1[i], par2[i], …) where each parameter must have the same number of values.
Usage Examples
Parameter Sweeps
from mmpp.simulation import SimulationManager
import numpy as np
# Initialize simulation manager
manager = SimulationManager(
main_path="/path/to/simulations/",
destination_path="/path/to/results/",
prefix="sweep_v1"
)
# Define parameter space
params = {
"b0": np.linspace(0.0001, 0.01, 10),
"fcut": np.linspace(2.6, 2.8, 20),
}
# Submit all simulations
manager.submit_all_simulations(
params=params,
last_param_name="fcut",
sbatch=True,
template="template.mx3"
)
Paired Parameter Studies
# For paired parameters (not Cartesian product)
params = {
"field": [0.1, 0.2, 0.3],
"freq": [2.0, 2.5, 3.0], # Must have same length
}
manager.submit_all_simulations(
params=params,
last_param_name="freq",
pairs=True # Use paired values instead of product
)