Index
The generation package provides functionality for generating samples.
This is designed to be easily extended with additional sample generation strategies.
Modules:
| Name | Description |
|---|---|
base_sample_generator |
Defines the base class for sample generation. |
lhs_sample_generator |
Provides a concrete implementation for generating LHS samples. |
parameter_samples_generator |
Provides structured mixed parameter sample generation. |
sample_generator_factory |
Provides a factory class for creating sample generators. |
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
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
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.