Skip to content

Commit 7cee1f7

Browse files
committed
Fix documentaion version libraries. Add how_to_use section
1 parent 2de4534 commit 7cee1f7

File tree

8 files changed

+277
-253
lines changed

8 files changed

+277
-253
lines changed

.readthedocs.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ build:
1818
- doxygen
1919
- pip install pydot
2020
- pip install sphinx==5.0.2
21-
- pip install breathe
22-
- pip install -U exhale
23-
- pip install sphinx_rtd_theme
21+
- pip install breathe==4.35.0
22+
- pip install -U exhale==0.3.7
23+
- pip install sphinx_rtd_theme==3.0.2
2424

2525

2626
# Build documentation in the "docs/" directory with Sphinx

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
# The theme to use for HTML and HTML Help pages. See the documentation for
100100
# a list of builtin themes.
101101
#
102-
html_theme = 'alabaster'
102+
html_theme = 'default'
103103

104104
# Add any paths that contain custom static files (such as style sheets) here,
105105
# relative to this directory. They are copied after the builtin static files,

docs/how_to_use.rst

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
How to use
2+
=============
3+
4+
The following is an example how to use the
5+
``FrozenLake`` environment from <a href="https://github.com/Farama-Foundation/Gymnasium/tree/main">Gymnasium</a>.
6+
7+
.. code-block::
8+
9+
#include "rlenvs/rlenvs_types_v2.h"
10+
#include "rlenvs/envs/gymnasium/toy_text/frozen_lake_env.h"
11+
#include "rlenvs/envs/api_server/apiserver.h"
12+
13+
#include <iostream>
14+
#include <string>
15+
#include <unordered_map>
16+
#include <any>
17+
18+
namespace example_1{
19+
20+
const std::string SERVER_URL = "http://0.0.0.0:8001/api";
21+
22+
using rlenvscpp::envs::gymnasium::FrozenLake;
23+
using rlenvscpp::envs::RESTApiServerWrapper;
24+
25+
26+
void test_frozen_lake(const RESTApiServerWrapper& server){
27+
28+
FrozenLake<4> env(server);
29+
30+
std::cout<<"Environame URL: "<<env.get_url()<<std::endl;
31+
32+
// make the environment
33+
std::unordered_map<std::string, std::any> options;
34+
options.insert({"is_slippery", false});
35+
env.make("v1", options);
36+
37+
std::cout<<"Is environment created? "<<env.is_created()<<std::endl;
38+
std::cout<<"Is environment alive? "<<env.is_alive()<<std::endl;
39+
std::cout<<"Number of valid actions? "<<env.n_actions()<<std::endl;
40+
std::cout<<"Number of states? "<<env.n_states()<<std::endl;
41+
42+
// reset the environment
43+
auto time_step = env.reset(42, std::unordered_map<std::string, std::any>());
44+
45+
std::cout<<"Reward on reset: "<<time_step.reward()<<std::endl;
46+
std::cout<<"Observation on reset: "<<time_step.observation()<<std::endl;
47+
std::cout<<"Is terminal state: "<<time_step.done()<<std::endl;
48+
49+
//...print the time_step
50+
std::cout<<time_step<<std::endl;
51+
52+
// take an action in the environment
53+
// 2 = RIGHT
54+
auto new_time_step = env.step(2);
55+
56+
std::cout<<new_time_step<<std::endl;
57+
58+
// get the dynamics of the environment for the given state and action
59+
auto state = 0;
60+
auto action = 1;
61+
auto dynamics = env.p(state, action);
62+
63+
std::cout<<"Dynamics for state="<<state<<" and action="<<action<<std::endl;
64+
65+
for(auto item:dynamics){
66+
67+
std::cout<<std::get<0>(item)<<std::endl;
68+
std::cout<<std::get<1>(item)<<std::endl;
69+
std::cout<<std::get<2>(item)<<std::endl;
70+
std::cout<<std::get<3>(item)<<std::endl;
71+
}
72+
73+
action = env.sample_action();
74+
new_time_step = env.step(action);
75+
76+
std::cout<<new_time_step<<std::endl;
77+
78+
// synchronize the environment
79+
env.sync(std::unordered_map<std::string, std::any>());
80+
81+
auto copy_env = env.make_copy(1);
82+
copy_env.reset();
83+
84+
std::cout<<"Org env cidx: "<<env.cidx()<<std::endl;
85+
std::cout<<"Copy env cidx: "<<copy_env.cidx()<<std::endl;
86+
87+
copy_env.close();
88+
89+
// close the environment
90+
env.close();
91+
92+
}
93+
94+
}
95+
96+
97+
int main(){
98+
99+
using namespace example_1;
100+
101+
RESTApiServerWrapper server(SERVER_URL, true);
102+
103+
std::cout<<"Testing FrozenLake..."<<std::endl;
104+
example_1::test_frozen_lake(server);
105+
std::cout<<"===================="<<std::endl;
106+
return 0;
107+
}
108+
109+
110+
111+
112+
In general, the environments exposed by the library follow the semantics in <a href="https://github.com/deepmind/dm_env/blob/master/docs/index.md">Environment API and Semantics</a> specification.
113+
For more details see the <a href="doc/env_spec.md">```rlenvscpp``` environment specification</a> document.
114+
115+
The general use case is to build the library and link it with your driver code to access its functionality.
116+
The environments specified as using REST in the tables above, that is all ```Gymnasium```, ```gym_pybullet_drones``` and ```GymWalk```
117+
environments are accessed via a client/server pattern. Namely, they are exposed via an API developed using
118+
<a href="https://fastapi.tiangolo.com/">FastAPI</a>.
119+
You need to fire up the FastAPI server, see dependencies, before using the environments in your code.
120+
To do so
121+
122+
``
123+
./start_uvicorn.sh
124+
``
125+
126+
By default the ```uvicorn``` server listents on port 8001. Change this if needed. You can access the OpenAPI specification at
127+
128+
``
129+
http://0.0.0.0:8001/docs
130+
``
131+
132+
Note that currently the implementation is not thread/process safe i.e. if multiple threads/processes access the environment
133+
a global instance of the environment is manipulated. Thus no session based environment exists.
134+
However, you can create copies of the same environment and access this via its dedicate index.
135+
If just one thread/process touches this specific environment you should be ok.
136+
Notice that the FastAPI server only uses a single process to manage all the environments.
137+
In addition, if you need multiple instances of the same environment you can also use one
138+
of the exissting vectorised environments (see table above).
139+
140+
Finally, you can choose to launch several instances of ```uvirocrn``` (listening on different ports).
141+
However in this case you need to implement all the interactions logic yourself as currently no implementation exists to handle such a scenario.

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
```rlenvscpp``` documentation
6+
``rlenvscpp`` documentation
77
=====================================
88

99
.. toctree::
1010
:maxdepth: 2
1111
:caption: Contents:
1212

1313
overview
14+
how_to_use
1415
installation
1516
api/library_root
1617

docs/installation.rst

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,88 @@
11
Installation
2-
------------
2+
============
3+
4+
This section describes how to install ``rlenvscpp``.
5+
6+
Dependencies
7+
------------
8+
9+
The library has the following general dependencies
10+
11+
- A compiler that supports C++20 e.g. g++-11
12+
- `Boost C++ <https://www.boost.org/>`_
13+
- `CMake >= 3.10 <https://cmake.org/>`_
14+
- `Gtest <https://github.com/google/googletest>`_ (if configured with tests)
15+
- `Eigen3 <https://eigen.tuxfamily.org/index.php?title=Main_Page>`_
16+
17+
Using the Gymnasium environments requires `Gymnasium <https://github.com/Farama-Foundation/Gymnasium/tree/main>`_
18+
installed on your machine.
19+
In addition, you need to install
20+
21+
- `FastAPI <https://fastapi.tiangolo.com/>`_
22+
- `Uvicorn <https://www.uvicorn.org/>`_
23+
- `Pydantic <a href="https://docs.pydantic.dev/latest/>`_
24+
25+
By installing the requirement under ``requirements.txt`` should set your Python environment up correctly.
26+
27+
``rlenvscpp`` also incorporates, see ``(src/extern)``, the following libraries
28+
29+
- `HTTPRequest <https://github.com/elnormous/HTTPRequest>`_
30+
- `nlohmann/json <https://github.com/nlohmann/json>`_
31+
32+
33+
There are extra dependencies if you want to generate the documentation. Namely,
34+
35+
- Doxygen
36+
- Sphinx
37+
- sphinx_rtd_theme
38+
- breathe
39+
- m2r2
40+
41+
The usual CMake based installation process is used. Namely
42+
43+
.. code-block::
44+
45+
mkdir build && cd build && cmake ..
46+
make install
47+
48+
49+
You can toggle the following variables
50+
51+
- CMAKE_BUILD_TYPE (default is RELEASE)
52+
- ENABLE_TESTS_FLAG (default is OFF)
53+
- ENABLE_EXAMPLES_FLAG (default is OFF)
54+
- ENABLE_DOC_FLAG (default is OFF)
55+
56+
For example enbling the examples
57+
58+
.. code-block::
59+
60+
cmake -DENABLE_EXAMPLES_FLAG=ON ..
61+
make install
62+
63+
64+
65+
Run the tests
66+
-------------
67+
68+
You can execute all the tests by running the helper script ``execute_tests.sh``.
69+
70+
71+
Issues
72+
-------
73+
74+
**Could not find ``boost_system``**
75+
76+
It is likely that you are missing the boost_system library with your local Boost installation. This may be the case
77+
is you installed boost via a package manager. On a Ubuntu machine the following should resolve the issue
78+
79+
.. code-block::
80+
81+
sudo apt-get update -y
82+
sudo apt-get install -y libboost-system-dev
83+
84+
85+
**FastAPI throws 422 Unpocessable entity**
86+
87+
Typically, this is a problem with how the client (400-range error) specified the data
88+
to be sent to the server.

0 commit comments

Comments
 (0)