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 | None,
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 | None
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, MjState | 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, MjState | None]
|
The |
Source code in src/mujoco_mojo/utils/runner.py
| Python | |
|---|---|
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 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
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
| None = 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, MjState | None]
Helper to package a Trial and run it.
The model and state are live in-process objects; callers that need to cross a ProcessPoolExecutor boundary (i.e. parallel MC) must use _execute_trial_subprocess instead, which drops the non-picklable objects before the result is serialized back.
Returns (mojo_model, trial_status, state).
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 | |
|---|---|
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
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 | |
|---|---|
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 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 | |