isaaclab.cloner#
Submodules
Segment-boundary-safe prim-path primitives for the cloner. |
|
Queries over the prototype/clone relation a |
Classes
|
Description of a single replication layout, consumed by |
|
Configuration for environment replication. |
|
Legal clone combination defined by explicitly listing active assets. |
|
Folds |
|
Queue and apply USD replication work for one stage. |
Functions
|
Build a single-source clone plan that targets every env from one source row. |
|
Build a |
|
Build the valid clone-combination variant tensor. |
|
Return the number of spawn variants declared by one spawner configuration. |
|
Create a centered grid of transforms for |
|
Drain |
|
Register |
|
Replicate USD prims to per-environment destinations. |
|
Create inverted collision groups for clones (PhysX only). |
Clone plan#
The ClonePlan value type and the constructors that build one.
A plan is the whole description of a replication layout: which prototypes exist, where each
one is cloned to, and which envs each one populates. It is built once, queried through
query, and executed by replicate().
Three constructors cover the ways a layout is specified:
clone_plan_from_env_0()— every env is a copy of one prototype env.make_clone_plan()— the layout is derived from the scene’s asset cfgs, expanding multi-asset spawners into per-variant prototypes.make_valid_clone_combinations()— restricts which variant combinationsmake_clone_plan()may draw from, weighted per combination.
Classes:
Description of a single replication layout, consumed by |
Functions:
|
Create a centered grid of transforms for |
|
Return the number of spawn variants declared by one spawner configuration. |
|
Build the valid clone-combination variant tensor. |
|
Build a |
|
Build a single-source clone plan that targets every env from one source row. |
- class isaaclab.cloner.clone_plan.ClonePlan[source]#
Bases:
objectDescription of a single replication layout, consumed by
replicate().Attributes:
Source prim paths, one per replication row.
Destination path templates with
"{}"for the env id, one per row.Bool tensor
[len(sources), num_clones];Trueif envjcomes from rowi.Long tensor
[num_clones]of target env ids.Per-env world positions [m], shape
[num_clones, 3], orNone.id(cfg)to the row indices the cfg owns.Methods:
__init__(sources, destinations, clone_mask)- clone_mask: torch.Tensor#
Bool tensor
[len(sources), num_clones];Trueif envjcomes from rowi.
- env_ids: torch.Tensor | None = None#
Long tensor
[num_clones]of target env ids.Optional for plans used only with
iter_sources()orpath_to_source(); required byreplicate().
- positions: torch.Tensor | None = None#
Per-env world positions [m], shape
[num_clones, 3], orNone.
- isaaclab.cloner.clone_plan.grid_transforms(N: int, spacing: float = 1.0, up_axis: str = 'z', device='cpu')[source]#
Create a centered grid of transforms for
Ninstances.Computes
(x, y)coordinates in a roughly square grid centered at the origin with the provided spacing, places the third coordinate according toup_axis, and returns identity orientations. This matches the grid layout used byisaaclab.terrains.TerrainImporterfor consistent environment positioning.- Parameters:
- Returns:
posis a tensor of shape(N, 3)with positions [m].oriis a tensor of shape(N, 4)with identity quaternions in(x, y, z, w).
- Return type:
A tuple
(pos, ori)where
- isaaclab.cloner.clone_plan.num_spawn_variants(spawn_cfg: Any) int[source]#
Return the number of spawn variants declared by one spawner configuration.
MultiAssetSpawnerCfgdeclares one variant per asset configuration andMultiUsdFileCfgone per USD path; every other spawner declares a single variant.- Parameters:
spawn_cfg¶ – Spawner configuration to inspect.
- Returns:
The number of spawn variants the configuration expands into.
- isaaclab.cloner.clone_plan.make_valid_clone_combinations(asset_names: Sequence[str], variant_counts: Sequence[int], clone_combinations: Sequence[InclusionSet] | None = None, device: str = 'cpu', *, all_asset_names: Sequence[str] | None = None) torch.Tensor[source]#
Build the valid clone-combination variant tensor.
Each combination contributes rows in proportion to its weight, split evenly across its spawn variants and interleaved round-robin, so any prefix of the tensor samples every combination.
- Parameters:
asset_names¶ – Clone-planned scene asset names, one per tensor column.
variant_counts¶ – Number of spawn variants per clone-planned asset.
clone_combinations¶ – Legal clone combinations; assets not mentioned by any combination are active in every row.
Noneuses the full cartesian product of variants.device¶ – Torch device for the output tensor. Defaults to
"cpu".all_asset_names¶ – Optional full scene asset-name list; combination entries may reference assets that are not clone-planned.
- Returns:
A
[num_valid_combinations, num_assets]tensor of source variant indices,-1where an asset is absent.- Raises:
ValueError – If the inputs are inconsistent or no valid rows result.
- isaaclab.cloner.clone_plan.make_clone_plan(cfgs: Iterable[Any], num_clones: int, env_spacing: float, device: str, *, clone_strategy: Callable = <function sequential>, valid_set: torch.Tensor | None = None) ClonePlan[source]#
Build a
ClonePlanfrom asset cfgs.Iterates
cfgs, identifies env-scoped cfgs with a spawn, expandsMultiAssetSpawnerCfg/MultiUsdFileCfginto per-variant prototype rows, runsclone_strategyto assign prototypes to envs, and returns a self-containedClonePlanwithcfg_rowspopulated.Each input cfg’s
spawn_path/spawn_pathsis mutated so the subsequent asset constructor spawns the prototype into its first active environment. Cfgs whoseprim_pathis global (not under the env root/World/envs/) or that lack a spawn are skipped — they do not appear in the plan and are not replicated.- Parameters:
cfgs¶ – Asset cfgs with resolved
prim_path(no{ENV_REGEX_NS}macros).num_clones¶ – Number of target envs.
env_spacing¶ – Distance between neighboring grid env origins [m].
device¶ – Torch device for plan tensors.
clone_strategy¶ – Function that assigns prototype combinations to envs. Defaults to
sequential().valid_set¶ – Optional
[num_combos, num_groups]long tensor of valid prototype combinations.None(default) uses the full cartesian product of every group’s prototype indices.
- Returns:
A
ClonePlanwhosesources/destinations/clone_maskdescribe the flat prototype-to-env mapping and whosecfg_rowsmaps each cfg to the rows it owns.
- isaaclab.cloner.clone_plan.clone_plan_from_env_0(source: str, destination: str, num_clones: int, device: str, positions: torch.Tensor | None = None) ClonePlan[source]#
Build a single-source clone plan that targets every env from one source row.
Auto-populates
ClonePlan.cfg_rowsfromREPLICATION_QUEUE, including only cfgs whoseprim_pathfalls under the env-root prefix ofdestination. Must be called after all asset constructors have run, so their cfgs are already registered in the queue; otherwise those assets will be skipped by the subsequentreplicate()call.- Parameters:
- Returns:
A
ClonePlanwith a single source row covering every env.
Path#
Segment-boundary-safe prim-path primitives for the cloner.
A prim path is a sequence of /-delimited segments, not a character string, and the stdlib
string operations cross those boundaries silently: str.startswith() reports that
".../Robot" contains ".../RobotArm". This module encodes the boundary semantics once.
Two kinds of prefix appear in the cloner. A root is a concrete prefix path
("/World/envs/env_0"); relative_to(), under() and rebase() work against
one. A template carries a single "{}" clone slot standing for one segment
("/World/envs/env_{}/Robot"); split(), match() and relativize() work
against one. Reach them through the package, as cloner.path.rebase(...).
Classes:
The |
Functions:
|
Split a clone destination template around its |
|
Match |
|
Strip a concrete |
|
Return whether |
|
Rebase |
|
Return the part of |
- class isaaclab.cloner.path.TemplateMatch[source]#
The
"{}"text a template captured ("3", or a wildcard".*"), and the path below it.Attributes:
Methods:
__new__(_cls, instance, suffix)Create new instance of TemplateMatch(instance, suffix)
- isaaclab.cloner.path.split(template: str) tuple[str, str][source]#
Split a clone destination template around its
"{}"clone slot.The clone slot represents one concrete environment/instance path segment.
- Parameters:
template¶ – Destination path template with exactly one
"{}"for the instance id.- Returns:
The
(prefix, suffix)strings around the clone slot. A trailing slash is insignificant, so an instance-root template (".../env_{}") yields an empty suffix.- Raises:
ValueError – If
templatedoes not hold exactly one clone slot. A second slot would survive into the suffix and break the laterstr.formatthat fills the first.
- isaaclab.cloner.path.match(path_expr: str, template: str) TemplateMatch | None[source]#
Match
path_expragainst a destination template, capturing the instance slot.The
"{}"slot matches one path segment’s worth of text, whether a concrete id (3) or a wildcard (.*). Recovering that text is the only way to tell which instance a concrete clone path belongs to without slicing the string by hand.- Parameters:
- Returns:
A
TemplateMatchwith the captured instance text and the asset-relative suffix, orNonewhenpath_expris not under the template’s instance root.
Example
>>> match("/World/envs/env_3/Robot/base", "/World/envs/env_{}/Robot") TemplateMatch(instance='3', suffix='/base')
- isaaclab.cloner.path.relative_to(path: str, root: str) str | None[source]#
Strip a concrete
rootprefix offpathon a segment boundary.Unlike slicing or
str.removeprefix(), this returnsNonerather than a mid-segment remainder whenpathis not underroot.
- isaaclab.cloner.path.under(path: str, root: str) bool[source]#
Return whether
pathlies within the subtree rooted atroot.Boundary-correct membership test: unlike
str.startswith(), it does not match across a segment boundary (".../Robot"does not contain".../RobotArm").
- isaaclab.cloner.path.rebase(path: str, src_root: str, dst_root: str) str[source]#
Rebase
pathfrom one concrete root prefix onto another on a segment boundary.Unlike
str.replace(), this swaps only a boundary-aligned prefix and touches only the leading occurrence.
- isaaclab.cloner.path.relativize(path_expr: str, template: str) str | None[source]#
Return the part of
path_exprbelow a template’s instance root.The suffix half of
match(), for callers that do not need the captured instance.- Parameters:
- Returns:
The asset-relative suffix (starting with
/, or""whenpath_expris exactly the template root), orNonewhenpath_expris not under the root.
Query#
Queries over the prototype/clone relation a ClonePlan describes.
Each plan row pairs a prototype path that exists once on the stage with a destination
template and the environments it populates, so the relation is partial in both directions: a
prototype reaches only the environments its row covers, and an environment holds only the
assets whose rows cover it. path_to_clone(), path_env_ids() and
path_to_source() are the three ways to walk it; iter_sources() is
path_to_source() for callers that need every variant behind one template.
Environment ids are not mask columns. Column j stands for
env_ids[j], which is the number
replicate() formats into the template. These functions take and
return environment ids throughout.
A path belongs to the nearest row containing it: the deepest prototype root, or the template
leaving the shortest suffix. Rows tying there are one asset’s variants, and the environment
picks between them. test/cloner/test_clone_plan_algebra.py pins that down.
The path primitives are aliased pth because path is a parameter name here.
Functions:
|
Return the environments a prototype |
|
Return the clone of a prototype |
|
Resolve a clone-side expression to the prototype it was cloned from. |
|
Yield every populated plan row whose destination owns a path expression. |
- isaaclab.cloner.query.path_env_ids(plan: ClonePlan, path: str) tuple[int, ...][source]#
Return the environments a prototype
pathis replicated to.
- isaaclab.cloner.query.path_to_clone(plan: ClonePlan, path: str, env_id: int) str | None[source]#
Return the clone of a prototype
pathin one environment.Only the prototype root is swapped; everything below it is carried through unchanged.
- Parameters:
- Returns:
The clone path in
env_id, orNonewhenpathis unowned,env_idis not targeted by the plan, or no owning row populates it. Where several variants share the prototype subtree, the variant populatingenv_idis used.
- isaaclab.cloner.query.path_to_source(plan: ClonePlan, path_expr: str, env_id: int | None = None) tuple[str, str, str] | None[source]#
Resolve a clone-side expression to the prototype it was cloned from.
A concrete clone path names its environment in the template’s clone slot, and that environment selects which variant to report — which is what lets this undo
path_to_clone()for a heterogeneous asset. A wildcard expression (.../env_.*/...) names no environment and stands for all of them, so it resolves to the first populated variant unlessenv_idsays which one to take.- Parameters:
- Returns:
A
(source_path, destination_glob, asset_suffix)tuple, whereasset_suffixis the part ofpath_exprbelow the owning template.Nonewhenpath_exprmatches no row, or no matching row populates the requested environment, letting callers fall back to direct stage resolution.Partial-env coverage is supported: when the matching rows cover only a subset of envs (an asset present in some envs but not others, as in heterogeneous scenes), the returned glob resolves to just those envs.
- Raises:
ValueError – When
path_expris owned by multiple distinct, equally near templates.
- isaaclab.cloner.query.iter_sources(plan: ClonePlan, path_expr: str) Iterator[tuple[str, str, str, tuple[int, ...]]][source]#
Yield every populated plan row whose destination owns a path expression.
Where
path_to_source()names one variant, this yields them all, for callers that must visit each prototype behind a destination template (loading one mesh per variant).Example
For a row with prototype root
"/World/source/Robot", destination template"/World/scenes/{}/Robot"and env ids(0, 2), querying"/World/scenes/.*/Robot/base"yields("/World/source/Robot", "/World/scenes/{}/Robot", "/World/source/Robot/base", (0, 2)).