embodichain.lab.task_program.integrations.scene_expansion#
This integration evaluates an ordered mapping of physical environment rows to
SceneVariant proposals through the
existing batched Task Program and Gym demonstration path. An injected host
prepares the selected rows together; a row-addressed validator supplies measured
task evidence. The rows share an explicit or environment-configured Task Program.
Host-owned settled state identity and explicit initial-state checks. |
|
Independent scene preparation, program execution, and measured outcome. |
|
Prepare selected scenes and execute their valid rows on one World clock. |
Preparation and execution boundary#
The preparation callback applies or restores the candidate, settles physics,
checks the actual initial state, saves its initial-state artifact, and refreshes
recording observations and affected bindings. It returns a mapping containing
exactly the requested rows, each with a ScenePreparationResult holding the
actual initial-state ID and nonempty ValidationResult checks. Rejecting an
initial state prevents execution of that row while valid peers can proceed.
Physical preparation and workspace screening are supplied by the caller at
this layer; the fixed-candidate API does not instantiate a simulation host.
For existing-rigid-object layouts, use
SimulationSceneExpansionHost
with task-specific initial checks and measured acceptance.
For valid initial states, execute_scene_variants creates a fresh bridge using
the canonical EmbodiedEnv.create_demo_segments(task_program=...) path and
passes the resulting segments through execute_demo_episode with explicit
active_env_ids. Physics still advances the whole World. Handwritten
segment-planner overrides do not replace the selected Task Program. The normal
Gym executor owns env.step(). Automatic resets are suspended throughout
preparation, execution, and measurement. Explicit resets during either callback
discard recording buffers while the attempt remains in progress; the attempt’s
persistence guard survives replacement of episode metadata by those resets.
Measured acceptance and persistence#
SceneVariantEpisodeResult preserves initial checks, program execution, and
measured task checks independently. program_completed records normal
completion of the selected canonical bridge, and program_completion_mask
owns its row-specific acceptance snapshot; env_id identifies the physical
row. execution retains the complete batch result, while program_success
uses only that row’s completion and success flags. The execution entry point leaves the
mask empty when the bridge did not complete. program_success requires that
bridge evidence and a successful demo execution. Generic Gym success from a
legacy task override or early termination does not establish program completion.
Acceptance requires valid initial checks, program_success, and passing
measured task checks. Empty checks, unavailable evidence, a failed program, or
failed measured goals cannot accept the scene. A completed program with
projected effects still needs physical evidence from the measured validator.
The attempt’s proposal, actual initial-state identity, and validation evidence
are published per row under the existing episode_context source
scene_expansion/task_program.
Preparation provenance is owned and recursively immutable; to_metadata()
returns JSON-compatible values, including the canonical bridge completion
evidence. While an attempt is active, reset cannot persist dataset, camera, or
trajectory buffers, even after a preparation or measurement reset replaces the
pending metadata. Failed or interrupted recordings remain ineligible for these
writes, including explicit commit-row requests and failed-episode recording.
Rejection belongs to the recording buffers until reset actually discards them.
Replacing episode annotations or starting another demo does not clear it. A
later successful attempt without that reset can return accepted=True but
cannot make the earlier rejected recording eligible to save. Discard the
recording before retrying, using env.reset(options={"save_data": False}).
The integration performs one attempt, propagates configuration and host errors,
and creates no retry scheduler or persistence session. The caller closes the
normal transaction by resetting the selected rows and supplying accepted row IDs
as commit_env_ids. Failed rows remain ineligible even when save is requested.
An accepted execution is not confirmation that a dataset write succeeded.
Injecting a host and measured validator#
The following helper accepts the fixed source from the scene proposal example. Both callbacks are required application implementations, so the example does not substitute a constant passing check for physical evidence:
from collections.abc import Callable, Mapping
from embodichain.lab.gym.envs.embodied_env import EmbodiedEnv
from embodichain.lab.sim.motion.expansion import ValidationResult
from embodichain.lab.sim.scene.expansion import FixedSceneCandidateSource, SceneVariant
from embodichain.lab.task_program.integrations.scene_expansion import (
ScenePreparationResult,
SceneVariantEpisodeResult,
execute_scene_variants,
)
def collect_fixed_variants(
env: EmbodiedEnv,
source: FixedSceneCandidateSource,
*,
prepare_scene: Callable[
[Mapping[int, SceneVariant]], Mapping[int, ScenePreparationResult]
],
measured_validator: Callable[[int], ValidationResult],
) -> list[SceneVariantEpisodeResult]:
results = []
for variant in source:
result = execute_scene_variants(
env,
{0: variant},
prepare_scene=prepare_scene,
measured_validator=measured_validator,
episode_index=variant.ordinal,
attempt_id=variant.ordinal,
)[0]
results.append(result)
env.reset(options={"reset_ids": [0], "save_data": result.accepted})
return results
The environment must already have its Task Program integration configured.
prepare_scene begins each candidate from a clean recording boundary using
reset with save_data=False when needed, including after any rejected or
interrupted attempt. It captures state and reseeds observations only after
settling and refreshing bindings. The measured callback reads terminal state
and any required intermediate-event evidence; it returns ValidationResult
rather than an arbitrary truthy value. Applications retain their own bounded
retry policy and exceptional-attempt cleanup.
Public interfaces#
- class embodichain.lab.task_program.integrations.scene_expansion.ScenePreparationResult[source]#
Host-owned settled state identity and explicit initial-state checks.
- Parameters:
initial_state_id (
str) – Identity of the actual state saved by the host after preparation and settling. This is distinct from the proposal ID.validation (
ValidationResult) – Required initial-state checks based on the actual scene. Empty or unavailable checks reject the candidate.metadata (
Mapping[str,object]) – JSON-compatible provenance such as scene/integration versions and the identity of the host’s saved initial-state artifact.
Methods:
__init__(initial_state_id, validation[, ...])- __init__(initial_state_id, validation, metadata=<factory>)#
- class embodichain.lab.task_program.integrations.scene_expansion.SceneVariantEpisodeResult[source]#
Independent scene preparation, program execution, and measured outcome.
- Parameters:
env_id (
int) – Physical environment row represented by this result.variant (
SceneVariant) – Exact proposed scene evaluated by this attempt.preparation (
ScenePreparationResult) – Actual settled initial-state identity and checks.execution (
DemoEpisodeResult|None) – Existing demo executor result, absent for an invalid initial scene. Program completion alone does not imply acceptance.measured_validation (
ValidationResult|None) – Required measured task checks after execution, absent when initial-state validation prevented execution.program_completed (
bool) – Whether the selected canonical bridge completed all segment lifecycles normally. Generic Gym success is insufficient.program_completion_mask (
tuple[bool,...]) – Owned single-row bridge acceptance snapshot, available only after normal program completion.
Methods:
__init__(variant, preparation, execution, ...)Export JSON-compatible proposal, initial-state, and outcome evidence.
Attributes:
Return whether initial checks, execution, and measured checks passed.
Return whether the canonical program and demo execution succeeded.
- __init__(variant, preparation, execution, measured_validation, program_completed=False, program_completion_mask=(), *, env_id)#
- property accepted: bool#
Return whether initial checks, execution, and measured checks passed.
- Returns:
Acceptance for this scene and attempt only; persistence is owned by the existing caller and is not implied by this result.
- property program_success: bool#
Return whether the canonical program and demo execution succeeded.
- Returns:
Success only with normal bridge completion and its acceptance mask.
- embodichain.lab.task_program.integrations.scene_expansion.execute_scene_variants(env, variants, *, prepare_scene, measured_validator, task_program=None, episode_index=0, attempt_id=0, execution_cfg=None, nominal_source_factory=None, expansion_profile=None, expansion_candidate_index=0, plan_transform_factory=None, trace_actions=False)[source]#
Prepare selected scenes and execute their valid rows on one World clock.
The canonical Task Program bridge is created after preparation. Its segments use the ordinary batched demo executor with an explicit active-row mask. Initial failures prevent execution of those rows; program completion and measured acceptance are checked independently for every remaining row.
This entry performs no persistence. The caller resets to commit accepted rows or discard rejected buffers. Checks block saving during preparation, execution and measurement; rejection stays attached to its row until reset. Physics advances the entire World, including unassigned rows.
- Parameters:
env (
EmbodiedEnv) – Initialized EmbodiedEnv or wrapper owning the physical World.variants (
Mapping[int,SceneVariant]) – Nonempty ordered mapping from physical row to scene proposal.prepare_scene (
Callable[[Mapping[int,SceneVariant]],Mapping[int,ScenePreparationResult]]) – Batch callback returning exactly one preparation result per requested row, after state writes and any whole-World settling.measured_validator (
Callable[[int],ValidationResult]) – Required post-execution checks for one physical row.task_program (
TaskProgramCfg|CompiledTaskProgram|None) – Shared config/compiled program, or the configured program.episode_index (
int) – Logical index used by the existing demo recording path.attempt_id (
int) – Collection attempt index.execution_cfg (
DemoExecutionCfg|None) – Existing batched demo persistence layout settings.nominal_source_factory (
TaskProgramNominalSourceFactory|None) – Optional episode-scoped external motion binding.expansion_profile (
CombinedExpansionProfile|None) – Optional episode-owned combined motion profile.expansion_candidate_index (
int) – Shared combined recipe index.plan_transform_factory (
TaskProgramPlanTransformFactory|None) – Optional trusted plan transform; mutually exclusive with an expansion profile.trace_actions (
bool) – Enable source tracing, qualified only for a B=1 World.
- Return type:
Mapping[int,SceneVariantEpisodeResult]- Returns:
Immutable row mapping with separate initial, program and measured outcomes. A rejected row does not invalidate a successful peer.
- Raises:
ValueError – For malformed selections/configuration before preparation.
TypeError – For invalid callbacks, candidates or result contracts.
RuntimeError – For another active scene attempt on the same World.
Exception – Runtime failures reject all requested buffers before propagating.