What are Ocean environments?
Ocean environments are RL environments that:- Run in C/CUDA: Core simulation logic is implemented in C or CUDA, not Python
- Scale massively: Support thousands to millions of parallel agents per environment
- Minimize overhead: Observations and actions are written directly to shared memory buffers
- Integrate seamlessly: Expose a standard Gymnasium-compatible Python interface
Performance
Ocean environments achieve 1M-10M+ steps per second on a single CPU core
Scalability
Run thousands of environments in parallel with minimal memory overhead
Flexibility
Custom C bindings allow arbitrary simulation complexity
Compatibility
Standard Gymnasium API works with any RL framework
Architecture
Ocean environments use a unique architecture that separates Python interface from simulation logic:Python wrapper
A lightweight Python class (
pufferlib.PufferEnv) handles the Gymnasium API and manages shared memory buffers for observations, actions, rewards, and terminals.C binding layer
The
env_binding.h template provides standardized functions for environment initialization, stepping, rendering, and cleanup. Each environment implements required callbacks.Simulation core
Pure C/CUDA code implements the actual environment logic. This code has zero Python dependencies and operates directly on memory buffers.
Performance characteristics
Ocean environments achieve exceptional performance through several key optimizations:Zero-copy memory sharing
Observations and actions are stored in NumPy arrays backed by shared memory. C code writes observations directly to these buffers without any copying or serialization:Minimal Python overhead
The Python wrapper is extremely thin - just a few lines per step:Efficient vectorization
Multiple environments run in parallel with minimal overhead:Batch processing
All environments step simultaneously in a single C function call:Typical performance
Benchmark results on a modern CPU (single core):| Environment | Agents | Steps/second | Notes |
|---|---|---|---|
| Cartpole | 4,096 | 5M | Simple dynamics |
| Snake | 4,096 | 10M | Optimized grid |
| Asteroids | 4,096 | 3M | Collision detection |
| Breakout | 1,024 | 2M | Rendering enabled |
| Battle | 512 × 1024 | 1M | Complex multi-agent |
Performance varies by environment complexity and hardware. GPU-based environments (CUDA) can achieve even higher throughput.
C/CUDA optimization benefits
Compared to pure Python environments, Ocean environments provide: 10-1000x speedup over naive Python implementations- Eliminates Python interpreter overhead
- Enables SIMD vectorization and compiler optimizations
- Reduces memory allocations and garbage collection
- No garbage collection pauses
- Predictable memory usage
- Scales linearly with cores
- Smaller memory footprint per environment
- Efficient cache utilization
- Better CPU utilization
When to use Ocean environments
Ocean environments are ideal for:Large-scale training
Training with millions of environment steps per update
Rapid iteration
Quick experiments with fast turnaround times
Benchmarking
Standardized high-performance test environments
Custom simulations
Building new environments that need maximum speed
Example usage
Next steps
Browse environments
See all available Ocean environments and their features
Create custom environments
Learn how to build your own high-performance C environments