# google-deepmind/ferminet architecture

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

- Interactive diagram: https://gitdiagram.com/google-deepmind/ferminet
- Repository: https://github.com/google-deepmind/ferminet

## Overview

##### Main Components
- Configurations & Input: Represent the configuration system (using ml_collections) that loads various config files (e.g., under ferminet/configs/ and excited configurations) which govern the physics settings (atoms, molecules, basis sets, etc.) and training hyperparameters.
- Core Modules & Network Architecture: Highlight the main FermiNet algorithm. This includes:
– The neural network implementation (ferminet/networks.py and ferminet/psiformer.py) responsible for calculating the wavefunction.
– Supporting blocks (network_blocks.py), envelopes, and pseudopotentials.
- Monte Carlo Engine: Mark the components handling variational Monte Carlo sampling (mcmc.py), which produces “walkers” (configurations) used during training and inference.
- Physics Computation Modules: Indicate the modules performing physics evaluations like computing the Hamiltonian (hamiltonian.py, ferminet/pbc/hamiltonian.py) and observables (observables.py), including modules for density calculation and Jastrow factors.
- Utility and Auxiliary Components: Include helper modules found under utils (e.g., system.py, gto.py, statistical tools, writing outputs) and the constant/initialization files (constants.py, base_config.py).
- Testing & Notebooks: Although they are not part of the runtime system, note that tests (in tests/ directories) and notebooks (in ferminet/notebooks) serve as important artifacts for development and analysis.

##### Relationships and Interactions
- Model Training: Show the training process where the network architecture receives parameters and data (MCMC walkers) to iteratively update the wavefunction.
- Auxiliary Data: Highlight how external libraries (such as JAX for computation, ml_collections for configuration, and PySCF for molecular input) integrate into the workflow.

##### Architectural Patterns and Design Principles
- Configurability: Emphasize the flexible configuration system (using ml_collections) which leads to easy experimentation with different atomic/molecular systems.
- Extensibility & Testing: Indicate that additional configs (especially under excited states) and tests are included, enabling rapid experimentation and thorough verification.
- Integration with JAX: Mark the use of JAX (with pmap for multi-GPU support) as a key element supporting parallel computation and efficient hardware utilization.

##### Mention Relevant Technologies, Frameworks, and Libraries
- JAX (including jaxlib): For high-performance neural network training with automatic differentiation and GPU support.
- ml_collections: For managing hierarchical configuration.
- PySCF: For constructing molecular systems (used optionally for inference).
- NumPy: For handling large arrays in output and checkpoint data.
- Additional tools: pytest for testing and GitHub Actions (per the .github/workflows directory) for CI.

## Diagram (Mermaid)

```mermaid
graph TD
    CONFIG["Configuration System (ml_collections)"]:::config
    NN["Neural Network Module"]:::nn
    MCMC["Monte Carlo Sampler"]:::mc
    PHYS["Hamiltonian & Physics Calculations"]:::phys
    OUTPUT["Output & Checkpoint Management"]:::output
    UTIL["Utilities & Auxiliary Components"]:::util
    TEST["Testing & Analysis"]:::test

    %% Primary vertical flow
    CONFIG -->|"loads"| NN
    NN -->|"trains with"| MCMC
    NN -->|"provides input to"| PHYS
    MCMC -->|"supplies walkers to"| PHYS
    PHYS -->|"generates results for"| OUTPUT
    OUTPUT -->|"feeds"| TEST

    %% Utility support for multiple components
    UTIL -->|"supports"| CONFIG
    UTIL -->|"supports"| NN
    UTIL -->|"supports"| MCMC
    UTIL -->|"supports"| PHYS

    %% Styling definitions
    classDef config fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef nn fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef mc fill:#A3E4D7,stroke:#1ABC9C,stroke-width:2px;
    classDef phys fill:#F5B7B1,stroke:#CB4335,stroke-width:2px;
    classDef output fill:#D7BDE2,stroke:#AF7AC5,stroke-width:2px;
    classDef util fill:#F8C471,stroke:#BA4A00,stroke-width:2px;
    classDef test fill:#D5F5E3,stroke:#28B463,stroke-width:2px;

    %% Click Events for Configuration & Input
    click CONFIG "https://github.com/google-deepmind/ferminet/tree/main/ferminet/configs/"
    click CONFIG "https://github.com/google-deepmind/ferminet/blob/main/ferminet/base_config.py"

    %% Click Events for Neural Network Engine
    click NN "https://github.com/google-deepmind/ferminet/blob/main/ferminet/networks.py"
    click NN "https://github.com/google-deepmind/ferminet/blob/main/ferminet/psiformer.py"
    click NN "https://github.com/google-deepmind/ferminet/blob/main/ferminet/network_blocks.py"

    %% Click Event for Monte Carlo Sampler
    click MCMC "https://github.com/google-deepmind/ferminet/blob/main/ferminet/mcmc.py"

    %% Click Events for Hamiltonian Calculator & Physics Modules
    click PHYS "https://github.com/google-deepmind/ferminet/blob/main/ferminet/hamiltonian.py"
    click PHYS "https://github.com/google-deepmind/ferminet/blob/main/ferminet/pbc/hamiltonian.py"
    click PHYS "https://github.com/google-deepmind/ferminet/blob/main/ferminet/observables.py"
    click PHYS "https://github.com/google-deepmind/ferminet/blob/main/ferminet/jastrows.py"

    %% Click Events for Utility & Auxiliary Components
    click UTIL "https://github.com/google-deepmind/ferminet/tree/main/ferminet/utils/"
    click UTIL "https://github.com/google-deepmind/ferminet/blob/main/ferminet/utils/system.py"
    click UTIL "https://github.com/google-deepmind/ferminet/blob/main/ferminet/utils/gto.py"
    click UTIL "https://github.com/google-deepmind/ferminet/blob/main/ferminet/utils/statistics.py"
    click UTIL "https://github.com/google-deepmind/ferminet/blob/main/ferminet/utils/writers.py"
    click UTIL "https://github.com/google-deepmind/ferminet/blob/main/ferminet/constants.py"

    %% Click Event for Checkpoints & Output Management
    click OUTPUT "https://github.com/google-deepmind/ferminet/blob/main/ferminet/checkpoint.py"

    %% Click Events for Testing & Analysis Notebooks
    click TEST "https://github.com/google-deepmind/ferminet/tree/main/ferminet/tests/"
    click TEST "https://github.com/google-deepmind/ferminet/blob/main/ferminet/notebooks/excited_states_analysis.ipynb"
```
