{"id":14529878,"url":"https://github.com/sisl/deep_flow_control","last_synced_at":"2025-09-13T11:20:54.259Z","repository":{"id":83919928,"uuid":"154720940","full_name":"sisl/deep_flow_control","owner":"sisl","description":"Source code for \"Deep Dynamical Modeling and Control of Unsteady Fluid Flows\" from NeurIPS 2018","archived":false,"fork":false,"pushed_at":"2018-12-03T21:13:22.000Z","size":10465,"stargazers_count":49,"open_issues_count":0,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-09-02T01:33:45.826Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sisl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-25T18:46:00.000Z","updated_at":"2025-06-08T15:03:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"eb404a28-350e-4998-a5f6-0b781899dac7","html_url":"https://github.com/sisl/deep_flow_control","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sisl/deep_flow_control","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisl%2Fdeep_flow_control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisl%2Fdeep_flow_control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisl%2Fdeep_flow_control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisl%2Fdeep_flow_control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sisl","download_url":"https://codeload.github.com/sisl/deep_flow_control/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisl%2Fdeep_flow_control/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274955743,"owners_count":25380669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-05T00:01:03.162Z","updated_at":"2025-09-13T11:20:54.202Z","avatar_url":"https://github.com/sisl.png","language":"Python","funding_links":[],"categories":["Fluid"],"sub_categories":[],"readme":"# Deep Flow Control\nSource code for \"Deep Dynamical Modeling and Control of Unsteady Fluid Flows\" from NIPS 2018. The paper can be found [here](https://arxiv.org/pdf/1805.07472.pdf).\n\n\n![](gifs/vortex.gif)\n\n\n## Overview\nA description of the individual files is given below.\n### ```training``` Directory\n* ```koopman_model.py``` - script for defining architecture of and constructing Deep Koopman models for training.\n* ```train_koopman.py``` - training script for Deep Koopman models.\n* ```bayes_filter.py``` - script for defining architecture of and constructing Deep Variational Bayes Filter models.\n* ```train_bayes_filter.py``` - training script for Deep Variational Bayes Filter models.\n* ```dataloader.py``` - script for loading and processing data prior to training.\n* ```utils.py``` - contains functions for evaluating trained models.\n* ```find_matrices.py``` - script to load a trained neural network model and determine the B-matrix, action normalization parameters, and goal state encoding.\n* ```find_dynamics.py``` - script to load a trained neural network model and output the current state encoding and the A-matrix based on the previous sequence of observed states and actions.\n\n### ```mpc_files``` Directory\n* ```config.ini``` - example config file that defines parameters for a PyFR simulation of the 2D cylinder system. Relevant parameters that may need to be modified can be found in the ```soln-plugin-controller``` section.\n* ```controller.patch``` - patch that can be applied to PyFR to allow for prescribing an angular velocity on the surface of the cylinder and performing model predictive control.\n* ```mesh.pyfrm``` - mesh file required to run simulation of 2D cylinder system.\n* ```cyl-2d-p2-1530.pyfrs``` - solution file that can be used to initialize simulations of the 2D cylinder system.\n* ```base.h5``` - snapshot of steady base flow that defines the goal state in model predictive control.\n* ```loc_to_idx.json``` - JSON file containing a map from spatial locations in full CFD solutions to indices in the arrays used as neural network inputs.\n\n## Getting Started\nBelow we detail the steps required to install the necessary software, generate training data, train a Deep Koopman model, and perform model predictive control.\n\n### Software Installation\n#### Python Environment\nDeep Flow Control depends on both [TensorFlow](https://www.tensorflow.org/install/) and [PyFR](http://www.pyfr.org) which require python 3.5 to work properly. The training code depends on python 2.7 so it is easiest to manage different python environments using [conda](https://www.anaconda.com/download/). Once conda is installed, you can create the two needed python environments by\n\n```\nconda create -n py27 python=2.7 anaconda\nconda create -n py35 python=3.5 anaconda\n```\n\nWhen installing PyFR or tensorflow start by activating the python 3.5 environment\n```\nsource activate py35\n```\n\n#### PyFR Installation\nDeep Flow Control requires [PyFR v1.7.6](https://github.com/vincentlab/PyFR/releases/tag/v1.7.6). Once downloaded, copy ```controller.patch``` into the top-level directory of PyFR and run ```git apply controller.patch``` to modify the PyFR code in order to enable simulation with control inputs. This patch will create a file named ```controller.py``` in the ```pyfr/plugins``` directory that contains the necessary code for defining control laws and performing model predictive control.\n\nAfter applying the patch, PyFR can be installed by navigating to the PyFR directory and running\n```\npython setup.py build\npython setup.py install\n```\n\n#### TensorFlow Installation\nTensorflow can be installed via `pip install tensorflow` or `pip install tensorflow-gpu`\n\n\n\n### Generating Training Data\nOnce PyFR has been successfully installed, simulations can be run in order to generate training data. Move the files ```config.ini```, ```mesh.pyfrm```, ```cyl-2d-p2-1530.pyfrs```, and ```loc_to_idx.json``` to the same directory. Modify ```config.ini``` and ```controller.py``` as desired. Direct the python path to include the training files by adding the following to your ```.bashrc``` or ```.bash_profile``` file\n\n```\nexport PYTHONPATH=$PYTHONPATH:/path/to/deep_flow_control/training\n```\n\nTo generate the training data run the command\n\n```pyfr restart -bcuda -p mesh.pyfrm cyl-2d-p2-1530.pyfrs config.ini```\n\nto begin a simulation using the CUDA backend (OpenCL and OpenMP are also available as backends). Training data will be saved to the directory ```save_dir```, as defined in ```config.ini ``` but make sure the directory already exists.\n\n### Training a Model\nThe scripts in the ```training``` directory can be used to train a Deep Koopman model. Navigate to the directory containing the scripts\n```\ncd path/to/deep_flow_control/training\n```\nBefore executing the scripts, make sure to switch to python 2.7 with\n```\nsource activate py27\n```\n\nExamine ```train_koopman.py``` to get a sense for the arguments that can be used to define the model architecture. An example command to train a Deep Koopman model is:\n\n```python train_koopman.py --num_filters 256 128 64 32 16 --control_input True --data_dir (data_dir)```\n\nwhere ```(data_dir)``` is the directory where training data has been stored. By default checkpoints will be written to a directory named ```./checkpoints```.\n\n### Running MPC\nOnce you have a trained model, modify the arguments in ```config.ini``` to perform model predictive control. In particular, you will need to set ```mpc = 1```, change ```training_path``` to be the path to the directory where the training scripts are located, modify ```checkpoint``` to correspond to the desired model checkpoint, and change ```base_flow``` to contain the correct path to the file ```base.h5```. From this point, simulations can be run with the same command used to generate the training data. Make sure to activate python 2.7 before running PyFR with model predictive control.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsisl%2Fdeep_flow_control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsisl%2Fdeep_flow_control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsisl%2Fdeep_flow_control/lists"}