Repository navigation
Add a variation build context, a host asset and per-environment build-time records - #1433
Closed
cvolkcvolk wants to merge 25 commits into
Closed
cvolkcvolk wants to merge 25 commits into
cvolkcvolk wants to merge 25 commits into
Conversation
Add VariationBuildContext with the build's num_envs, seed and the variation key, and get_variation_key for the "<asset>.<variation>" key. configure_at_build_time() takes an optional context and the hooks read it through build_context, so the hook signatures stay the same and existing callers without a context keep working. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
VariationBuildContext.make_generator() seeds a CPU generator from the build seed and the variation key, so draws repeat for the same seed, differ between variations and leave the global torch random state alone. ChoiceSampler.sample() accepts the generator. Nothing calls them yet. AssetSelectionVariation uses both in a later PR. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Asset.add_variation() now calls VariationBase.attach(), and the variation exposes the asset as host. A variation can be attached only once. The reference is weak because configclass validation follows attributes without cycle detection. No existing variation reads host or overrides attach. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
A build-time variation can now draw one value per environment by passing env_ids. VariationRecorder stores those values per env, without needing bind_env(), and reports each one for every episode of its env. _make_listener takes a build_time flag that attach() sets for BuildTimeVariationBase; the placement sampler and run-time variations are routed as before. release_episode drops only run-time samples, so each env keeps its build-time value. VariationRecord rejects mixed shared and per-env draws and a second value for an env that already has one, and validates a draw before writing any of it. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Recorded variation replay already rejects per-env draws against a
replayed build-time value ("received per-env ids") and build-time
values that differ between environments ("changes across episodes").
Pin the first, which no test covered, and feed a recording made by a
per-env build-time variation into the second.
Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Recorded variation replay now builds its "<asset>.<variation>" key with the same helper as the builder and the recorder. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
_apply_build_time_variations() gives every enabled variation, build time and run time, a VariationBuildContext with the builder's num_envs and seed and the variation's key. The seed already changes per rebuild and per rank. Existing variations do not read the context, so their behaviour is unchanged. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
cvolkcvolk
force-pushed
the
cvolkcvolk/feature/variation-build-context
branch
from
October 13, 2026 08:26
60034bf to
978c347
Compare
Drop the caller name from the configure_at_build_time context argument, name the subject of the in-place mutation sentence in _apply_build_time_variations, and replace a test comment that referred to the main branch with the reason behind the behaviour. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
VariationRecord used "build-time" for two things: the store for draws without env ids, which run-time variations fill too, and the per-env store of build-time variations. Split record_buildtime_sample into record_shared_sample and record_per_env_build_time_samples, rename the shared store to _shared_sample and the listener flag to is_build_time_variation, so on_sample shows its three routes. The shared-draw assertion now points to env_ids, and the bind_env() assertion says it applies to per-env run-time draws. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The setter now pairs with the host property and follows set_replay_sampler. VariationRecorder.attach(variations) keeps its meaning, so "attach" no longer reads in two directions. The weak-reference comment names the case it guards against: an asset stored in a configclass field, which validation walks without cycle detection. The light variations hold their light strongly and never end up in such a field. The second-host assertion names the asset the variation was being added to, and the add_variation and host docstrings state their preconditions and when host is None. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
BuildTimeVariationBase now gives the whole recipe for a per-env draw: num_envs rows, env_ids, the build-seeded generator and the replay limit, and names host as a way to reach the asset. make_generator says that each call restarts the stream. VariationBuildContext.seed names the builder seed and says what None does. build_context says it stays set until the next configure_at_build_time call, and its assertion tells the caller what to pass instead of naming ArenaEnvBuilder. get_variation_key states the key format instead of listing where the key is used. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Name the test variations after their lifecycle and draw scope (_SharedBuildTimeVariation, _PerEnvBuildTimeVariation, _RunTimeVariation, ...), so a test shows which kind of draw it makes. Split the build-time record tests so each accepted or rejected draw has its own test name, and run the per-env rejections from one starting record so each also checks that nothing was written. Rename the run-time routing test after its behaviour. The replay rejection test now uses the seeded choice variation, so the context seed decides the two per-env values, and its docstring says why the loader rejects them. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Give the context's immutability and its generator seed derivation their own tests, and parametrize the invalid-field cases on the field being broken, so each case shows which check fires. Name the choice sampler tests after ChoiceSampler and say why the global random state is moved. Update the test module docstring to cover the build context and host. The make_generator comment now says why it uses a digest: Python's hash() of a str changes between processes. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
ContextRecordingVariation read like part of the variation recorder. Rename the helpers to PerEnvContextReadingVariation and RunTimeContextReadingVariation, and give the per-env draws their own value, TEST_PER_ENV_VALUE, so it is clear the per-env record holds that variation's draws rather than the sphere radius. Name the env outside the build used for the shared-record check, and say which variation draws the shared value. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Adding one variation instance to a second asset now reports both assets. Also drop "only" from the VariationBase docstring, which now lists host and build_context, write self.build_context consistently in the BuildTimeVariationBase recipe, note that changing the generator seed derivation changes every seeded draw, and drop the Sphinx reference from the test module docstring. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Rename the shared-draw recorder test to say "shared", give the VariationRecord rule tests one test_record_ prefix, and spell the builder test's run-time local like its class. The placement test now uses a bare sampler instead of borrowing a shared build-time variation. The shared-after-per-env rejection test again checks that the rejected draw does not block a later per-env draw, which the combined test covered before it was split. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The None default only let a few tests skip building a context; the builder always passes one. Requiring it leaves one rule: after configure_at_build_time, build_context is set. The reset comment, the "without one" clause and the context-free test variation go away, and the build_context assertion now covers only a read before the first call. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Drop __post_init__: the builder, its only producer, passes values that are already checked where they enter Arena (ArenaEnvBuilderCfg asserts num_envs > 0; argparse and the typed YAML schema make the seed an int). Make seed an int. Production builds always pass ArenaEnvBuilderCfg.seed, and in-order asset selection computes candidate positions from it, so a None seed would only need an assert there. make_generator loses its system-entropy branch. Name the generator tests after the rules they check: the stream depends only on seed and variation_key, and the global random state is left alone. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
host now returns the Asset or fails with a message saying what to do, instead of returning None before the variation is added or after its asset is garbage-collected. Variations that read their asset through host, as asset selection will, need no None check. set_host says it runs before add_variation stores the variation, which an override that rejects a second variation of its kind relies on. The weak-reference comment cites a config that recurses today with a strong reference: an EventTermCfg whose params hold a DROID embodiment (test_embodiment_collision_mesh fails with RecursionError). The add_variation docstring names environment code as a caller too. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
It takes one multi-row sample with env_ids, like its siblings record_runtime_sample and record_shared_sample, so it reads as their per-env build-time counterpart. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
A build-time variation makes one per-env draw for all its environments, as the BuildTimeVariationBase recipe asks, so VariationRecord now rejects any second per-env draw instead of merging a later draw for other environments. The write becomes one assignment after the checks, so the overlap check and the validate-first ordering go away. Drop _has_shared_sample: every reader already treats a None shared sample as "nothing drawn". The sample_for_episode docstring says that VariationRecorder, not the record, keeps per-episode and per-env build-time draws apart. Direct VariationRecord tests no longer pass a cfg that nothing reads. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The _realize_at_build_time docstrings said "bound asset config(s)" and "target configuration" next to the new host. They now say the hooks apply values to asset configs, and the BuildTimeVariationBase recipe asks for one per-env draw and says replay supports only draws without env_ids, instead of the undefined "shared form". Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The per-env build-time test now checks only that each env keeps its value for every episode, also after release_episode, and names the env outside the build. The choice test is renamed after what it adds: each env's episode row holds the chosen item itself. The CPU and every-episode checks it repeated are covered elsewhere. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
set_host built its message through the host property, which now asserts once the first host is garbage-collected, so that case lost the "cannot also be added to" message. It reads the weak reference directly again, and a test covers the case. The garbage-collected host message now has the same form as its neighbours. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Collaborator
Author
|
Closing this in favor of two smaller PRs:
The rest of this PR is not carried over: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pass every enabled variation a
VariationBuildContextwith the build's environment count, seed and variation key, and addmake_generator()for seeded draws that leave the global random state alone. LetVariationRecorderkeep a build-time value per environment, and let a variation reach the asset it was added to throughhost.Why this change?
Asset selection is a build-time variation that seeds its choice from the build seed and installs the chosen asset on the object it was added to. Today a build-time variation cannot do that. It draws from the global torch random state and cannot see the seed. The base class also gives a variation no way to reach the asset it was added to. The light variations get their light through their constructor. Asset selection does not: in the API proposed in #1425 it is built from its candidates and then added to an object, as in
pickup.add_variation(AssetSelectionVariation(...)). Soadd_variationis the only place it can learn which object it belongs to.A build-time variation also cannot give each environment its own value. It cannot see
num_envs, the recorder keeps one shared build-time value, and on main a build-time draw withenv_idsfails during the build because no env is bound to the recorder yet.This PR adds these general pieces and no new variation.
AssetSelectionVariation, in a draft PR stacked on this one, usesset_host()andhost,VariationBuildContext.seed,make_generator()andconfigure_at_build_time(context); it selects one asset for all environments of a build, so it does not use the per-environment records.What changes?
VariationBuildContext(num_envs, seed, variation_key)is a frozen dataclass with three typed fields: the build's environment count,ArenaEnvBuilderCfg.seedand the variation's key.ArenaEnvBuilderbuilds one for each enabled variation, build-time and run-time, and passes it toconfigure_at_build_time(context)as a new required argument._prepare_at_build_timeand_realize_at_build_timekeep their signatures and read it through thebuild_contextproperty, which fails an assertion if read before the firstconfigure_at_build_timecall.VariationBuildContext.make_generator()returns a new CPUtorch.Generatorseeded from the build seed and the variation key. The same seed repeats the draws, each variation gets its own stream, and the global torch random state is neither read nor advanced. Each call starts the stream again, so a variation makes all its draws in a build from one generator. The experiment runner already adds the rebuild index to the seed, so each rebuild draws new values. OnlyChoiceSampler.sample()takes the generator, through a new keyword-onlygeneratorargument.UniformSamplerandBernoulliSamplerstill draw from the global torch random state.get_variation_key(asset_name, variation_name)builds the"<asset>.<variation>"key in the builder, the recorder and replay.VariationRecorderkeeps the per-environment draw of a build-time variation (a draw withenv_idsby aBuildTimeVariationBase) and reports each environment's value for every episode of that environment. It needs nobind_env()for that draw.release_episodefrom Unify placement sampling and replay #1427 still drops only run-time samples, so these values stay. Shared draws and run-time draws are recorded as before.VariationRecord.record_buildtime_sampleis renamed torecord_shared_sample, because it also records run-time draws made withoutenv_ids. A later shared draw replaces the earlier one. The newrecord_per_env_build_time_samplerecords a build-time variation's per-environment draw. A build makes one such draw for all its environments: a second per-environment draw, a mix of shared and per-environment draws, or a draw whose rows do not match itsenv_idsfails an assertion and records nothing.Asset.add_variation()now calls the newVariationBase.set_host(asset)before it stores the variation, sovariation.hostreturns the asset the variation was added to. Subclasses can overrideset_hostto check that asset. Adding a variation to a second asset fails an assertion that names both assets. So does readinghostbefore the variation is added, or after its asset was garbage-collected. The variation holds its host through a weak reference:add_variationgives every variation on every asset this back-reference, and Isaac Lab's configclass validation follows object attributes without cycle detection. With a strong reference,test_embodiment_provides_robot_collision_meshintest_embodiment_collision_mesh.pyfails: it validates anEventTermCfgwhose params hold a DROID embodiment, and validation goes from the embodiment to its camera variations and back through their host references until it raisesRecursionError.Suggested reading order:
variation_base.py,variation_recorder.py,arena_env_builder.py, then the tests.Usage example
Before:
After:
Because this variation passes
env_ids,VariationRecorderkeepschosen[i]for every episode of environment i. The same seed, variation key, environment count and candidates give the samechosen. No variation in this PR applies per-environment values to the scene.Validation
pre-commit run --all-filespasses on the current head, with main merged in.test_variation_base.py,test_variation_recorder.py,test_build_time_variations.py,test_choice_samplers.pyandtest_recorded_variation_samples.py) and the two builder tests that main changed or added next to this PR's builder change (test_arena_env_graph_conversion.py, andtest_placement_after_build_time_variations.pyfrom Run placement after build-time variations #1452) pass in the Arena container: 78 passed.test_legacy_graph_builder_keeps_namespace_inside_graph_compatibilityfails when its file runs alone, on main as well, because nothing has started Isaac Sim yet (No module named 'omni.usd'). It passes in the full phase run.Timeout (0:02:00)!insimulation_app.close()after all their tests passed.test_embodiment_provides_robot_collision_meshandtest_variation_with_a_host_does_not_create_a_config_validation_cycleintest_variation_base.pyfail withRecursionError./tmpthat all Arena containers on that machine share, so robot and object USDs loaded without their prims.pytetwild), the multi-env mimic test hits its 900 s timeout, and the last five bring-ups intest_kitchen_bench_yaml_env.pyfail with "Failed to get rigid body transforms from backend".test_variation_base.pycovers the build context and key, the generator andhost;test_choice_samplers.pythegeneratorargument ofChoiceSampler;test_variation_recorder.pythe per-environment records, their rejection rules and replay rejection with a real per-environment recording (test_replay_rejects_a_recording_with_per_env_build_time_values);test_recorded_variation_samples.pyreplay rejection of per-environment draws; andtest_builder_passes_build_context_and_records_per_env_samplesintest_build_time_variations.pythe builder for both variation lifecycles.