Skip to main content

🌊 Flow Gym : A Research Toolkit for Fluid Flow Estimation

Python 3.10+ GitHub stars PyPI version License: MIT uv

Flow Gym is a toolkit for research and deployment in flow quantification, inspired by OpenAI Gym and Stable-Baselines3. It leverages SynthPix for synthetic image generation and provides a unified interface for testing, training, and deploying learning-based algorithms that estimate fluid flow from sequences of tracer-particle images. The framework also includes a growing collection of integrated algorithms and stable JAX re-implementations of state-of-the-art methods.

The Flow Gym environment

✨ Features

  • Stable and reproducible environments Flow Gym provides FluidEnv, a unified environment for both supervised and reinforcement learning. It abstracts away infrastructure details and ensures consistent training and evaluation across experiments.

  • Unified estimator framework The Estimator API makes it easy to integrate, compare, and benchmark different flow estimation algorithms. It also supports extensions beyond velocity estimation — for example, pressure or tracer density — enabling ablation studies and cross-domain applications in fluid dynamics and control.

  • Ready for real-world deployment Flow Gym includes efficient JAX implementations of state-of-the-art flow estimation methods, optimized for real-time performance and suitable for closed-loop control or other fluid-sensing applications.

Getting Started 🚀

# Basic installation
uv add flow-gym-suite # or pip install flow-gym-suite

# With CUDA12 support
uv add "flow-gym-suite[cuda12]"

If you also want to use Flow Gym for training an evaluation, please clone the repository and install the development dependencies as outlined in the CONTRIBUTING.md page. There you can also find help if you have any issues installing Flow Gym.

Basic usage / Deployment 🧭

from flowgym.make import make_estimator
# Define the config (or load from YAML)
model_config = {
    "estimator": "dis_jax",
    "estimate_type": "flow",
    "config": {"jit": True, ..., },
}

# Create the estimator and associated functions
trained_state, create_state_fn, compute_estimate_fn, model = make_estimator(
    model_config=model_config,
    image_shape=image_shape
)

# Compute an estimate for an image pair
est_state = create_state_fn(prev)
new_est_state, metrics = compute_estimate_fn(curr, est_state)

Training a model 🧠

from flowgym.environment.fluid_env import FluidEnv

# Create the environment
env, env_state = FluidEnv.make(env_config)

for episode in range(num_episodes):
    obs, env_state, done = env.reset(env_state)
    est_state = create_state_fn(obs)
    train_step_fn = model.create_train_step()

    while not done.any():
        # Estimator forward pass
        est_state, metrics = compute_estimate_fn(obs, est_state, train_state)

        # Extract the action (the last estimate)
        action = estimation_state["estimates"][:, -1]
        # Environment step
        obs, env_state, reward, done = env.step(env_state, action)

        # Optimization step
        loss, train_state, _ = train_step_fn(
            est_state, train_state, reward
        )

Implementing a custom estimator 🧩

from flowgym.base import Estimator
class MyEstimator(Estimator):
    def init(self, rng, observation_space, action_space):
        # Initialize model parameters and state
        pass

    def _estimate(self, images, state, trainable_state, extras):
        # Define the forward pass of the model
        return new_state, extras, metrics

    def create_trainable_state(self, dummy_input, key):
        # Create the trainable state if needed (e.g., network structure, optimizer, etc.)
        pass

    def create_train_step(self):
        def train_step(self, estimation_state, trainable_state, rewards):
            # Define the training step (loss computation and optimization)
            return loss, new_trainable_state, metrics

Custom Preprocessing 🧼

# flowgym/common/preprocess.py
def custom_preprocess_validate_params(params: Dict[str, Any]) -> None:
    # Validate custom pre-processing parameters
    pass

def custom_preprocess(
    images: jnp.ndarray,
    params: Dict[str, Any]
) -> jnp.ndarray:
    # Implement custom pre-processing logic
    return processed_images

__all__ = [
    "custom_preprocess_validate_params",
    "custom_preprocess",
]

Custom Postprocessing 🎨

# flowgym/flow/postprocess/__init__.py
def custom_flow_postprocess_validate_params(params: Dict[str, Any]) -> None:
    # Validate custom post-processing parameters
    pass

def custom_flow_postprocess(
    estimates: jnp.ndarray,
    params: Dict[str, Any]
) -> jnp.ndarray:
    # Implement custom flow post-processing logic
    return processed_estimates

__all__ = [
    "custom_flow_postprocess_validate_params",
    "custom_flow_postprocess",
]

Examples 📚

For more examples, please check our training and evaluation scripts.

Contributing 🤗

Contributions are more than welcome! 🙏 Please check out our how to contribute page, and feel free to open an issue for problems and feature requests⚠️.

If you have developed a new method integrating with Flow Gym, please do open a PR! New methods should come with reproducible experiments showcasing the features. We collect these experiments in the folder experiments/your-method.

Citation 📈

If you use this code in your research, please cite our paper:

   @article{banelli2025flowgym,
      title={Flow Gym},
      author={Banelli, Francesco and Terpin, Antonio and Bonomi, Alan and D'Andrea, Raffaello},
      year={2025}
   }

License 📝

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for flow-gym-suite 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flow-gym-suite 0.1.0
File Size Uploaded Provenance Actions
flow_gym_suite-0.1.0.tar.gz 120.7 kB Without provenance Details for flow_gym_suite-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flow-gym-suite 0.1.0
File Interpreter ABI Platform Actions
flow_gym_suite-0.1.0-py3-none-any.whl Python 3 none any Details for flow_gym_suite-0.1.0-py3-none-any.whl

Total release size: 239.1 kB

Release files / flow_gym_suite-0.1.0.tar.gz

Download URL flow_gym_suite-0.1.0.tar.gz
Size 120.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d4866aee513bb8b0442583267e585d849607cda4a9ae7156b652a80250ee02e6
BLAKE2b-256 checksum
How to use checksums
e6f4ff4caf58245ade3cc00d23c31e935e91d6a0ed1ae3911fb375cbc4d67767
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / flow_gym_suite-0.1.0-py3-none-any.whl

Download URL flow_gym_suite-0.1.0-py3-none-any.whl
Size 118.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00f8e34b874354c1606e1956d49bbabb6d5f51485e1accd44a2f573196ec9089
BLAKE2b-256 checksum
How to use checksums
7c337b70aad6f700b62a9fa3334e77655da3d302e7d68f27cdac77aaa9fc4e3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for flow-gym-suite 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page