GSOC2023ns3-ai

From Nsnam
Revision as of 09:44, 18 June 2023 by Muyuan (Talk | contribs)

Jump to: navigation, search

Main Page - Current Development - Developer FAQ - Tools - Related Projects - Project Ideas - Summer Projects

Installation - Troubleshooting - User FAQ - HOWTOs - Samples - Models - Education - Contributed Code - Papers

Back to GSoC 2023 projects

Project Overview

Project Goals

The proposed project aims to enhance the ns3-ai module, which provides interfaces between ns-3 and Python-based ML frameworks using shared memory, with a focus on performance optimization and expanding the range of supported data structures. To achieve this, the project will introduce APIs for additional data structures like vector and string in shared memory IPC to reduce the interaction between C++ and Python. Additionally, the project will provide examples demonstrating how to implement ML algorithms within ns-3 using C++ and open-source frameworks such as TensorFlow and PyTorch. The project will also improve the current examples and documentation and integrate new examples, such as LTE handover. Overall, the project aims to expand and accelerate the capabilities of the ns3-ai module, enabling users to simulate and analyze large-scale networks with greater efficiency and flexibility.

Repository

https://github.com/ShenMuyuan/ns3-ai/tree/improvements

About Me

Education

As a junior at Huazhong University of Science and Technology, I am majoring in electronic engineering. I am proud to be a member of the Undergraduate Program for Advanced Project-based Information Science Education, also known as the Seed Class, and currently serve as the class monitor. Additionally, I am a project leader in the Dian group, where I engage in extracurricular technical projects. In terms of relevant coursework, I have excelled in network programming through courses such as C programming language and computer network, both of which I achieved a perfect grade point of 4.0. These courses have equipped me with a strong foundation in network programming, which I believe will enable me to contribute effectively to relevant projects. I am a motivated and skilled undergraduate student with a passion for network programming and a track record of academic excellence.

Experience with ns-3

During my academic journey, I have had the opportunity to explore computer networking through labs and projects. In particular, in the labs for the computer networking course, I gained valuable insights into how different parameters, such as the number of STAs, CW range, and packet arrival rate, can impact network throughput in the WiFi DCF protocol. In addition, I have worked on a project that leverages ns-3 as a simulation platform with Prof. Yayu Gao. Through this project, I have gained practical experience in simulating WiFi MAC rate control algorithms, which has further solidified my understanding of the ns-3's usage and its object-oriented programming approach. Overall, my hands-on experience in both labs and projects has allowed me to apply theoretical concepts to practical scenarios and enhanced my network simulation and analysis skills.

Milestones

Based on my proposal, I divide my project into two phases, listed below.

Phase one (before midterm evaluation)

Enhancements for the interface

std::vector support

Introduce APIs for storing data structures like std::vector in shared memory, to reduce the interaction between C++ and Python.

gym-like interface

Introduce a gym-like interface to enable users to train RL models directly in ns-3 with OpenAI Gym.

Enhancements for existing examples

Make all previous examples up to date with the Cmake building system introduced in ns3.36, also provide a new example to benchmark the running time of vectors.

Phase two (after midterm evaluation)

Integration of ns-3 and C++-based ML frameworks

TODO

Finishing new examples and benchmarking test

TODO

Weekly Report

Week 1 (May 29 - June 4)

Achievements

  1. Got familiar with the usage of Boost library, and the syntax of Cython pyx files. I am using Boost to support dynamic allocation and synchronization in shared memory and Cython to wrap C++ code for Python.
  2. Created the interface to support std::vector in shared memory. Also wrote a new a-plus-b example to demonstrate the usage. It is still in development and currently supports macOS.
  3. (Update on June 3) Now I am using pybind11 instead of Cython for Python binding, because pybind11 has similar performance but cleaner code. And also it is easier to use cmake to install the python module.

Problems

  1. The code is quite naive and possibly includes some extra interactions that lowers performance.
  2. I have not tested the new interface on Linux.
  3. (Update on June 3) The new interface has hardcoded parts in the setup.py. Users need to explicitly specify their Boost library include and library paths.
  4. (Update on June 3) Although I have only one example currently, if there is more, users need to repeatedly call the setup.py to install modules which lacks efficiency.

Todo next week

  1. Use the new interface in an existing example such as rl-tcp, compare running time with old interface, to know its performance better.
  2. Switch to a new branch called "improvements" instead of "cmake", which better shows the project goal.
  3. (Update on June 3) Modify CMakeLists.txt to pass the result of find_package(Boost...) to setup.py, and remove the hardcoded part.
  4. (Update on June 3) Make "pip install . --user" a target in Cmake, so that users can install Python modules more easily, like "./ns3 build ns3ai_interfaces".
  5. If I have time, I will test my code on Linux.

Week 2 (June 5 - June 11)

Achievements

  1. Updated the Thompson Sampling example to use the new interface. Previously, it uses simple packed structure for information sharing. Now it uses the first element of shared std::vector (which is basically the same structure as before).
  2. Measured running time of the Thompson Sampling example, old interface vs new interface. Results: old about 5 seconds, new about 12 minutes.

Problems

  1. The benchmarking result above shows that, in terms of passing small amount of data in each interaction, the new interface is 150 times slower than the old interface.

Todo next week

  1. Measure running time of another example (the new multi-bss example) which passes large amount of data in each interaction, to check whether the new interface improves performance in that case. If the new outperforms the old, then the old and new interface can coexist for different cases. Else, I will consider modifying the implementation.
  2. Or, try to optimize the code to make small data interaction faster.

Week 3 (June 12 - June 18)

Achievements

  1. Accelerated data interaction using spinlock-based semaphore as synchronization method. The running time of Thompson Sampling example shortened to 6 seconds on my machine, which means that the performance of small data interaction is close to the previous interface.
    • I tried eliminating data copying operations and use a lot of reference instead, but it hardly improves running time.
    • I guessed that semaphores will spin instead of sleep, which can save more time (although it wastes CPU). So in the synchronization code I replaced Boost.Interprocess condition variable with Boost.Interprocess semaphore. But there was no improvement. Investigation using Clion's builtin profiler shows that sleeping takes a large portion of running time. Then I read the source code of Boost and found that when a semaphore is waiting, it's not purely spinning. Actually, it puts process to sleep after the spinning time reaches a small threshold. I commented the spin counting code to force always spinning, and the running time reduced a lot.
    • To avoid modifying library code, I created my own version of semaphore. My implementation of semaphore is similar to Boost's, but while waiting it only spins and never go to sleep. This significantly accelerates interaction between Python and C++, reducing the running time to 6s.
  2. Updated the a plus b and constant rate example. Currently available examples that use new interface: A Plus B, Thompson Sampling, Constant Rate.

Problems

  1. The examples has not been tested on Linux yet, which will take place next week.

Todo next week

  1. Start working on ns3-gym-like interface, which is one of the milestones.
  2. Work with Hao to release the previous version of ns3ai.
  3. Test the three currently available examples on Linux system.