moplayground.learning¶
Connecting the multi-objective trainers to mm.train, and loading trained policies
back. See Training a policy and
Rolling out a policy.
moplayground.learning.training
¶
Functions:
| Name | Description |
|---|---|
setup_morlax |
|
setup_amor |
|
mo_wrapper |
Multi-Objective Wrapper |
setup_morlax
¶
Source code in src/moplayground/learning/training.py
setup_amor
¶
Source code in src/moplayground/learning/training.py
mo_wrapper
¶
mo_wrapper(env: MjxEnv, episode_length: int = 1000, action_repeat: int = 1, randomization_fn=None) -> Wrapper
Multi-Objective Wrapper
Source code in src/moplayground/learning/training.py
moplayground.learning.inference
¶
Functions:
| Name | Description |
|---|---|
get_all_models |
Checkpoint directories in |
get_last_model |
Most recent checkpoint directory in |
load_mo_policy |
Load the latest multi-objective policy in |
load_hypernetworks |
Load MORLAX networks and hypernetwork params from a checkpoint. |
load_hypernetwork_inference_fn |
Loads policy inference function from PPO checkpoint. |
load_amor_networks |
Load AMOR networks + saved (normalizer, policy, value) params. |
load_make_amor_inference_fn |
Load the (call-time-tradeoff) AMOR inference function from a checkpoint. |
get_all_models
¶
Checkpoint directories in run_dir, sorted by training step.
A checkpoint directory is a subdirectory whose name is an integer (the
training step), e.g. 000050032640.
Source code in src/moplayground/learning/inference.py
get_last_model
¶
load_mo_policy
¶
load_mo_policy(algorithm: str, network_params: dict, num_objectives: int, run_dir, tradeoff: ndarray, network_factory=None, deterministic: bool = True)
Load the latest multi-objective policy in run_dir.
Dispatches on algorithm ('morlax' or 'amor'). Returns a 2-arg callable
policy(obs, key) -> (action, extras) with tradeoff baked in, so it
is compatible with mm.eval.rollout_policy and other consumers.
For AMOR specifically, the underlying inference function natively accepts
a tradeoff at call time (so the tradeoff can change per step). To get
that 3-arg form, call :func:load_amor_inference_fn directly instead of
this function.
Source code in src/moplayground/learning/inference.py
load_hypernetworks
¶
load_hypernetworks(network_params: dict, num_objectives: int, run_dir=None, path=None, network_factory=make_morlax_networks, quiet=True) -> tuple[MORLAXNetworks, dict]
Load MORLAX networks and hypernetwork params from a checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_params
|
dict
|
MORLAX network-factory keyword arguments. |
required |
num_objectives
|
int
|
Number of objectives. |
required |
run_dir
|
Run directory; the latest checkpoint in it is used when
|
None
|
|
path
|
Explicit checkpoint directory. Overrides |
None
|
Source code in src/moplayground/learning/inference.py
load_hypernetwork_inference_fn
¶
load_hypernetwork_inference_fn(network_params: dict, num_objectives: int, run_dir=None, path=None, network_factory=make_morlax_networks)
Loads policy inference function from PPO checkpoint.
Source code in src/moplayground/learning/inference.py
load_amor_networks
¶
load_amor_networks(network_params: dict, num_objectives: int, run_dir=None, path=None, network_factory=make_amor_networks, quiet=True) -> tuple
Load AMOR networks + saved (normalizer, policy, value) params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_params
|
dict
|
AMOR network-factory keyword arguments. |
required |
num_objectives
|
int
|
Number of objectives. |
required |
run_dir
|
Run directory; the latest checkpoint in it is used when
|
None
|
|
path
|
Explicit checkpoint directory. Overrides |
None
|
Source code in src/moplayground/learning/inference.py
load_make_amor_inference_fn
¶
load_make_amor_inference_fn(network_params: dict, num_objectives: int, run_dir=None, path=None, network_factory=make_amor_networks)
Load the (call-time-tradeoff) AMOR inference function from a checkpoint.
Returns (amor_inference_fn, saved_params) where amor_inference_fn has
signature (params, deterministic) -> policy(obs, tradeoff, key) and
saved_params is the (normalizer, policy, value) 3-tuple from the
checkpoint.
Source code in src/moplayground/learning/inference.py
moplayground.learning.wrappers
¶
Classes:
| Name | Description |
|---|---|
MultiObjectiveEpisodeWrapper |
Maintains episode step count and sets done at episode end. |
MultiObjectiveEvalWrapper |
Brax env with eval metrics. |
MultiObjectiveEpisodeWrapper
¶
Bases: Wrapper
Maintains episode step count and sets done at episode end.
Methods:
| Name | Description |
|---|---|
reset |
|
step |
|
Attributes:
| Name | Type | Description |
|---|---|---|
episode_length |
|
|
action_repeat |
|
Source code in src/moplayground/learning/wrappers.py
reset
¶
Source code in src/moplayground/learning/wrappers.py
step
¶
Source code in src/moplayground/learning/wrappers.py
MultiObjectiveEvalWrapper
¶
Bases: Wrapper
Brax env with eval metrics.
Methods:
| Name | Description |
|---|---|
reset |
|
step |
|