Index
Job management utilities for simulation servers.
Provides sample generation, output handling, and run management utilities adapted from mada-job-management jobkit.
FolderOutputHandler
Bases: BaseOutputHandler
Output handler for writing samples to a folder.
Attributes:
| Name | Type | Description |
|---|---|---|
settings_class |
The settings class for this output handler. |
|
supported_kwargs |
The full set of supported keyword arguments for the |
|
required_kwargs |
The set of required keyword arguments for the |
Methods:
| Name | Description |
|---|---|
write |
Writes samples to a folder structure. |
Source code in src/mada_tools/simulation/simutils/samples/output/folder_output_handler.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
write(samples, parameter_names=None, **kwargs)
Creates a folder structure for each sample, writes the parameters to individual files,
and dumps all RunInstances to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
ndarray
|
A list of samples, where each sample is a list of floats. |
required |
parameter_names
|
List[str] | None
|
List of parameter names. |
None
|
**kwargs
|
Dict[str, Any]
|
Additional keyword arguments for output configuration. |
{}
|
Returns:
| Type | Description |
|---|---|
SampleOutputResult
|
A |
Source code in src/mada_tools/simulation/simutils/samples/output/folder_output_handler.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
LHSampleGenerator
Bases: BaseSampleGenerator
Latin Hypercube Sample generator component.
Attributes:
| Name | Type | Description |
|---|---|---|
settings_class |
The settings class for this output handler. |
|
supported_kwargs |
The full set of supported keyword arguments for the |
|
required_kwargs |
The set of required keyword arguments for the |
Methods:
| Name | Description |
|---|---|
find_missing_required_kwargs |
Validates that all required keyword arguments are present. |
build_settings_from_kwargs |
Validates the keyword arguments and builds the settings object. |
generate |
Generate a list of samples from the provided data. |
Source code in src/mada_tools/simulation/simutils/samples/generation/lhs_sample_generator.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
generate(**kwargs)
Generate a list of samples from the provided data.
This method will convert the keyword arguments into a LHSampleSettings object
for validation and logging purposes. It will then use these settings to generate
samples using the Latin Hypercube Sampling method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Dict[str, Any]
|
Keyword arguments for sample generation. For LHS sampling, this must include: - dims: int, number of dimensions - n_samples: int, number of samples to generate - lower_bounds: List[float], lower bounds for each dimension - upper_bounds: List[float], upper bounds for each dimension - rng: Optional[np.random.Generator], random number generator |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A numpy array of generated samples. |
Source code in src/mada_tools/simulation/simutils/samples/generation/lhs_sample_generator.py
ParameterSampleGenerator
Build concrete parameter rows from mixed parameter specifications.
ParameterSampleGenerator is simulation-agnostic shared infrastructure for
parameterized run generation. It validates the common parameter schema and
expands it into concrete sample rows, while server helpers remain responsible
for translating those rows into simulation-specific runtime inputs such as
command-line arguments, deck variables, environment variables, or staged files.
Attributes:
| Name | Type | Description |
|---|---|---|
allowed_types |
Optional[set[str]]
|
Optional set of server-supported parameter types. When provided, parameter specs using any other type are rejected during parsing. |
continuous_allowed_types |
Optional[set[str]]
|
Optional set of parameter
types allowed to use |
max_exe_parameters |
Optional[int]
|
Optional maximum number of parameters
whose type is exactly |
validate_cli_values |
bool
|
Whether parameters of type exactly |
Methods:
| Name | Description |
|---|---|
__init__ |
Configure generator-level validation constraints. |
generate |
Validate parameter specifications and expand them into concrete sample rows plus reproducibility metadata. |
parse_parameter_specs |
Normalize and validate raw parameter specifications into structured
|
_generate_lhs_rows |
Generate per-row values for |
_generate_grid_rows |
Generate Cartesian-product rows for |
_generate_zip_rows |
Generate grouped rows for |
Source code in src/mada_tools/simulation/simutils/samples/generation/parameter_samples_generator.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
generate(parameters, num_samples=None, seed=None, rng_bit_generator=None)
Validate parameter specifications and generate all run rows.
Continuous and discrete_lhs parameters produce num_samples LHS rows.
Discrete and discrete_random parameters produce Cartesian grid rows. Zip
parameters pair values by index within each zip group, and independent
zip groups are combined as separate dimensions.
The final run matrix is:
grid rows * zip rows * LHS rows
The returned ParameterSampleResult contains ordered sample rows, per-run dictionaries, validated specs, and reproducibility metadata.
Source code in src/mada_tools/simulation/simutils/samples/generation/parameter_samples_generator.py
parse_parameter_specs(parameters)
Validate and normalize structured parameter specifications.
Each non-random, non-zip entry in parameters must use this list form:
[param_type, param_selection, param_values]
discrete_random and zip entries require a fourth value:
[param_type, "discrete_random", param_values, param_num_selections]
[param_type, "zip", param_values, param_zip_group_id]
Parameter names must be non-empty strings. Parameter type and selection
names are normalized to lowercase. param_values must normalize to a
non-empty list. JSON-encoded list strings are accepted as a compatibility
fallback, but callers should prefer passing native lists.
Supported selections are continuous, discrete, discrete_lhs,
discrete_random, and zip. Unsupported selections, invalid bounds,
invalid random counts, unsupported parameter types, and mismatched zip
groups raise built-in Python exceptions.
Source code in src/mada_tools/simulation/simutils/samples/generation/parameter_samples_generator.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
ParameterSampleResult
dataclass
Generated parameter samples and reproducibility metadata.
This dataclass is the main output of ParameterSampleGenerator.generate().
It contains the generated sample table, row-oriented dictionaries for server
helpers, the validated schema used to produce them, and metadata required to
reproduce randomized sampling.
Attributes:
| Name | Type | Description |
|---|---|---|
parameter_names |
List[str]
|
Ordered parameter names defining the column
order for |
samples |
List[List[Any]]
|
Sample table in row-major form. Each inner list
contains values ordered to match |
row_values |
List[Dict[str, Any]]
|
One dictionary per generated run keyed by parameter name. This is typically the most convenient structure for translating sampled values into command lines, deck edits, manifests, or staged input files. |
specs |
List[ParameterSpec]
|
Validated parameter specifications used to generate the sample rows. |
sampling_metadata |
Dict[str, Any]
|
Reproducibility metadata returned from
|
Source code in src/mada_tools/simulation/simutils/samples/generation/parameter_samples_generator.py
ParameterSpec
dataclass
Validated parameter generation specification.
Instances of this dataclass represent one normalized parameter definition after
schema validation. The fields correspond to the shared prompt-facing tuple
shape consumed by ParameterSampleGenerator.parse_parameter_specs().
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Parameter name used in generated rows and output tables. |
parameter_type |
str
|
Server-defined parameter type such as |
selection |
str
|
Shared sampling mode, normalized to lowercase. Supported
modes are |
values |
List[Any]
|
Normalized non-empty list of candidate values or
numeric bounds, depending on |
num_selections |
Optional[int]
|
Number of values to choose without
replacement for |
zip_group |
Optional[int | str]
|
Zip-group identifier used to pair values
by index across related |
Source code in src/mada_tools/simulation/simutils/samples/generation/parameter_samples_generator.py
RunInstance
dataclass
Represents a single instance of a computational run, storing relevant data and metadata associated with the run.
Attributes:
| Name | Type | Description |
|---|---|---|
run_location |
str
|
The directory where the run will be executed. |
id |
str
|
The identifier for a run instance. |
command |
str
|
The executable command to run (optional). |
args |
List[str]
|
The arguments to pass to the command (optional). |
Methods:
| Name | Description |
|---|---|
to_dict |
Converts the RunInstance object into a JSON-serializable dictionary. |
get_command_with_args |
Returns the command and arguments for execution. |
Source code in src/mada_tools/simulation/simutils/models.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
__repr__()
Returns a detailed string representation of the RunInstance object for debugging.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A detailed string representation of the object. |
Source code in src/mada_tools/simulation/simutils/models.py
__str__()
Returns a human-readable string representation of the RunInstance object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string describing the run instance. |
Source code in src/mada_tools/simulation/simutils/models.py
from_dict(data)
classmethod
Creates a RunInstance object from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict
|
Dictionary containing run instance data |
required |
Returns:
| Type | Description |
|---|---|
RunInstance
|
RunInstance object with data from the dictionary |
Source code in src/mada_tools/simulation/simutils/models.py
get_command_with_args()
Returns the command and arguments for execution.
Returns:
| Type | Description |
|---|---|
Tuple[str, List[str]]
|
Tuple[str, List[str]]: The command and its arguments. |
Source code in src/mada_tools/simulation/simutils/models.py
get_run_command()
Constructs the shell command to execute this run instance.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The shell command to execute this run. |
Source code in src/mada_tools/simulation/simutils/models.py
to_dict()
Converts the RunInstance object into a JSON-serializable dictionary.
Returns:
| Type | Description |
|---|---|
Dict
|
A dictionary representation of the RunInstance object. |
Source code in src/mada_tools/simulation/simutils/models.py
SampleOutputResult
dataclass
Represents the result of sample output generation, storing the output path, output type, and optionally the run instances (if necessary).
Attributes:
| Name | Type | Description |
|---|---|---|
output_path |
str
|
The path where the samples are written. For "csv" output, this is the path to the CSV file. For "folder" output, this is the path to the directory. |
output_type |
str
|
The type of output generated (e.g., "csv", "folder"). |
run_instances |
List[RunInstance]
|
A list of RunInstance objects if the output type is "folder". |
Source code in src/mada_tools/simulation/simutils/models.py
__repr__()
Returns a detailed string representation of the SampleOutputResult object for debugging.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A detailed string representation of the object. |
Source code in src/mada_tools/simulation/simutils/models.py
__str__()
Returns a human-readable string representation of the SampleOutputResult object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string describing the sample output result. |
Source code in src/mada_tools/simulation/simutils/models.py
create_sampling_rngs(seed=None, rng_bit_generator='MT19937')
Create independent RNG streams and metadata for parameter sampling.
The returned streams are keyed by sampling mode: lhs, discrete_lhs, and
discrete_random. They are derived from jumped versions of one root bit
generator so each mode is reproducible without sharing mutable RNG state.
seed must be None or a non-negative integer. When seed is None, NumPy
initializes from system entropy and the effective entropy value is recorded
in the metadata. rng_bit_generator may be MT19937, PCG64, PCG64DXSM, or
PHILOX. If omitted, MT19937 is used.
Source code in src/mada_tools/simulation/simutils/samples/generation/parameter_samples_generator.py
get_run_instances(run_instances_json_path)
Reads the run_instances.json file from the specified study directory and converts it into a list of RunInstance objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_instances_json_path
|
str
|
The path to the run_instances.json file. |
required |
Returns:
| Type | Description |
|---|---|
List[RunInstance]
|
A list of RunInstance objects. |
Source code in src/mada_tools/simulation/simutils/utils.py
normalize_cli_value(parameter_name, value)
Normalize a CLI parameter value into argv tokens.
A non-empty string is split with shlex.split so quoted groups are preserved. A non-empty list of non-empty strings is treated as an explicit argv token list. Shell expansion is not performed; variables, globs, redirects, pipes, and command substitutions remain ordinary argv text after splitting.