Skip to content

Commit f0e52bb

Browse files
committed
Remove envtorch dir nesting and add base env code
1 parent 66d970e commit f0e52bb

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "envtorch"
7-
version = "0.0.0"
7+
version = "0.1.0"
88
requires-python = ">=3.8"
99
dependencies = [
1010
"torch>=1.9.0",
File renamed without changes.

src/core/base.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Abstract base classes for EnvTorch
2+
from __future__ import annotations
3+
4+
from abc import ABC, abstractmethod
5+
from typing import Generic, TypeVar
6+
7+
from .types import StepResult
8+
9+
# Generic type variables
10+
ActT = TypeVar("ActT") # Type for the action sent to the environment
11+
ObsT = TypeVar("ObsT") # Type for the observation returned by the environment
12+
13+
14+
class BaseEnv(ABC, Generic[ActT, ObsT]):
15+
"""
16+
Abstract base class for all environments.
17+
18+
Each environment must implement:
19+
- reset(): to initialize or reinitialize environment state
20+
- step(action): to execute an action and return results
21+
- close(): to release resources (containers, sessions, etc.)
22+
"""
23+
24+
@abstractmethod
25+
def reset(self) -> ObsT:
26+
"""
27+
Resets the environment to its initial state.
28+
29+
Returns:
30+
ObsT: The initial observation after resetting.
31+
"""
32+
raise NotImplementedError
33+
34+
@abstractmethod
35+
def step(self, action: ActT) -> StepResult[ObsT]:
36+
"""
37+
Performs one logical step in the environment.
38+
39+
Args:
40+
action (ActT): The action to perform in the environment.
41+
42+
Returns:
43+
StepResult[ObsT]: The resulting observation, reward, done flag, and info.
44+
"""
45+
raise NotImplementedError

src/core/types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Type definitions for EnvTorch
2+
from dataclasses import dataclass
3+
from typing import Any, Generic, Optional, TypeVar
4+
5+
# Generic type for observations
6+
ObsT = TypeVar("ObsT") # TypeVar for typehinting in IDEs
7+
8+
9+
@dataclass
10+
class StepResult(Generic[ObsT]):
11+
"""
12+
Represents the result of one environment step.
13+
14+
Attributes:
15+
observation: The environment's observation after the action.
16+
reward: Scalar reward for this step (optional).
17+
done: Whether the episode is finished.
18+
info: Additional metadata (e.g. debug info, latency, etc.).
19+
"""
20+
21+
observation: ObsT
22+
reward: Optional[float] = None
23+
done: bool = False
24+
info: Optional[dict[str, Any]] = None

src/envs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Environment implementations like CodingEnv here

src/envtorch/envs/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)