Skip to content

Source code of the experiments of the master thesis of Emanuele Petriglia (October 2024).

License

Notifications You must be signed in to change notification settings

unimib-datAI/marl-dfaas

Repository files navigation

Multi-Agent RL for DFaaS by Emanuele Petriglia

This repository is in a working in progress state.

If you are looking for the source code of the experiments of Emanuele Petriglia's master's thesis, discussed in October 2024, see the petriglia-thesis-2024 branch.

The thesis, a summary and the presentation slides are available in another repository hosted on GitLab, but they are written in Italian.

How to set up the environment

The experiments are run and tested on Ubuntu 24.04 using Python 3.12. For a reproducible development environment, it is preferable to install the dependencies in a virtual environment (see the venv module). The venv module is not installed by default in Ubuntu, it must be installed using sudo apt install python3.12-venv.

The complete list of Python dependencies can be found in the requirements.txt file. However, the most important dependencies are:

  • Ray RLlib (version 2.40): this is a reinforcement learning library used to define the DFaaS custom environment, run the experiments by training the models with the implemented algorithms.

  • PyTorch (version 2.5.1): is a library for deep learning on GPUs and CPUs. It is used by Ray RLlib when training models with deep learning reinforcement learning algorithms.

  • Matplotlib (version 3.9.3): is a plot generation library used in the scripts in the plots directory.

When installing Ray RLlib, pip automatically installs its dependencies, which are also used by the experiment scripts (like NumPy or Gymnasium). This means that the environment can be easily set up by installing the following packages:

ray[rllib]==2.40.0
torch==2.5.1
gputil==1.4.0  # Required by RLlib (GPU system monitoring).
matplotlib==3.9.3

Run the following commands to set up the development environment with Ubuntu:

$ sudo apt install python3.12-venv
$ git clone https://github.com/unimib-datAI/marl-dfaas.git
$ cd marl-dfaas
$ python3.12 -m venv .env
$ source .env/bin/activate
$ pip install ray[rllib]==2.39.0 torch==2.5.1 gpuutil==1.4.0

For perfect reproducibility, there is a requirements.txt file that can be used instead of the previous command:

$ pip install --requirement requirements.txt

Please note that both the requirements file and the command line suggestions expect a machine with an NVIDIA GPU and CUDA (at least 12.4) installed for PyTorch. PyTorch can also be used with a CPU, in this case follow the instructions on the official website.

The requirements file also contains black (a development tool for automatically formatting source code), pylint (a static code analyser) and pre-commit packages. The latter run automatically black when doing commits.

How to run the experiments

WIP

Important: always run Python scripts from the project root directory to allow loading of commonly used modules (dfaas_env.py...). As example, if you need to run a test script:

$ python tests/env/local_strategy.py

Patching Ray

The selected version of Ray RLlib needs to be patched to fix some bugs or undesirable behaviour that has not yet been addressed upstream. The patches are collected in the patches directory and can be applied using the patch command:

patch -p0 < patches/NAME.patch

The patches have only been tested with Ray 2.40.0. They will only work if the virtual environment is named .env and the Python version is 3.12, as the file path is hardcoded into the patch file.

Note: The patch binary is required and preinstalled on Ubuntu. If not available, it can be installed with apt install patch.

The patches are created using the standard diff tool:

diff -Naru .env/.../rllib/example.py .env/.../rllib/example_new.py > patches/NAME.patch

See this reply on StackExchange for more information.

License

Copyright 2024 Emanuele Petriglia

The source code in this repository is licensed under the Apache License, version 2.0. See the LICENSE file for more information.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Source code of the experiments of the master thesis of Emanuele Petriglia (October 2024).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages