Giter Site home page Giter Site logo

bonsai-cstr's Introduction

Continuous Stirred Tank Reactor (CSTR) sample

Project Bonsai code sample demonstrating chemical process optimization in a continuous stirred tank reactor (CSTR). Efficient control of an exothermic, non-linear chemical reaction with a CSTR is a benchmark in which to compare PID, MPC and Bonsai brains.

For an overview of this sample, watch Chemical Reactor Optimization with Microsoft Project Bonsai.

The chemical process here considers a transition from low to high conversion rate (high to low residual concentration). Because the chemical reaction is exothermic (produces heat), the reactor temperature must be controlled to prevent a thermal runaway. The control task is complicated by the fact that the process dynamics are nonlinear and transition from stable to unstable and back to stable as the conversion rate increases. The reactor dynamics are modeled in Simulink. The controlled variables (states) are the residual concentration and the reactor temperature, and the manipulated variable (action) is the temperature of the coolant circulating in the reactor's cooling jacket.

CSTR Schematic

This example shows how to use Project Bonsai's Machine Teaching strategies to learn a controller for a chemical reactor transitioning from low to high conversion rate. For background, see Seborg, D.E. et al., "Process Dynamics and Control", 2nd Ed., 2004, Wiley, pp. 34-36. This sample is largely adapted from the MathWorks': Gain scheduled control of a chemical reactor.

Adapative PI Control

Simulink PID

Bonsai Brain Control

Model Integration

Actions (Manipulated Variables)

Bare minimum for the sim (all units are continuous):

Action Range Units
dTc [-20, 20] [Kelvin]

Final set for Bonsai training:

Note: Performance improved when making the brain learn the per-timestep adjustment to apply to previous dTc. Control is maintained with the addition of dTc_adjust, and an accumulator was added on the simulator side.

Action Continuous Value Units
dTc_adjust [-5, 5]* [Kelvin/min]

Note: given an additional rule that requires keeping dTc changes at no more than 10 Kelvins/min, we forced dTc_adjust to be on the [-5, 5] range (for Ts=0.5min)

States (Control Variables)

Which matches the set of Observable States used for bonsai training

State Continuous Value Units
Cr [0.1, 12] [kmol/m3]
Tr [10, 800] [Kelvin]
Tc [10, 800] [Kelvin]
Cref [0.1, 12] [kmol/m3]

Note, the .ink file defines ranges higher than the ones shown here. That is made on purpose since the brain will try to explore, and thus will hit extreme limits in doing so.

Tref was removed as observable state since brain to simplify brain training. With Bonsai's solution, Tref is not needed to be able to drive the concentration linearly between points.

Constraints

  • Tc < 10 degrees / min
  • Tr < 400 to prevent thermal runaway

Model Overview and Instructions

Please open the MATLAB livescript, Chemical_Process_Optimization.mlx, for further descriptions and instructions for getting started with this sample.

Project

This repo has been populated by an initial template to help get you started. Please make sure to update the content to build a great experience for community-building.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

bonsai-cstr's People

Contributors

defeirst avatar jralexander avatar microsoft-github-operations[bot] avatar microsoftopensource avatar scotstan avatar scottstanfield avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bonsai-cstr's Issues

CSTR 1.5 punchlist

Using the pythonsim branch for now.

  • Single conda environment.yml file on python 3.10.1 for all
  • Add new CSTR simulator running in Python (to parallel the Simulink version)
  • Linear and Non-linear MPC controllers for baseline on Python sim
  • Spec for common results.csv file to compare
  • Strategy to train four distinct brains to support: modular-, modular-brain-ml, modular-brain-mpc, monolithic-brain
  • Choose graphics path: GIF from do_mpc vs animation using matplotlib
  • Decouple run-time graphics from results generation (for batch scripts)
  • Batch drive the entire benchmark suite
  • Test against CSTR 1.0 suite
  • Parameterize --noise=0.01 or use ENV across the samples

Consider tech edits to README per MSFT contributor accessibility guidelines

prefer active vs passive (passive adds cognitive noise)
one idea per sentence
no pronouns (this, that, you, we, rarely "it")
"you" best in side-bars "you might get an error if..."
no gender pronouns (he, she, they); prefer roles "the systems engineer"
avoid possessive (ESL)
avoid contractions (It's, hadn't)
avoid posessives (ESL, unique to English?) (Its)

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.