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.
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_}
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.
POST /make
Description: Creates a new environment. Response format:
{"message": "OK", "idx": "idx"}
{
"version": "version",
"options": json
}
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()
{
seed: int = 42,
options: dict[str, Any] = {}
}
POST /{idx}/step
Description: Step in the environment with the given id. Response format:
{"time_step": step}
action: Any
where action is the admissible action to be executed on the environment.
GET /copies
Description: Query the number of copies available for a specific environment. Response format:
{"copies": len(manager)}
There is also a limited API for Tensorboard:
POST /init
POST /close
POST /add-text
POST /add-scalar
POST /add-scalars
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