Skip to content

CognacS/flagg-graphgen

Repository files navigation

FLAGG: Flexible Autoregressive Graph Generation

Requirements

The code was tested with Python 3.11.7. The requirements can be installed by following these steps:

  • Download anaconda/miniconda if needed
  • Create a new environment through the given environment files with the following command:
    conda env create -f <env_file>.yml
    where <env_file> is the name of the environment file to use. It is possible to install dependencies for CPU with environment_cpu.yml or for GPU with environment_cuda.yml.
  • Install this package with the following command:
    pip install -e .
    which will compile required cython and c++ code.

Experiments

Reproducibility

For CUDA>=10.2, to run any experiments in a reproducible way, it is necessary to set the environment variable:

    export CUBLAS_WORKSPACE_CONFIG=:4096:8

or in Windows, for cmd:

    set CUBLAS_WORKSPACE_CONFIG=:4096:8

for PowerShell:

    $env:CUBLAS_WORKSPACE_CONFIG=":4096:8"

and to remove:

    Remove-Item Env:\CUBLAS_WORKSPACE_CONFIG

Running experiments

Configurations are composed of:

  • a task, composed of a dataset and a test suite, defined by an assignment
  • a method, defined by a model, a trainer, a dataloader, a datatransform, and a set of callbacks
  • a logger, e.g., WandB or TensorBoard
  • a platform, defining the computational resources to use

Presets can be defined in the config/presets directory, and experiments can be run by using the following command:

    python main.py +preset=<preset> seed=<seed>

where <preset> is the name of the preset to use, and <seed> is the seed to use for the experiment. The seed is optional, and if not provided, the experiment will be run with a default seed. Experiments are always run with reproducibility.

The presets inside this repository are the configurations for running the experiment of the paper. The directory preset/ifh is for Vanilla FLAGG, the directory preset/sifh is for the Sparse FLAGG, and preset/mifh is for the Property FLAGG.

Adding options

To concatenate options to a preset (found in config/options), simply add the following to your python main.py command:

    +options=<option>

where <option> is the name of the option to use (the file's name minus the extension). Multiple options can be concatenated by adding +options=[<option1>,<option2>,...] to the command instead.

Loading a checkpoint produces bad results: label remapping

Due to a known issue installing new datasets, when running experiments with provided checkpoints please add:

    +options=remap_cls

to your python main.py command. This will remap the model's labels to the dataset ones. Not doing so will result in bad model performance, as model labels are not the same as dataset labels, thus producing nonsensical generations.

Diffusion jumps

To experiment with diffusion jumps (speeding up generation at the cost of performance), add the following to your python main.py command:

    +options=djump_<jump_size>

Empirical sampling of graph node numbers

To sample the number of nodes in generated graphs from the empirical distribution of the training set, instead of the insertion+halt mechanism, add the following to your python main.py command:

    +options=node_empirical

Saving generative traces/chains

To save the generative traces/chains of the model, add the following to your python main.py command:

    +options=save_chains

Datasets

Datasets will be downloaded automatically to a new directory ./datasets when running an experiment.

Checkpoints and logging

Checkpoints are saved in a new directory ./checkpoints, and logging can be done through TensorBoard or WandB, which requires a free account to be used.

Extending the code

The code can be extended by adding new datasets, test assignments, models, trainers, dataloaders, datatransforms, callbacks. The code is designed to be modular and easy to extend.

To register a new generator model it is sufficient to add a model file in the src/models directory (or any subdirectory), and to register the model using the @reg_models.register() decorator.

from src.models import reg_models
from src.models.generator import Generator

@reg_models.register()
class MyGraphGenerator(Generator):
    def __init__(
            self,

            my_configuration: Dict,

            ######## passed by configurator ######
            dataset_info: Dict = None,
            test_assignment: Assignment = None,
            console_logger: Logger = None
        ):
        super().__init__(
            dataset_info=dataset_info,
            test_assignment=test_assignment,
            console_logger=console_logger
        )

        self.model = MyModel(my_configuration)

        # save hyperparameters
        self.save_hyperparameters(ignore=Generator.IGNORED_HPARAMS)

    # implement other pytorch lightning methods
    def training_step(self, batch, batch_idx):
        # implement training step
        pass

    def sample(self, num_samples: int) -> List[Graph]:
        # implement sampling method
        pass

License

This code is released under the MIT License. See LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors