Module moog.physics.abstract_physics

Abstract physic class.

Expand source code
"""Abstract physic class."""

import abc


class AbstractPhysics(abc.ABC):
    """Abstract physics class.
    
    All physics objects must inherit from this class.
    """

    def __init__(self, updates_per_env_step):
        self._updates_per_env_step = updates_per_env_step
    
    @abc.abstractmethod
    def apply_physics(self, state, updates_per_env_step):
        """Step the physics.
        
        Args:
            state: Environment state.
            updates_per_env_step: Int. Number of times the physics is applied
                per environment step.
        """
        pass

    def reset(self, state):
        """Reset the physics.

        This is called at every episode reset of the environment. Usually it
        does nothing (usually the physics don't change between episodes), but
        for maze environments this is used to initialize the maze for the
        episode.

        Args:
            state: Environment state.
        """
        pass

    def step(self, state):
        """Step physics, applying forces self._updates_per_env_step times."""
        for _ in range(self._updates_per_env_step):
            self.apply_physics(state, self._updates_per_env_step)

    @property
    def updates_per_env_step(self):
        """Number of times the physics is applied per environment step."""
        return self._updates_per_env_step

Classes

class AbstractPhysics (updates_per_env_step)

Abstract physics class.

All physics objects must inherit from this class.

Expand source code
class AbstractPhysics(abc.ABC):
    """Abstract physics class.
    
    All physics objects must inherit from this class.
    """

    def __init__(self, updates_per_env_step):
        self._updates_per_env_step = updates_per_env_step
    
    @abc.abstractmethod
    def apply_physics(self, state, updates_per_env_step):
        """Step the physics.
        
        Args:
            state: Environment state.
            updates_per_env_step: Int. Number of times the physics is applied
                per environment step.
        """
        pass

    def reset(self, state):
        """Reset the physics.

        This is called at every episode reset of the environment. Usually it
        does nothing (usually the physics don't change between episodes), but
        for maze environments this is used to initialize the maze for the
        episode.

        Args:
            state: Environment state.
        """
        pass

    def step(self, state):
        """Step physics, applying forces self._updates_per_env_step times."""
        for _ in range(self._updates_per_env_step):
            self.apply_physics(state, self._updates_per_env_step)

    @property
    def updates_per_env_step(self):
        """Number of times the physics is applied per environment step."""
        return self._updates_per_env_step

Ancestors

  • abc.ABC

Subclasses

Instance variables

var updates_per_env_step

Number of times the physics is applied per environment step.

Expand source code
@property
def updates_per_env_step(self):
    """Number of times the physics is applied per environment step."""
    return self._updates_per_env_step

Methods

def apply_physics(self, state, updates_per_env_step)

Step the physics.

Args

state
Environment state.
updates_per_env_step
Int. Number of times the physics is applied per environment step.
Expand source code
@abc.abstractmethod
def apply_physics(self, state, updates_per_env_step):
    """Step the physics.
    
    Args:
        state: Environment state.
        updates_per_env_step: Int. Number of times the physics is applied
            per environment step.
    """
    pass
def reset(self, state)

Reset the physics.

This is called at every episode reset of the environment. Usually it does nothing (usually the physics don't change between episodes), but for maze environments this is used to initialize the maze for the episode.

Args

state
Environment state.
Expand source code
def reset(self, state):
    """Reset the physics.

    This is called at every episode reset of the environment. Usually it
    does nothing (usually the physics don't change between episodes), but
    for maze environments this is used to initialize the maze for the
    episode.

    Args:
        state: Environment state.
    """
    pass
def step(self, state)

Step physics, applying forces self._updates_per_env_step times.

Expand source code
def step(self, state):
    """Step physics, applying forces self._updates_per_env_step times."""
    for _ in range(self._updates_per_env_step):
        self.apply_physics(state, self._updates_per_env_step)