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:
where <env_file> is the name of the environment file to use. It is possible to install dependencies for CPU with
conda env create -f <env_file>.yml
environment_cpu.ymlor for GPU withenvironment_cuda.yml. - Install this package with the following command:
which will compile required cython and c++ code.
pip install -e .
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:8or in Windows, for cmd:
set CUBLAS_WORKSPACE_CONFIG=:4096:8for PowerShell:
$env:CUBLAS_WORKSPACE_CONFIG=":4096:8"and to remove:
Remove-Item Env:\CUBLAS_WORKSPACE_CONFIGConfigurations are composed of:
- a
task, composed of adatasetand atestsuite, defined by an assignment - a
method, defined by amodel, atrainer, adataloader, adatatransform, and a set ofcallbacks - 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.
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.
Due to a known issue installing new datasets, when running experiments with provided checkpoints please add:
+options=remap_clsto 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.
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>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_empiricalTo save the generative traces/chains of the model, add the following to your python main.py command:
+options=save_chainsDatasets will be downloaded automatically to a new directory ./datasets when running an experiment.
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.
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
passThis code is released under the MIT License. See LICENSE file for details.