1 unstable release
| 0.0.8 | May 17, 2025 |
|---|
#1846 in Machine learning
245KB
3.5K
SLoC
A wrapper for Minari environments.
This crate provides a Rust interface for Minari datasets, which are collections of offline reinforcement learning data. It allows users to load and interact with Minari datasets in a way that is compatible with the Border framework.
Features
- Dataset Loading: Load Minari datasets from disk or from the Minari registry.
- Environment Interaction: Interact with the loaded datasets using the Border environment interface.
- Data Access: Access observations, actions, rewards, and other data from the datasets.
Example
The following example demonstrates how to:
- Load a D4RL Kitchen dataset
- Create a replay buffer from a specific episode
- Recover the environment state
- Replay the actions from the dataset
This is particularly useful for:
- Analyzing expert demonstrations
- Testing environment behavior
- Validating dataset quality
- Reproducing recorded trajectories
use border_core::Env;
use border_minari::{d4rl::kitchen::ndarray::KitchenConverter, MinariDataset};
fn main() -> Result<()> {
// Load the D4RL Kitchen dataset
let dataset = MinariDataset::load_dataset("D4RL/kitchen/complete-v1", true)?;
// Create a converter for handling observation and action types
let mut converter = KitchenConverter {};
// Create a replay buffer containing only the sixth episode
let replay_buffer = dataset.create_replay_buffer(&mut converter, Some(vec![5]))?;
// Recover the environment state from the dataset
// The 'false' parameter indicates not to use the initial state
// 'human' indicates the agent type
let mut env = dataset.recover_environment(converter, false, "human")?;
// Get the sequence of actions from the replay buffer
let actions = replay_buffer.whole_actions();
// Reset the environment and replay the actions
env.reset(None)?;
for ix in 0..actions.action.shape()[0] {
let act = actions.get(ix);
let _ = env.step(&act);
}
Ok(())
}
The example uses the following key components:
KitchenConverter: Handles conversion between Python and Rust types for the Kitchen environmentMinariDataset: Manages the dataset and provides methods for data accessEnv: The Border environment interface for interaction
Integration with Border
This crate implements the Env trait from border-core, making it compatible with other Border components
such as agents, policies, and trainers. It can be used in both online and offline reinforcement learning scenarios.
Dependencies
~8–21MB
~248K SLoC