Giter VIP home page Giter VIP logo

fenics-drl's Introduction

fenics-DRL :

Repository from the paper A review on Deep Reinforcement Learning for Fluid Mechanics.

List of other repo. with CFD + DRL (if your code is not here, please feel free to make a pull request)

(Explanatations on how to use the code are below)

Fenis + DRL https://github.com/DonsetPG/fenics-DRL
Flow Control of the 2D Kármán Vortex Street with Deep Reinforcement Learning https://github.com/jerabaul29/Cylinder2DFlowControlDRL
Accelerating Deep Reinforcement Learning strategies of Flow Control through a multi-environment approach https://github.com/jerabaul29/Cylinder2DFlowControlDRLParallel
Deep Reinforcement Learning control of the unstable falling liquid film https://github.com/vbelus/falling-liquid-film-drl
Direct shape optimization through deep reinforcement learning https://github.com/jviquerat/drl_shape_optimization
Fluid directed rigid ball balancing using Deep Reinforcement Learning https://github.com/sahilgupta2105/Deep-Reinforcement-Learning
Efficient collective swimming by harnessing vortices through deep reinforcement learning https://github.com/cselab/smarties
Training an RL agent to swim at low Reynolds Number https://github.com/RpDp-git/LearningToSwim-DQN

How to use the code :

Install everything :

CFD :

We used Fenics for this project. The easiest way to install it is by using Docker. Then :

docker run -ti -v $(pwd):/home/fenics/shared -w /home/fenics/shared quay.io/fenicsproject/stable:current

should install Fenics.

DRL :

We are using both Gym - OpenAI and Stable-Baselines. They both can installed with :

pip install gym 
pip install stable-baselines

More generally, everything you need can be installed with :

pip install --user tensorflow keras gym stable-baselines sklearn

Launch an experiment :

An experiment consists of an Environement (based on Gym - OpenAI & Fenics), and an Algorithm from Stable-Baselines. They can be launched with test_main.py. You will only have to precise a few parameters :

*nb_cpu*: the amount of CPU you want to use (e.g. 16)
*agents*: an array of the algorithms you want to use (e.g. ['PPO2','A2C'])
*name_env*: The name of the environment (e.g. 'Control-cylinder-v0')
*total_timesteps*: the amount of timesteps the training will last (e.g. 100000)
*text*: Some precisions you wanna add to you experiment (e.g. '1_step_1_episode_2CPU')

Build your own environment :

The Gym.env environment :

You can find examples of such environments in example 1 : Control Cylinder or example 2 : Flow Control Cylinder. They always share the same architecture :

class FluidMechanicsEnv_(gym.Env):
    metadata = {'render.modes': ['human']}

    def __init__(self,
                    **kwargs):
        ...
        self.problem = self._build_problem()
        self.reward_range = (-1,1)
        self.observation_space = spaces.Box(low=np.array([]), high=np.array([]), dtype=np.float16)
        self.action_space = spaces.Box(low=np.array([]), high=np.array([]), dtype=np.float16)
        
    def _build_problem(self,main_drag):
        ...
        return problem
        
        
    def _next_observation(self):
        ...
        
        
    def step(self, action):
        ...
        return obs, reward, done, {}
    
    def reset(self):
        ...

Here, most of these functions are DRL related, and more informations can be found at this paper (for applications of DRL on fluid mechanics) or here (for more general informations about DRL). The only link with Fenics is made with the

def _build_problem(self,main_drag):
        ...
        return problem

function, where you will be using functions from Fenics.

Fenics functions :

We built several functions to help you use Fenics and build DRL environment with it. Three main classes exist :

  • class Channel
  • class Obstacles
  • class Problem

Channel :

Allows you to create the 'box' where your simulation will take place.

Obstacles :

Allows you to add forms and obstacles (Circle, Square and Polygons) to your environment.

Problem :

Build the simulation with Channl and Obstacles. Also get parameters for the mesh and the solver. Finally, this is a Problem object you will return in the Gym.env class.

What's next :

We built this repository in order to get a code as clean as possible for fluid mechanics with DRL. However, Fenics is not the best solver, especially with very demanding problem. The goal is to keep the same philosophy in mind (DRL and Fluid mechanics coupled easily) but with other (and faster) libraries. Since most of these libraries are C++ based, and using powerful clusters, the architecture will be completely different. We are still working on it and doing our best to release an alpha version as soon as possible.

This repository will be updated when such library finally comes out. Until then, we hope that with this paper and this repository combined, some Fluid Mechanics researcher might want to try to apply Deep Reinforcement Learning to their experiments.

The Team :

fenics-drl's People

Contributors

donsetpg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fenics-drl's Issues

No matching distribution found for ale-py~=0.7.5; extra == "atari" (from gym[atari])

Hi @DonsetPG
Thank you for your sharing.I met some errors while using pip install stable-baselines,which was run in fenics dockers images.

ERROR: Could not find a version that satisfies the requirement ale-py~=0.7.5; extra == "atari" (from gym[atari]) (from versions: 0.6.0.dev20200207) ERROR: No matching distribution found for ale-py~=0.7.5; extra == "atari" (from gym[atari])

Negative drag values while training

Hi,

I've recently started using RL to fluid problems. So please excuse for naive questions. While training the value of drag force is coming negative using fenics. Then how come Cd graph is plotted with the positive value? Can you elaborate

Thanks

Some confusions about control_cylinder.py

Hi @DonsetPG

My coding skills are not very good.There are a few things in https://github.com/DonsetPG/fenics-DRL/blob/master/examples/control_cylinder.py that I don't understand:
1.In line 67 super(FluidMechanicsEnv, self).__init__(),There‘s no FluidMechanicsEnv,I guess you want to call FluidMechanicsEnv_;
2.In line 148 '''problem = Problem(render=self.render,
filename =filename,
min_bounds=(-5,-5),
max_bounds=(20,5),
types='Rectangle',
size_obstacles=nb_obstacles,
coords_obstacle = obstacles,
size_forms=1,
coords_forms = forms,
size_mesh = 100,
cfl=5,
final_time=10)'''has an input named coords_forms = forms,which can’t be found in class Problem from
https://github.com/DonsetPG/fenics-DRL/blob/master/deepfluid/fenics/fenics_domains.py. May be it‘s included in **kwargs

TypeError: can't pickle dolfin.cpp.geometry.Point objects

I met the following error when I used python3 test_main.py to lauch an experiment:

Traceback (most recent call last): File "test_main.py", line 27, in <module> launch_training(nb_cpu,name_agent,name_env,total_timesteps,text) File "/home/jzz/fenics-DRL/examples/training_control_cylinder.py", line 118, in launch_training env = SubprocVecEnv([lambda: env_ for i in range(n_cpu)]) File "/home/jzz/.local/lib/python3.7/site-packages/stable_baselines/common/vec_env/subproc_vec_env.py", line 103, in __init__ process.start() File "/home/jzz/anaconda3/envs/drl/lib/python3.7/multiprocessing/process.py", line 112, in start self._popen = self._Popen(self) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/multiprocessing/context.py", line 291, in _Popen return Popen(process_obj) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/multiprocessing/popen_forkserver.py", line 35, in __init__ super().__init__(process_obj) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/multiprocessing/popen_fork.py", line 20, in __init__ self._launch(process_obj) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/multiprocessing/popen_forkserver.py", line 47, in _launch reduction.dump(process_obj, buf) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/multiprocessing/reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj) File "/home/jzz/.local/lib/python3.7/site-packages/stable_baselines/common/vec_env/base_vec_env.py", line 331, in __getstate__ return cloudpickle.dumps(self.var) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/site-packages/cloudpickle/cloudpickle_fast.py", line 102, in dumps cp.dump(obj) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/site-packages/cloudpickle/cloudpickle_fast.py", line 633, in dump return Pickler.dump(self, obj) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 437, in dump self.save(obj) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/site-packages/cloudpickle/cloudpickle_fast.py", line 815, in save_function *self._dynamic_function_reduce(obj), obj=obj File "/home/jzz/anaconda3/envs/drl/lib/python3.7/site-packages/cloudpickle/cloudpickle_fast.py", line 757, in _save_reduce_pickle5 save(state) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 771, in save_tuple save(element) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 856, in save_dict self._batch_setitems(obj.items()) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 882, in _batch_setitems save(v) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 771, in save_tuple save(element) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 549, in save self.save_reduce(obj=obj, *rv) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 638, in save_reduce save(args) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 771, in save_tuple save(element) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 549, in save self.save_reduce(obj=obj, *rv) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 662, in save_reduce save(state) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 856, in save_dict self._batch_setitems(obj.items()) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 882, in _batch_setitems save(v) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 549, in save self.save_reduce(obj=obj, *rv) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 662, in save_reduce save(state) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 856, in save_dict self._batch_setitems(obj.items()) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 882, in _batch_setitems save(v) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 549, in save self.save_reduce(obj=obj, *rv) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 662, in save_reduce save(state) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 856, in save_dict self._batch_setitems(obj.items()) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 882, in _batch_setitems save(v) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 549, in save self.save_reduce(obj=obj, *rv) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 662, in save_reduce save(state) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 856, in save_dict self._batch_setitems(obj.items()) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 882, in _batch_setitems save(v) File "/home/jzz/anaconda3/envs/drl/lib/python3.7/pickle.py", line 524, in save rv = reduce(self.proto) TypeError: can't pickle dolfin.cpp.geometry.Point objects

Here are the informations about my systerm:

Ubuntu 20.04.5 LTS \n \l

cat /proc/cpuinfo| grep "processor"| wc -l
12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.