A package for reinforcement learning in physics simulations
Project description
Physics-rl
Physics-rl allows users to easily train tensorflow agents using reinforcement learning in environments simulated using FENiCSx.
This library provides the following functionalities:
- Tools to handle a mix of distributed computation and single-node computation (Coordinator and Coordinated classes and
@parallel
decorator). - Ready to use simulation of two physical environments governed by the heat diffusion equation (HeatEnvironment class) and by a monodomain Mitchell-Schaeffer model (MonodomainMitchellSchaeffer class).
- A class that handles data collection and training using user-provided agents and environments with reasonable opinionated defaults (Dojo class).
Coordination system
Any class that needs to run distributed FENiCSx computation should inherit from Coordinated and the methods that need to be run on all processes should be marked with the @parallel
decorator. The result is a class that can be used in the leader process as if it was running in a single process (thus allowing compatibility with tf-agent's ecosystem), while still running on all processes the necessary computations.
All processes should have a Coordinator instance; in most cases there should be exactly one per process. All instances inheriting from Coordinated must be registered in the Coordinator, the corresponding instances of the same class in different processes are registered in a common namespace (the namespace can be manually set, but in most cases it is inferred automatically). This allows a function call in an instance in the leader process to be replicated on the correct instances in the follower processes.
The typical usage of the library is as follows
coordinator = Coordinator()
env = System(coordinator) # System inherits from Coordinated and PyEnvironment
with coordinator:
if coordinator.is_leader():
env = tf_py_environment.TFPyEnvironment(env)
q_net = QNetwork(env.observation_spec(), env.action_spec())
dojo = Dojo(q_net, env)
dojo.train(100)
Check out the file example_dojo_fenics.py
for a complete example of how the library can be used.
Setup
- Uninstall MPI if you have already installed it (in some cases it conflicts with conda's MPI installation)
- Create environment
conda create --name physicsrl python==3.10
conda activate physicsrl
- install dolfinx following the official instructions
conda install -c conda-forge fenics-dolfinx mpich pyvista
- install the other dependencies
pip install -r requirements.txt
Compatibility
Python 3.9 or more recent is required.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file physicsrl-1.0.0.tar.gz
.
File metadata
- Download URL: physicsrl-1.0.0.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f232aea20272f89a902941aa8d38fbc3a2548c0a4093a73c348fcb4f437308f |
|
MD5 | 0161d761aef292a88f58aa4f697fbbd8 |
|
BLAKE2b-256 | 3dc85479e4664c804b15cf002d5d2eeb6463008f92cf87c3fd2098e046552b52 |
File details
Details for the file physicsrl-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: physicsrl-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ad26d203dee989aab73a79f3d797fe36273007570b09a1d587b691fa3cf67ed |
|
MD5 | 50f08458862a5877334d57d19323b0a4 |
|
BLAKE2b-256 | 578081375bf1f99f7709c1b75384d10a71ec8fa8c01c2634aa620641b58625e0 |