nemo_gym.base_environment_server

View as Markdown

Shared lifecycle for environment servers.

Module Contents

Classes

NameDescription
BaseEnvironmentServerExpose a typed episode protocol with shared limits and cleanup.
BaseEnvironmentServerConfigConfigure protocol-neutral episode limits.
CleanupContextHold bounded process-local cleanup callbacks for one episode.
CleanupHandleClose one registered participant at a protocol boundary.
HandledEpisodeErrorCarry a failure that belongs in the native episode response.
_CleanupEntry-

Data

CleanupCallback

EpisodeRequestT

EpisodeResponseT

LOGGER

API

class nemo_gym.base_environment_server.BaseEnvironmentServer()

Bases: SimpleServer, Generic[EpisodeRequestT, EpisodeResponseT]

Expose a typed episode protocol with shared limits and cleanup.

_admission
Semaphore | None = None
config
BaseEnvironmentServerConfig
request_model
type[EpisodeRequestT]
response_model
type[EpisodeResponseT]
nemo_gym.base_environment_server.BaseEnvironmentServer._unhandled_failure_response(
error: Exception
nemo_gym.base_environment_server.BaseEnvironmentServer.failure_response(
nemo_gym.base_environment_server.BaseEnvironmentServer.model_post_init(
context: typing.Any
) -> None
asyncabstract

Run one concrete environment protocol.

nemo_gym.base_environment_server.BaseEnvironmentServer.run_request(
async
nemo_gym.base_environment_server.BaseEnvironmentServer.setup_webserver() -> fastapi.FastAPI
nemo_gym.base_environment_server.BaseEnvironmentServer.validate_response_identity(
) -> None
staticmethod
class nemo_gym.base_environment_server.BaseEnvironmentServerConfig()

Bases: BaseRunServerInstanceConfig

Configure protocol-neutral episode limits.

cleanup_timeout_seconds
PositiveFloat
default_episode_timeout_seconds
PositiveFloat | None = None
max_concurrent_episodes
PositiveInt | None = None
model_config
= ConfigDict(extra='forbid')
queue_timeout_seconds
PositiveFloat | None = None
nemo_gym.base_environment_server.BaseEnvironmentServerConfig.validate_queue_timeout() -> typing_extensions.Self
class nemo_gym.base_environment_server.CleanupContext(
cleanup_timeout_seconds: float,
)
Dataclass

Hold bounded process-local cleanup callbacks for one episode.

Callbacks:

  • are process-local Python objects, although they may issue remote close requests;
  • run sequentially in LIFO order within one total cleanup timeout;
  • must be idempotent because a timed-out remote request may have succeeded;
  • are lost on process or host failure, so remote owners need expiry or reaping.

Callback failures are logged and do not stop later callbacks. Cleanup has no durable retry after this context is discarded.

_cleanups
list[_CleanupEntry] = field(default_factory=list)
cleanup_timeout_seconds
float
episode_id
EpisodeId
nemo_gym.base_environment_server.CleanupContext.aclose() -> None
async
nemo_gym.base_environment_server.CleanupContext.register_cleanup(
name: str,
class nemo_gym.base_environment_server.CleanupHandle(
timeout_seconds: float
)
Dataclass

Close one registered participant at a protocol boundary.

entry
_CleanupEntry
timeout_seconds
float
nemo_gym.base_environment_server.CleanupHandle.close() -> None
async

Run this idempotent callback once.

The episode timeout bounds calls made during the protocol. The context’s cleanup timeout bounds callbacks left for final unwinding.

class nemo_gym.base_environment_server.HandledEpisodeError(
)
Exception

Bases: Exception

Carry a failure that belongs in the native episode response.

class nemo_gym.base_environment_server._CleanupEntry(
name: str,
active: bool = True,
lock: asyncio.Lock = asyncio.Lock()
)
Dataclass
active
bool = True
callback
CleanupCallback
lock
Lock = field(default_factory=(asyncio.Lock))
name
str
nemo_gym.base_environment_server._CleanupEntry.close() -> None
async
nemo_gym.base_environment_server.CleanupCallback = Callable[[], Awaitable[None]]
nemo_gym.base_environment_server.EpisodeRequestT = TypeVar('EpisodeRequestT', bound=(BaseEpisodeRequest[Any]))
nemo_gym.base_environment_server.EpisodeResponseT = TypeVar('EpisodeResponseT', bound=(BaseEpisodeResponse[Any]))
nemo_gym.base_environment_server.LOGGER = logging.getLogger(__name__)