unilab.utils.sim2sim

Cross-backend sim2sim contract snapshot and resolution.

Functions

extract_contract_snapshot(full_cfg)

Extract the contract fields from a resolved training config keyed by dotted path.

policy_load_dim_guard(*[, env_obs_dim, ...])

Re-raise a tensor shape mismatch during checkpoint load as a sim2sim diagnostic.

resolve_sim2sim_config(source_run_dir, ...)

Validate a target play config against the source training contract.

Exceptions

CrossBackendIncompatibleError

Raised when a target play config diverges from the source training contract.

exception unilab.utils.sim2sim.CrossBackendIncompatibleError[source]

Bases: RuntimeError

Raised when a target play config diverges from the source training contract.

unilab.utils.sim2sim.extract_contract_snapshot(full_cfg)[source]

Extract the contract fields from a resolved training config keyed by dotted path.

Parameters:

full_cfg (DictConfig)

Return type:

dict[str, Any]

unilab.utils.sim2sim.resolve_sim2sim_config(source_run_dir, target_cfg, *, algo_name=None, strict=True)[source]

Validate a target play config against the source training contract.

Returns None if source_run_dir is None (an explicit “no source run” play); otherwise returns target_cfg unchanged (never mutated). Raises CrossBackendIncompatibleError under strict when any DENYLIST field differs, including asymmetric presence for ENV_STRUCTURAL_DENYLIST paths. A source run whose contract snapshot is missing, malformed, or uses keys outside the current schema fails closed with the same error regardless of strict.

Parameters:
Return type:

DictConfig | None

unilab.utils.sim2sim.policy_load_dim_guard(*, env_obs_dim=None, env_action_dim=None, algo_name=None)[source]

Re-raise a tensor shape mismatch during checkpoint load as a sim2sim diagnostic.

Non-matching errors propagate unchanged, so a valid load is never blocked.

Parameters:
Return type:

Iterator[None]