Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "envtorch"
version = "0.0.0"
version = "0.1.0"
requires-python = ">=3.8"
dependencies = [
"torch>=1.9.0",
Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions src/core/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Abstract base classes for EnvTorch
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Generic, TypeVar

from .types import StepResult

# Generic type variables
ActT = TypeVar("ActT") # Type for the action sent to the environment
ObsT = TypeVar("ObsT") # Type for the observation returned by the environment


class BaseEnv(ABC, Generic[ActT, ObsT]):
"""
Abstract base class for all environments.

Each environment must implement:
- reset(): to initialize or reinitialize environment state
- step(action): to execute an action and return results
- close(): to release resources (containers, sessions, etc.)
"""

@abstractmethod
def reset(self) -> ObsT:
"""
Resets the environment to its initial state.

Returns:
ObsT: The initial observation after resetting.
"""
raise NotImplementedError

@abstractmethod
def step(self, action: ActT) -> StepResult[ObsT]:
"""
Performs one logical step in the environment.

Args:
action (ActT): The action to perform in the environment.

Returns:
StepResult[ObsT]: The resulting observation, reward, done flag, and info.
"""
raise NotImplementedError
24 changes: 24 additions & 0 deletions src/core/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Type definitions for EnvTorch
from dataclasses import dataclass
from typing import Any, Generic, Optional, TypeVar

# Generic type for observations
ObsT = TypeVar("ObsT") # TypeVar for typehinting in IDEs


@dataclass
class StepResult(Generic[ObsT]):
"""
Represents the result of one environment step.

Attributes:
observation: The environment's observation after the action.
reward: Scalar reward for this step (optional).
done: Whether the episode is finished.
info: Additional metadata (e.g. debug info, latency, etc.).
"""

observation: ObsT
reward: Optional[float] = None
done: bool = False
info: Optional[dict[str, Any]] = None
1 change: 1 addition & 0 deletions src/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Environment implementations like CodingEnv here
1 change: 0 additions & 1 deletion src/envtorch/envs/__init__.py

This file was deleted.