# danijar/dreamerv3 architecture

> Architecture diagram of the GitHub repository danijar/dreamerv3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danijar/dreamerv3
- Repository: https://github.com/danijar/dreamerv3

## Overview

##### Project Type & Purpose
- This is a reinforcement learning (RL) project that implements the DreamerV3 algorithm, which learns world models from experience and uses them to train an actor-critic policy using imagined trajectories.
- The README and file tree indicate that it is a research/reimplementation project that emphasizes scalability, data efficiency, and the application of a world model across diverse environments.

##### Main Components
- RL Agent & World Model:
- The core learning components reside in the “dreamerv3” directory (files like agent.py, main.py, rssm.py and a configs.yaml). This contains the logic for the RL agent and the world model (recurrent state-space model, prediction, etc).
- Environment Interfaces:
- The “embodied/envs” directory contains various environment wrappers (for Atari, DMC, Minecraft, and others) that simulate the different domains on which the agent is trained.
- Core Functionalities:
- The “embodied/core” directory holds core libraries for driver, replay buffers, random utilities, limiters, selectors, streams, and wrappers that are common to running and training the RL algorithms.
- JAX-specific Tools:
- “embodied/jax” contains modules for agent logic, network definitions, optimizers, transformation functions, and other JAX utilities, which are central for GPU/TPU-based computations.
- Training & Evaluation Routines:
- The “embodied/run” directory provides scripts for training, evaluation, parallel execution, and continuing training runs.
- Performance and Testing:
- “embodied/perf” and “embodied/tests” contain performance benchmarks and unit tests to ensure each component’s reliability.
- Deployment & Build:
- The Dockerfile, entrypoint.sh, and related configuration files (e.g., requirements.txt, setup.py) enable containerized deployment and dependency management.

##### Architectural Patterns & Design Principles
- Modularity: The clear separation between environment wrappers, core utilities, JAX computations, and training routines speaks to high modularity.
- Configurability: Use of YAML configuration files (e.g., configs.yaml) along with command-line overrides indicates a flexible, configurable architecture.
- Scalability: The project supports multiple platforms (GPU, CPU, TPU) and environments, and the design supports parallel training and evaluation in embodied/run/parallel.
- Testing & Performance: Built-in tests (under embodied/tests) and performance scripts (under embodied/perf) emphasize a test-driven approach to performance and correctness.

##### Relevant Technologies
- Python 3.11+ is required.
- JAX: for fast numerical computations especially for neural networks and gradient-based learning.
- Docker: to containerize the environment for consistent reproducibility.
- Additional libraries as indicated in requirements.txt (which might include libraries for machine learning, data processing, plotting, etc.)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Core"
        A["Agent & World Model\n(dreamerv3)"]:::agent
        E["Environment Interfaces\n(embodied/envs)"]:::env
        C["Core Utilities\n(embodied/core)"]:::core
        J["JAX Computation Layer\n(embodied/jax)"]:::jax
        T["Training & Evaluation\n(embodied/run)"]:::train
    end

    subgraph "Testing & Performance"
        PB["Performance Benchmarks\n(embodied/perf)"]:::perf
        UT["Unit Tests\n(embodied/tests)"]:::perf
    end

    subgraph "Deployment & Build"
        D1["Docker & Entrypoint\n(Dockerfile, entrypoint.sh)"]:::deploy
        D2["Dependencies & Setup\n(requirements.txt, setup.py)"]:::deploy
    end

    %% Connections within Application Core
    E -->|"provides_experience"| A
    A -->|"uses"| C
    A -->|"computes_with"| J
    T -->|"orchestrates"| A
    C -->|"supports"| T

    %% Connections to Testing & Performance
    T -->|"monitored_by"| PB
    A ---|"tested_by"| UT
    C ---|"tested_by"| UT

    %% Connections to Deployment & Build
    T -->|"containerized_by"| D1
    T -->|"configured_by"| D2

    %% Click Events
    click A "https://github.com/danijar/dreamerv3/tree/main/dreamerv3/"
    click E "https://github.com/danijar/dreamerv3/tree/main/embodied/envs/"
    click C "https://github.com/danijar/dreamerv3/tree/main/embodied/core/"
    click J "https://github.com/danijar/dreamerv3/tree/main/embodied/jax/"
    click T "https://github.com/danijar/dreamerv3/tree/main/embodied/run/"
    click PB "https://github.com/danijar/dreamerv3/tree/main/embodied/perf/"
    click UT "https://github.com/danijar/dreamerv3/tree/main/embodied/tests/"
    click D1 "https://github.com/danijar/dreamerv3/tree/main/Dockerfile"
    click D2 "https://github.com/danijar/dreamerv3/blob/main/requirements.txt"

    %% Styles
    classDef agent fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef env fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef core fill:#ffffcc,stroke:#666600,stroke-width:2px;
    classDef jax fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef train fill:#ffe6cc,stroke:#994d00,stroke-width:2px;
    classDef perf fill:#e6f2ff,stroke:#003366,stroke-width:2px;
    classDef deploy fill:#e6e6e6,stroke:#333333,stroke-width:2px;
```
