Module pearl.api.space

Expand source code
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Optional

import torch

from pearl.api.action import Action
from torch import Tensor


class Space(ABC):
    """An abstract base class for action and observation spaces in Pearl."""

    @abstractmethod
    def sample(self, mask: Optional[Tensor] = None) -> Action:
        """Samples an element from this space."""
        pass

    @property
    @abstractmethod
    def shape(self) -> torch.Size:
        """Returns the shape of an element of the space."""
        pass

    @property
    @abstractmethod
    def is_continuous(self) -> bool:
        """Checks whether this is a continuous space."""
        pass

Classes

class Space

An abstract base class for action and observation spaces in Pearl.

Expand source code
class Space(ABC):
    """An abstract base class for action and observation spaces in Pearl."""

    @abstractmethod
    def sample(self, mask: Optional[Tensor] = None) -> Action:
        """Samples an element from this space."""
        pass

    @property
    @abstractmethod
    def shape(self) -> torch.Size:
        """Returns the shape of an element of the space."""
        pass

    @property
    @abstractmethod
    def is_continuous(self) -> bool:
        """Checks whether this is a continuous space."""
        pass

Ancestors

  • abc.ABC

Subclasses

Instance variables

var is_continuous : bool

Checks whether this is a continuous space.

Expand source code
@property
@abstractmethod
def is_continuous(self) -> bool:
    """Checks whether this is a continuous space."""
    pass
var shape : torch.Size

Returns the shape of an element of the space.

Expand source code
@property
@abstractmethod
def shape(self) -> torch.Size:
    """Returns the shape of an element of the space."""
    pass

Methods

def sample(self, mask: Optional[Tensor] = None) ‑> torch.Tensor

Samples an element from this space.

Expand source code
@abstractmethod
def sample(self, mask: Optional[Tensor] = None) -> Action:
    """Samples an element from this space."""
    pass