Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:ARISE Initiative Robomimic Algo factory

From Leeroopedia
Knowledge Sources
Domains Robotics, Imitation_Learning, Offline_RL
Last Updated 2026-02-15 08:00 GMT

Overview

Concrete tool for creating algorithm instances from algorithm names and configuration objects provided by the robomimic algorithm module.

Description

The algo_factory function resolves an algorithm name to the appropriate algorithm class via a two-level registry lookup. It first calls algo_name_to_factory_func to get a factory function from REGISTERED_ALGO_FACTORY_FUNCS, then calls that factory function with the algorithm config to get the class and any extra kwargs. Finally, it instantiates the algorithm with all required parameters including observation shapes, action dimension, and device.

Usage

Call this function after dataset loading when you have the observation key shapes and action dimension from the dataset metadata. The returned algorithm instance is used for training (via train_on_batch) and evaluation (via RolloutPolicy wrapper).

Code Reference

Source Location

  • Repository: robomimic
  • File: robomimic/algo/algo.py
  • Lines: L54-86

Signature

def algo_factory(algo_name, config, obs_key_shapes, ac_dim, device):
    """
    Factory function for creating algorithms based on the algorithm name and config.

    Args:
        algo_name (str): the algorithm name

        config (BaseConfig instance): config object

        obs_key_shapes (OrderedDict): dictionary that maps observation keys to shapes

        ac_dim (int): dimension of action space

        device (torch.Device): where the algo should live (i.e. cpu, gpu)

    Returns:
        Algo: an algorithm instance (e.g., BC, BCQ, CQL) with constructed networks
    """

Import

from robomimic.algo import algo_factory

I/O Contract

Inputs

Name Type Required Description
algo_name str Yes Algorithm name (must match config.algo_name)
config BaseConfig Yes Full config object with algo, observation, and training settings
obs_key_shapes OrderedDict Yes Maps observation key names to their tensor shapes
ac_dim int Yes Action space dimension
device torch.Device Yes Compute device (CPU or CUDA)

Outputs

Name Type Description
algo Algo subclass Fully initialized algorithm (e.g., BC, BCQ, CQL, IQL, TD3_BC, DiffusionPolicyAlgo, GL, HBC, IRIS) with constructed neural networks on the specified device

Usage Examples

Standard Algorithm Creation

from collections import OrderedDict
import torch
from robomimic.algo import algo_factory

# Observation shapes from dataset
obs_key_shapes = OrderedDict(
    robot0_eef_pos=(3,),
    robot0_gripper_qpos=(2,),
)

# Create BC algorithm on GPU
model = algo_factory(
    algo_name="bc",
    config=config,
    obs_key_shapes=obs_key_shapes,
    ac_dim=7,
    device=torch.device("cuda:0"),
)

# Model is ready for training
model.set_train()

From Training Script

# In train.py, shapes come from dataset metadata
shape_meta = FileUtils.get_shape_metadata_from_dataset(
    dataset_path=config.train.data[0]["path"],
    all_obs_keys=config.all_obs_keys,
)

model = algo_factory(
    algo_name=config.algo_name,
    config=config,
    obs_key_shapes=shape_meta["all_shapes"],
    ac_dim=shape_meta["ac_dim"],
    device=device,
)

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment