Skip to content

action_primitive_set_base

BaseActionPrimitiveSet

Bases: with_metaclass(ABCMeta, object)

Source code in omnigibson/action_primitives/action_primitive_set_base.py
class BaseActionPrimitiveSet(with_metaclass(ABCMeta, object)):
    def __init_subclass__(cls, **kwargs):
        """
        Registers all subclasses as part of this registry. This is useful to decouple internal codebase from external
        user additions. This way, users can add their custom primitive set by simply extending this class,
        and it will automatically be registered internally. This allows users to then specify their primitive set
        directly in string-from in e.g., their config files, without having to manually set the str-to-class mapping
        in our code.
        """
        if not inspect.isabstract(cls):
            REGISTERED_PRIMITIVE_SETS[cls.__name__] = cls

    def __init__(self, env):
        self.env = env

    @property
    def robot(self):
        # Currently returns the first robot in the environment, but can be scaled to multiple robots
        # by creating multiple action generators and passing in a robot index etc.
        return self.env.robots[0]

    @abstractmethod
    def get_action_space(self):
        """Get the higher-level action space as an OpenAI Gym Space object."""
        pass

    @abstractmethod
    def apply(self, action):
        """
        Apply a primitive action.

        Given a higher-level action in the same format as the action space (e.g. as a number),
        generates a sequence of lower level actions (or raise ActionPrimitiveError). The action
        will get resolved and passed into apply_ref.
        """
        pass

    @abstractmethod
    def apply_ref(self, action, *args):
        """
        Apply a primitive action by reference.

        Given a higher-level action from the corresponding action set enum and any necessary arguments,
        generates a sequence of lower level actions (or raise ActionPrimitiveError)
        """
        pass

__init_subclass__(**kwargs)

Registers all subclasses as part of this registry. This is useful to decouple internal codebase from external user additions. This way, users can add their custom primitive set by simply extending this class, and it will automatically be registered internally. This allows users to then specify their primitive set directly in string-from in e.g., their config files, without having to manually set the str-to-class mapping in our code.

Source code in omnigibson/action_primitives/action_primitive_set_base.py
def __init_subclass__(cls, **kwargs):
    """
    Registers all subclasses as part of this registry. This is useful to decouple internal codebase from external
    user additions. This way, users can add their custom primitive set by simply extending this class,
    and it will automatically be registered internally. This allows users to then specify their primitive set
    directly in string-from in e.g., their config files, without having to manually set the str-to-class mapping
    in our code.
    """
    if not inspect.isabstract(cls):
        REGISTERED_PRIMITIVE_SETS[cls.__name__] = cls

apply(action) abstractmethod

Apply a primitive action.

Given a higher-level action in the same format as the action space (e.g. as a number), generates a sequence of lower level actions (or raise ActionPrimitiveError). The action will get resolved and passed into apply_ref.

Source code in omnigibson/action_primitives/action_primitive_set_base.py
@abstractmethod
def apply(self, action):
    """
    Apply a primitive action.

    Given a higher-level action in the same format as the action space (e.g. as a number),
    generates a sequence of lower level actions (or raise ActionPrimitiveError). The action
    will get resolved and passed into apply_ref.
    """
    pass

apply_ref(action, *args) abstractmethod

Apply a primitive action by reference.

Given a higher-level action from the corresponding action set enum and any necessary arguments, generates a sequence of lower level actions (or raise ActionPrimitiveError)

Source code in omnigibson/action_primitives/action_primitive_set_base.py
@abstractmethod
def apply_ref(self, action, *args):
    """
    Apply a primitive action by reference.

    Given a higher-level action from the corresponding action set enum and any necessary arguments,
    generates a sequence of lower level actions (or raise ActionPrimitiveError)
    """
    pass

get_action_space() abstractmethod

Get the higher-level action space as an OpenAI Gym Space object.

Source code in omnigibson/action_primitives/action_primitive_set_base.py
@abstractmethod
def get_action_space(self):
    """Get the higher-level action space as an OpenAI Gym Space object."""
    pass