cfl-minds / drl_shape_optimization

Deep reinforcement learning to perform shape optimization
MIT License
57 stars 15 forks source link
deep-reinforcement-learning drl ppo shape-optimization

drl_shape_optimization

The code in this repository presents a case of shape optimization for aerodynamics using DRL (Deep Reinforcement Learning). It is based on Tensorforce for the DRL components, and on Fenics for the CFD computations. The corresponding paper is here and here. If you use this code for your research, please consider citing this paper.

Update: The optimization method has been greatly improved, you can find more here.

What is in the repo

Installation and requirements

Method 1 (discouraged): installing by hand

In addition, you will need the following packages that are provided / defined in the repo (you may need to run these with sudo rights):

cd tensorforce; pip3 install -e .; cd ..

pip3 install -r requirements.txt

Method 2 (recommended): using the docker container provided

Get the docker container at: https://cloud.mines-paristech.fr/index.php/s/kv7ymdrITXbeBNa

Load the docker container, and start an interactive session sharing your cwd to allow exchange of information in and out of the container:

sudo docker load < shape_2d_2020_12.tar  # load the image into docker
sudo docker run -ti --name shape2dopt -v $(pwd):/home/fenics/shared shape_2d_2020_12:latest  # spin an interactive container (named shape2dopt) out of the image, sharing the cwd for allowing exchange of information
  at this stage you get a prompt inside the container; exit the container immediately
sudo docker start shape2dopt  # container was stopped when exiting, start it again
sudo docker exec -ti -u fenics shape2dopt /bin/bash -l  # get an interactive terminal inside the re-started container
  you are now in an interactive session inside the container, where the /shared folder is a mirror of your cwd, and /local contains the code, with all packages and dependencies availalbe

In addition, once you are finished working, you can stop the whole container by using sudo docker container stop shape2dopt

The code contained in this repo is included already in the container, at: /home/fenics/local/shape_optimization_DRL_prep. The source code for performing learning is available at: /home/fenics/local/shape_optimization_DRL_prep/src. All necessary dependencies and packages in the correct version are already included, no more setup is needed.

For a more in-depth introduction to docker commands, and more explanations about how this container was built, see the discussions written for a similar project available at: https://github.com/jerabaul29/Cylinder2DFlowControlDRLParallel/blob/master/Docker/README_container.md .

How to start learning

It is recommended to use multiple terminals, or a multiplexer like tmux, in order to manage the simulation servers vs the training client.

python3 launch_servers.py -n 4 -p 1111

The -n argument corresponds to the number of available cores on your machine, while -p must be an available port (any four-digit number should be ok, feel free to change it if 1111 is taken on your machine).

python3 launch_parallel_training.py -p 1111 -n 4

Note that the number of servers and the first port value must match that used for starting the simulation servers.