Skip to content

factory

get_state_dependency_graph(states=None)

Parameters:

Name Type Description Default
states None or Iterable

If specified, specific state(s) to sort. Otherwise, will generate dependency graph over all states

None

Returns:

Type Description
DiGraph

State dependency graph of supported object states

Source code in OmniGibson/omnigibson/object_states/factory.py
def get_state_dependency_graph(states=None):
    """
    Args:
        states (None or Iterable): If specified, specific state(s) to sort. Otherwise, will generate dependency graph
            over all states

    Returns:
        nx.DiGraph: State dependency graph of supported object states
    """
    states = REGISTERED_OBJECT_STATES.values() if states is None else states
    dependencies = {state: set.union(state.get_dependencies(), state.get_optional_dependencies()) for state in states}
    return nx.DiGraph(dependencies)

get_states_and_params_for_ability(ability, params)

Enumerate the (state_type, params) pairs an @ability contributes, with the per-(ability, state) param transform (see @transform_ability_params_for_state) applied to each.

Both object hydration (USDObject) and asset model-validation (get_all_object_category_models_with_abilities) must instantiate an ability's states with the SAME kwargs, otherwise a model can pass one path and fail the other. They therefore share this helper so the two never drift apart -- e.g. flammable injects requires_on_fire=True into HeatSourceOrSink, which flips its meta-link requirement; without the transform, validation would demand a heatsource meta link that hydration does not.

Parameters:

Name Type Description Default
ability str

Ability name

required
params dict

Raw ability params

required

Returns:

Type Description
list of (type, dict

(state_type, transformed_params) for each state @ability contributes

Source code in OmniGibson/omnigibson/object_states/factory.py
def get_states_and_params_for_ability(ability, params):
    """
    Enumerate the (state_type, params) pairs an @ability contributes, with the per-(ability, state)
    param transform (see @transform_ability_params_for_state) applied to each.

    Both object hydration (USDObject) and asset model-validation
    (get_all_object_category_models_with_abilities) must instantiate an ability's states with the
    SAME kwargs, otherwise a model can pass one path and fail the other. They therefore share this
    helper so the two never drift apart -- e.g. `flammable` injects requires_on_fire=True into
    HeatSourceOrSink, which flips its meta-link requirement; without the transform, validation
    would demand a heatsource meta link that hydration does not.

    Args:
        ability (str): Ability name
        params (dict): Raw ability params

    Returns:
        list of (type, dict): (state_type, transformed_params) for each state @ability contributes
    """
    return [
        (state_type, transform_ability_params_for_state(ability, state_type, params))
        for state_type in get_states_for_ability(ability)
    ]

get_states_by_dependency_order(states=None)

Parameters:

Name Type Description Default
states None or Iterable

If specified, specific state(s) to sort. Otherwise, will generate dependency graph over all states

None

Returns:

Type Description
list

all states in topological order of dependency

Source code in OmniGibson/omnigibson/object_states/factory.py
def get_states_by_dependency_order(states=None):
    """
    Args:
        states (None or Iterable): If specified, specific state(s) to sort. Otherwise, will generate dependency graph
            over all states

    Returns:
        list: all states in topological order of dependency
    """
    return list(
        reversed(
            list(
                nx.algorithms.lexicographical_topological_sort(
                    get_state_dependency_graph(states), key=lambda n: n.__name__
                )
            )
        )
    )

transform_ability_params_for_state(ability, state_type, params)

Applies the per-(ability, state) kwarg transform (if any) to @params.

Parameters:

Name Type Description Default
ability str

Ability name

required
state_type type

Object state class being hydrated from @ability's params

required
params dict

Raw ability params

required

Returns:

Type Description
dict

Transformed copy of @params

Source code in OmniGibson/omnigibson/object_states/factory.py
def transform_ability_params_for_state(ability, state_type, params):
    """
    Applies the per-(ability, state) kwarg transform (if any) to @params.

    Args:
        ability (str): Ability name
        state_type (type): Object state class being hydrated from @ability's params
        params (dict): Raw ability params

    Returns:
        dict: Transformed copy of @params
    """
    transform = _ABILITY_STATE_PARAM_TRANSFORMS.get((ability, state_type), None)
    if transform is None:
        return dict(params)
    renames, extra_kwargs = transform
    params = {renames.get(key, key): value for key, value in params.items()}
    params.update(extra_kwargs)
    return params