Skip to content

pockerman/bitrl-rest-api

Repository files navigation

bitrl-envs-api

API for reinforcement learning environments. Each environment exposes a Gymnasium like interface. The API is based on FastAPI. You can launch a server using the entrypoint.sh script. Alternatively, you can use Docker. You can find examples with C++ at: bitrl

The available endpoints are described below.

Environment API

Query liveness

GET /{idx}/is-alive

Description: Returns true if the environment with the given id is alive on the server. The response format is

{"result": is_alive_}

Close the environment

POST /{idx}/close

Description: Closes the environment with the given id. The response format on successful op is:

{"message": "OK"}

returns

{"message": "FAILED"}

if the the op was not successful.

Create a new environment

POST /make

Description: Creates a new environment. Response format:

{"message": "OK", "idx": "idx"}

Payload:

{
 "version": "version",
 "options": json
}

Reset the environment

POST /{idx}/reset

Description: Reset the environment with the given id. Response format:

{"time_step": step}

where step has the following structure:

class TimeStep(BaseModel, Generic[_Reward, _Discount, _Observation]):
    step_type: TimeStepType = Field(title="step_type")
    reward: Optional[_Reward] = Field(title="reward")
    discount: Optional[_Discount] = Field(title="discount")
    observation: _Observation = Field(title="observation")
    info: dict = Field(title="info")

    def first(self) -> bool:
        return self.step_type == TimeStepType.FIRST

    def mid(self) -> bool:
        return self.step_type == TimeStepType.MID

    def last(self) -> bool:
        return self.step_type == TimeStepType.LAST

    @property
    def done(self) -> bool:
        return self.last()

Payload:

{
seed: int = 42,
options: dict[str, Any] = {}
}

Step in the environment

POST /{idx}/step

Description: Step in the environment with the given id. Response format:

{"time_step": step}

Payload:

 action: Any

where action is the admissible action to be executed on the environment.

Query number of copies

GET /copies

Description: Query the number of copies available for a specific environment. Response format:

{"copies": len(manager)}

Tensorboard API

There is also a limited API for Tensorboard:

POST /init
POST /close
POST /add-text
POST /add-scalar
POST /add-scalars

Installation

You can use Docker to run the API:

docker build -t bitrl-rest-api:v1 .
docker run -p 8001:8001 bitrl-rest-api:v1

You can access the API documentation at http://0.0.0.0:8001/docs

There is also a pre-built Docker image at: https://hub.docker.com/repository/docker/alexgiavaras/bitrl-rest-api/general

About

An API for accessing reinforcement learning environments in a REST like manner

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages