Runner
runner
¶
BaseConfig
¶
Bases: MojoBaseModel
n_proc
class-attribute
instance-attribute
¶
n_proc: int = DEFAULT_N_PROC
Number of proccesses to allow.
This value is used to determine how many parallel jobs can be run. It is also used for the discovery of trial status. Using a value of 1 will result in the slowest runtime, but highest reliability.
Important
Be a good citizen. Use a reasonable number if you are working on a shared resource. You are a jerk if you use everything.
resume
class-attribute
instance-attribute
¶
resume: bool = DEFAULT_RESUME
Whether to resume a study if the study already exists.
padding_style
property
¶
padding_style: str
This dynamically defines the padding style for trial numbers. This is helpful to ensure the filesystem consistently sorts the trials.
Examples:
- Suppose you n_trials is 2000 (and the nominal trial_num is 0)
- This method would return 04d
- Trial number 0 maps to 0000
- Trial number 123 maps to 0123
- Trial number 1999 will still map to 1999
MonteCarloConfig
¶
Bases: BaseConfig
n_trial
class-attribute
instance-attribute
¶
n_trial: int = DEFAULT_MC_N_TRIAL
Number of trials to run.
You are able to resume a previous job and modify the number of runs desired by changing this value. A job already in progress will not be dynamically stopped though if you change this value at runtime.
n_proc
class-attribute
instance-attribute
¶
n_proc: int = DEFAULT_N_PROC
Number of proccesses to allow.
This value is used to determine how many parallel jobs can be run. It is also used for the discovery of trial status. Using a value of 1 will result in the slowest runtime, but highest reliability.
Important
Be a good citizen. Use a reasonable number if you are working on a shared resource. You are a jerk if you use everything.
resume
class-attribute
instance-attribute
¶
resume: bool = DEFAULT_RESUME
Whether to resume a study if the study already exists.
padding_style
property
¶
padding_style: str
This dynamically defines the padding style for trial numbers. This is helpful to ensure the filesystem consistently sorts the trials.
Examples:
- Suppose you n_trials is 2000 (and the nominal trial_num is 0)
- This method would return 04d
- Trial number 0 maps to 0000
- Trial number 123 maps to 0123
- Trial number 1999 will still map to 1999
OptimizerConfig
¶
Bases: BaseConfig
n_trial
class-attribute
instance-attribute
¶
n_trial: int = DEFAULT_OP_N_TRIAL
Number of trials to run.
study_name
class-attribute
instance-attribute
¶
study_name: str = DEFAULT_OP_STUDY_NAME
Unique identifier for the Optuna study.
direction
instance-attribute
¶
direction: Literal['minimize', 'maximize']
Whether we want to find the lowest or highest objective value.
timeout
class-attribute
instance-attribute
¶
timeout: float | None = DEFAULT_OP_TIMEOUT
Stop the study after this many seconds, regardless of trial count.
storage
class-attribute
instance-attribute
¶
storage: str | None = DEFAULT_OP_STORAGE
Database URL (e.g., 'sqlite:///study.db') for multi-node persistence.
sampler
class-attribute
instance-attribute
¶
The search algorithm. TPE is generally best for noisy physics.
evals_per_trial
class-attribute
instance-attribute
¶
Number of times to run the sim with different seeds per trial. The average score is returned to Optuna.
Reduces 'lucky' trials in noisy physics.
refine_search_factor
class-attribute
instance-attribute
¶
refine_search_factor: float | None = Field(
default=DEFAULT_OP_REFINE_SEARCH_FACTOR, gt=0, lt=1
)
If set (e.g., 0.5), and resume is True, the Runner will shrink the search space bounds by this factor around the current best trial to focus on local refinement.
Smaller values will more aggressively refine the search space.
prune_failed_trials
class-attribute
instance-attribute
¶
prune_failed_trials: bool = DEFAULT_OP_PRUNE_FAILED_TRIALS
Whether to immediately stop trials that violate physical constraints (e.g., Mujoco instability) to save compute time.
n_proc
class-attribute
instance-attribute
¶
n_proc: int = DEFAULT_N_PROC
Number of proccesses to allow.
This value is used to determine how many parallel jobs can be run. It is also used for the discovery of trial status. Using a value of 1 will result in the slowest runtime, but highest reliability.
Important
Be a good citizen. Use a reasonable number if you are working on a shared resource. You are a jerk if you use everything.
resume
class-attribute
instance-attribute
¶
resume: bool = DEFAULT_RESUME
Whether to resume a study if the study already exists.
padding_style
property
¶
padding_style: str
This dynamically defines the padding style for trial numbers. This is helpful to ensure the filesystem consistently sorts the trials.
Examples:
- Suppose you n_trials is 2000 (and the nominal trial_num is 0)
- This method would return 04d
- Trial number 0 maps to 0000
- Trial number 123 maps to 0123
- Trial number 1999 will still map to 1999
Trial
dataclass
¶
Trial(
trial_num: int,
base_dir: Path,
xml_name: str,
model_config_name: str,
padding_style: str,
)
Handles the lifecycle of a single simulation run.
The Trial object is responsible for the 'dirty work' of a Monte Carlo run: - Creating directories - Writing the MJCF XML - Saving the configuration snapshot - Triggering the physics runtime.
base_dir
instance-attribute
¶
base_dir: Path
Root directory where all simulation trials are stored.
xml_name
instance-attribute
¶
xml_name: str
Filename for the generated MJCF XML (e.g., 'model.xml').
model_config_name
instance-attribute
¶
model_config_name: str
Filename for the serialized MojoModel configuration (e.g., 'config.json').
padding_style
instance-attribute
¶
padding_style: str
Format specifier for directory naming (e.g., '04d').
trial_dir
property
¶
trial_dir: Path
The absolute path to this trial's unique workspace.
Example
If base_dir is './sims' and trial_num is 7 with '03d' padding, this returns './sims/trial_007'.
model_config_path
property
¶
model_config_path: Path
The full path to the JSON configuration file for this trial.
named_value_path
property
¶
named_value_path: Path
The full path to the JSON NamedValue file for this trial.
run
¶
run(
generator: MojoGenerator,
runtime: MojoRuntime | None,
seed: int | None,
overrides: NamedValueDict[NDArray],
gen_args: list[Any],
gen_kwargs: dict[str, Any],
run_args: list[Any],
run_kwargs: dict[str, Any],
) -> tuple[
MojoModel | None,
TrialStatus,
MjModel | None,
MjData | None,
]
Executes the complete simulation pipeline for this trial.
This method coordinates three main phases:
1. Generation: Calls the user-provided generator to build a MojoModel model.
2. Persistence: Creates the workspace and writes the model/config to disk.
3. Execution: Triggers the physics runtime if one is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generator
|
MojoGenerator
|
Function that returns a |
required |
runtime
|
MojoRuntime | None
|
Optional function to run the simulation (MuJoCo). |
required |
seed
|
int | None
|
Seed to use to define the trial. |
required |
overrides
|
NamedValueDict[NDArray]
|
Key-value pairs that override random distributions. |
required |
gen_args
|
list[Any]
|
Positional arguments for the generator. |
required |
gen_kwargs
|
dict[str, Any]
|
Keyword arguments for the generator. |
required |
run_args
|
list[Any]
|
Positional arguments for the runtime. |
required |
run_kwargs
|
dict[str, Any]
|
Keyword arguments for the runtime. |
required |
Returns:
| Type | Description |
|---|---|
tuple[MojoModel | None, TrialStatus, MjModel | None, MjData | None]
|
The |
Source code in src/mujoco_mojo/utils/runner.py
| Python | |
|---|---|
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 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
MojoRunner
dataclass
¶
MojoRunner(
generator: MojoGenerator,
generator_path: str | None = None,
runtime: MojoRuntime | None = DEFAULT_RUNTIME,
runtime_path: str | None = None,
objective: MojoObjective | None = None,
objective_path: str | None = None,
seed: int | None = DEFAULT_SEED,
workdir: Path = DEFAULT_WORKDIR,
model_config_name: str = DEFAULT_MODEL_CONFIG_NAME,
xml_name: str = DEFAULT_XML_NAME,
config: MonteCarloConfig
| OptimizerConfig = MonteCarloConfig(),
gen_args: list[Any] = list(),
gen_kwargs: dict[str, Any] = dict(),
run_args: list[Any] = list(),
run_kwargs: dict[str, Any] = dict(),
)
slurm_trial_id
property
¶
slurm_trial_id: int | None
Returns the current SLURM task ID if running as part of an array job.
run
¶
run(
global_overrides: NamedValueDict[
NDArray
] = NamedValueDict[NDArray](),
clean_workdir: bool = False,
cleanup_delay: int = 10,
execution_mode: ExecutionMode = LOCAL,
trial_nums: list[int] | None = None,
) -> bool
Vectors a job to be either computed locally or to be orchestrated by SLURM.
Source code in src/mujoco_mojo/utils/runner.py
orchestrate_slurm
¶
orchestrate_slurm(
global_overrides: NamedValueDict[NDArray],
trial_nums: list[int] | None = None,
) -> bool
Generates an sbatch script and submits the job array to SLURM for a given config.
Source code in src/mujoco_mojo/utils/runner.py
execute_single_trial
¶
execute_single_trial(
trial_num: int,
seed: int | None,
overrides_payload: dict,
) -> tuple[
MojoModel | None,
TrialStatus,
MjModel | None,
MjData | None,
]
Helper to package a Trial and run it.
Source code in src/mujoco_mojo/utils/runner.py
run_monte_carlo
¶
run_monte_carlo(
global_overrides: NamedValueDict[
NDArray
] = NamedValueDict[NDArray](),
trial_nums: list[int] | None = None,
) -> bool
Orchestrates a Monte Carlo job.
Source code in src/mujoco_mojo/utils/runner.py
| Python | |
|---|---|
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | |
get_slurm_array_string
staticmethod
¶
Collapses [0, 1, 2, 5, 6] into '0-2,5-6' for SLURM.
Source code in src/mujoco_mojo/utils/runner.py
get_slurm_partitions
staticmethod
¶
Queries sinfo for available partitions and identifies the default.
Source code in src/mujoco_mojo/utils/runner.py
normalize_to_mb
staticmethod
¶
Converts SLURM memory strings (e.g., '1000', '1G', '1024M') to integer MB.
Source code in src/mujoco_mojo/utils/runner.py
format_bytes
staticmethod
¶
Scales MB back up to the most readable unit (G, T, etc.).
Source code in src/mujoco_mojo/utils/runner.py
get_slurm_node_mem_limit
staticmethod
¶
Finds the MINIMUM RealMemory limit, normalized to MB.
Source code in src/mujoco_mojo/utils/runner.py
get_slurm_cpu_limit
staticmethod
¶
Finds the minimum of the max allowed CPUs (CPUTot) among nodes in a partition.
Source code in src/mujoco_mojo/utils/runner.py
slurm_time_to_seconds
staticmethod
¶
Converts SLURM time (D-HH:MM:SS or HH:MM:SS) to total seconds.
Source code in src/mujoco_mojo/utils/runner.py
get_slurm_time_limit
staticmethod
¶
Finds the MaxTime limit for a specific partition.
Source code in src/mujoco_mojo/utils/runner.py
get_max_array_size
staticmethod
¶
get_max_array_size() -> int
Queries the global SLURM configuration for MaxArraySize.
Source code in src/mujoco_mojo/utils/runner.py
orchestrate_slurm_monte_carlo
¶
orchestrate_slurm_monte_carlo(
global_overrides: NamedValueDict[
NDArray
] = NamedValueDict[NDArray](),
trial_nums: list[int] | None = None,
) -> bool
Orchestrates a Monte Carlo SLURM submission.
Source code in src/mujoco_mojo/utils/runner.py
| Python | |
|---|---|
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 | |