bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
Installing bitrl

bitrl is built on bitsim, so bitsim comes first. Ubuntu 24.04 is the reference platform: the CI builds bitrl there, with the scripts in bitrl's ci/ directory that this page mentions.

Dependencies

Dependency Needed for
A C++20 compiler, such as g++ 11, and CMake 3.20 or newer everything
bitsim 5, and what it needs: Boost, Eigen, spdlog everything; see Installing bitsim
libtorch, built with the C++11 ABI everything; the deep reinforcement learning
TBB, sudo apt-get install libtbb-dev everything
GoogleTest ENABLE_TESTS
The bitrl-rest-api server running the Gymnasium environments, not building

HTTPRequest and nlohmann/json come with bitsim. bitsim installs as the CMake package bitsim; ci/install_bitsim.sh <prefix> builds and installs it, and ci/install_libtorch.sh <prefix> downloads libtorch, the way the CI does.

Build

Tell CMake where bitsim and libtorch are:

cmake -B build -DCMAKE_PREFIX_PATH="/path/to/bitsim/prefix;/path/to/libtorch"
cmake --build build --parallel 3

Give --parallel a number. The files that include libtorch take a lot of memory to compile, and an unlimited build runs out of memory on a 16 GB machine. If bitsim was built with Chrono, and Chrono is not in a system prefix, add its prefix to CMAKE_PREFIX_PATH too.

Option Default Description
ENABLE_EXAMPLES ON Build the examples, see Examples
ENABLE_TESTS OFF Build the tests
USE_CUDA OFF Use CUDA; libtorch must be built with CUDA too
BITRL_LOG ON Library logging
BITRL_WERROR OFF Treat warnings as errors

With the tests:

cmake -B build -DCMAKE_PREFIX_PATH="..." -DENABLE_TESTS=ON
cmake --build build --parallel 3
ctest --test-dir build --output-on-failure

Install

cmake -B build -DCMAKE_PREFIX_PATH="..." -DCMAKE_INSTALL_PREFIX=$HOME/opt/bitrl
cmake --build build --parallel 3
cmake --install build

installs lib/libbitrllib.so, the headers in include/bitrl/ and the CMake package in lib/cmake/bitrl/. Another project then uses bitrl with

find_package(bitrl 5 REQUIRED)
target_link_libraries(my_target PRIVATE bitrl::bitrl)

and -DCMAKE_PREFIX_PATH with the prefixes of bitrl, bitsim and libtorch. The package finds bitsim, libtorch and TBB itself. ci/check_install.sh checks that an installed bitrl works this way.

The environment server

Gymnasium's environments run on the bitrl-rest-api server, which bitrl reaches at http://0.0.0.0:8001/api by default. Start it before you run the examples that use them; its README says how to install and run it.

Logging

bitrl logs with bitsim's logger, which writes with spdlog to standard error. bitrl's messages go to the logger named bitrl:

BITRL_LOG_INFO << "Episode " << episode << " reward " << reward;
bitrl::log::set_level("bitrl", bitrl::log::Level::warn); // only warnings and above from bitrl
bitrl::log::add_file_sink("training.log"); // to a file as well
bitrl's logging: the logger of bitsim, bitsim/utils/logger.h, with bitrl's messages going to the logg...
#define BITRL_LOG_INFO
Definition bitrl_log.h:36
void add_file_sink(const std::string &filename, bool truncate=true)
Write the messages of every logger to a file as well.
Definition logger.cpp:189
void set_level(Level level)
Set the level of every logger, and of the loggers made later.
Definition logger.cpp:165

The SPDLOG_LEVEL environment variable sets the levels without changing the code: SPDLOG_LEVEL=bitrl=warn ./ppo_cartpole. The logging section of Installing bitsim has the details.

The documentation

This site is built with Doxygen from its own repository; Building the documentation says how.