Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Re-structure the documentation #341

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ playground/
!docs/requirements-docs.txt
.DS_Store
docs/_build/
logs
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ gflownet is a library built upon [PyTorch](https://pytorch.org/) to easily train
In a nutshell, GFlowNets can be regarded as a generative model designed to sample objects $x \in \mathcal{X}$ proportionally to a reward function $R(x)$. This results in the potential of sampling diverse objects with high rewards. For example, given the reward landscape depicted below, defined over a two-dimensional space, a well-trained GFlowNet will be able to sample from the four high-reward corners with high probability.

<p align="center">
<img width="400" src="docs/images/reward_landscape.png" />
<img width="400" src="docs/source/figures/reward_landscape.png" />
</p>

GFlowNets rely on the principle of **compositionality** to generate samples. A meaningful decomposition of samples $x$ into multiple intermediate states $s_0\rightarrow s_1 \rightarrow \dots \rightarrow x$ can yield generalisable patterns. These patterns can then be learned by neural networks trained to model the value of transitions $F_{\theta}(s_t \rightarrow s_{t+1})$.

Consider the problem of generating [Tetris](https://en.wikipedia.org/wiki/Tetris)-like boards. A natural decomposition of the sample generation process would be to add one piece at a time, starting from an empty board. For any state representing a board with pieces, we could identify its valid parents and children, as illustrated in the figure below.

<p align="center">
<img width="400" src="docs/images/tetris_flows.png" />
<img width="400" src="docs/source/figures/tetris_flows.png" />
</p>

We could define a reward function $R(x)$ as the number of cells occupied by pieces, for instance. The goal of training a GFlowNet on this task would be to discover (sample) diverse solutions (boards with pieces) with high rewards. This represents an intuitive yet complex problem where GFlowNets can be used, which is [implemented in this library](https://github.com/alexhernandezgarcia/gflownet/blob/ahg/313-update-readme-components/gflownet/envs/tetris.py). Many problems in scientific discoveries, such as the inverse design of proteins, molecules, or crystals share similarties with this intuitive task.
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
SOURCEDIR = source
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
Expand Down
3 changes: 0 additions & 3 deletions docs/_static/css/custom.css

This file was deleted.

10 changes: 0 additions & 10 deletions docs/index.rst

This file was deleted.

1 change: 1 addition & 0 deletions docs/source/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated/
22 changes: 22 additions & 0 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.sidebar-container {
width: 20em !important;
}

.sidebar-brand img {
display: block;
margin: 0 auto 0.5rem auto;
padding-top: 1rem;
width: 80%;
height: auto;
}

/* To make toctree captions bold */
.caption .caption-text {
font-weight: bold;
}

/* To change the color of the first title on the page */
.article-container>article>section>h1 {
color: #904e3d;
/* Example: Google blue */
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
API Reference
Package Reference
=============

This page contains auto-generated API reference documentation [#f1]_ for the ``gflownet`` package.
Expand Down
3 changes: 3 additions & 0 deletions docs/source/advanced/stack_enviroments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Stacked Enviroment
===================
This tutorial demonstrates how to use more than one enviroments one time or what we call stacked enviroments...
6 changes: 3 additions & 3 deletions docs/conf.py → docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
ROOT = Path(__file__).resolve().parent.parent.parent
sys.path.insert(0, str(ROOT))

# -- Project information -----------------------------------------------------
Expand Down Expand Up @@ -70,8 +70,8 @@
html_css_files = [
"css/custom.css",
]
html_favicon = "./_static/images/gflownet-logo-32.png"

html_favicon = "./_static/images/gflownet-logo.png"
html_logo = "./figures/reward_landscape.png"
# -----------------------------
# ----- Plugins configs -----
# -----------------------------
Expand Down
File renamed without changes
5 changes: 5 additions & 0 deletions docs/source/get_started/colabs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Colab Notebooks and Video Tutorials
============

List of tutorials
-----------------
39 changes: 39 additions & 0 deletions docs/source/get_started/introduction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Introduction by Example
=======================

Welcome to the introduction of **gflownet**, a library designed to facilitate training and extending Generative Flow Networks (GFlowNets) for a wide range of applications, especially in scientific discovery. GFlowNets provide a framework for probabilistic and generative modeling.

What are GFlowNets?
-------------------

Generative Flow Networks, or GFlowNets, are a type of generative model that sample objects $x \in \mathcal{X}$ proportionally to a reward function $R(x)$. This framework is particularly suited for applications where the goal is to generate diverse high-reward samples, such as in scientific discovery.

.. image:: ../figures/reward_landscape.png
:align: center
:width: 400
:alt: Reward landscape

The model learns to transition between states in a way that the frequency of generating any given state is proportional to its reward. For instance, a GFlowNet trained on a 2D space with four high-reward areas would learn to sample those areas more frequently.

Compositionality and Sampling
------------------------------

GFlowNets utilize compositionality by decomposing samples $x$ into sequences of intermediate states, such as:

.. image:: ../figures/tetris_flows.png
:align: center
:width: 400
:alt: Tetris flows

In the example of generating Tetris-like boards, each board configuration is built by adding one piece at a time, starting from an empty board. Each intermediate state has potential "parents" and "children," forming a directed graph over states, where each edge (transition from one state to another) is modeled and learned.


Key Components
--------------

**gflownet** comprises several core components essential for its operation:

- **Environment**: Defines the state and action spaces for tasks, such as the Tetris or Scrabble environments.
- **Proxy**: Manages the reward function logic, essential for evaluating states.
- **Policy Models**: Neural networks that model the transitions between states.
- **GFlowNet Agent**: Orchestrates interactions between the environment, policies, and proxy, among other functions.
30 changes: 30 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
GFlowNets Documentation
======================

Welcome to the documentation for **gflownet**, a library built upon `PyTorch <https://pytorch.org>`_ to facilitate training and extending Generative Flow Networks (GFlowNets) for a wide range of applications, particularly in scientific discovery problems.

.. toctree::
:maxdepth: 2
:caption: Install gflownet

install/installation

.. toctree::
:maxdepth: 2
:caption: Get Started

get_started/introduction
get_started/colabs

.. toctree::
:maxdepth: 2
:caption: Tutorials

tutorials/grid_enviroment
tutorials/add_enviroment

.. toctree::
:maxdepth: 2
:caption: Advanced Concepts

advanced/stack_enviroments
75 changes: 75 additions & 0 deletions docs/source/install/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Installation
============

This section provides detailed instructions on how to install **gflownet**. Ensure your system meets the following requirements before proceeding with the installation.

Requirements
------------

* **Python Version:** Python 3.10 is required.
* **CUDA Version:** CUDA 11.8 is needed for GPU acceleration.
* **Operating System:** The setup is primarily supported on Ubuntu. The installation may work on OSX with manual handling of package dependencies.

Quick Installation
------------------

For a quick installation, clone the repository and execute the setup script:

.. code-block:: bash

git clone [email protected]:alexhernandezgarcia/gflownet.git
cd gflownet
./setup_all.sh

Detailed Installation
---------------------

If you prefer a more controlled installation or need to customize the environment, follow these steps:

1. **Create a Virtual Environment:**

.. code-block:: bash

python3.10 -m venv ~/envs/gflownet # Initialize your virtual environment.

2. **Activate the Virtual Environment:**

.. code-block:: bash

source ~/envs/gflownet/bin/activate # Activate your environment.

3. **Install Ubuntu Prerequisites:**

.. code-block:: bash

./prereq_ubuntu.sh # Installs some packages required by dependencies.

4. **Install Python Prerequisites:**

.. code-block:: bash

./prereq_python.sh # Installs Python packages with specific wheels.

5. **Optional: Install Geometric Dependencies:**

.. code-block:: bash

./prereq_geometric.sh # OPTIONAL - for the molecule environment.

6. **Install gflownet:**

.. code-block:: bash

pip install .[all] # Install the remaining elements of this package.

Optional Packages
-----------------

You can also install additional optional packages tailored for specific functionalities:

* **Development Tools:** Install with `dev` tag.
* **Materials Science Dependencies:** Install with `materials` tag.
* **Molecular Environment Packages:** Install with `molecules` tag.

The `all` tag installs all dependencies, which is the simplest and recommended option if you require full functionality.

2 changes: 2 additions & 0 deletions docs/source/tutorials/add_enviroment.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
How to add custom enviroment
============
2 changes: 2 additions & 0 deletions docs/source/tutorials/grid_enviroment.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Grid Enviroment tutorial
============
10 changes: 0 additions & 10 deletions docs/tutorial.rst

This file was deleted.

2 changes: 1 addition & 1 deletion prereq_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ python -m pip install --ignore-installed six appdirs
python -m pip install torch==2.0.1
python -m pip install dgl==1.1.3+cu118
python -m pip install dglgo==0.0.2
python -m pip install pyg_lib==0.3.1 torch_scatter==2.1.2 torch_sparse==0.6.18 torch_geometric==2.4.0 torch_cluster==1.6.3 torch_spline_conv==1.2.2 -f https://data.pyg.org/whl/torch-2.0.0+cpu.html
python -m pip install pyg_lib==0.3.1 torch_scatter==2.1.2 torch_sparse==0.6.18 torch_geometric==2.4.0 torch_cluster==1.6.3 torch_spline_conv==1.2.2 -f https://data.pyg.org/whl/torch-2.0.0+cpu.html
Loading