Package: agent-torch
Differentiable agent-based learning for million-scale populations - inside the body, around us and beyond.https://github.com/AgentTorch/AgentTorch/assets/13482350/4c3f9fa9-8bce-4ddb-907c-3ee4d62e71481. InstallationDownloadThe simplest way to install AgentTorch is from PyPi at:pip install agent-torchTo get the latest version of AgentTorch, you can install it directly from git at:pip install git+https://github.com/AgentTorch/AgentTorch2. SetupHardwareThe code has been tested for macOS Catalina 10.1.7 and Ubuntu 22.04.2 LTS. Large-scale experiments are run using NVIDIA TITANX GPU and V100 GPU.DependenciesStep 1: Create a virtual environmentagent_torch_env. We recommend using python 3.8 and pip as the install.python3.8 -m venv agent_torch_env
source agent_torch_env/bin/activateTo install python3.8, follow these tutorials forMacandUbunturespectively. To install pip, follow these tutorials forMacandUbunturespectively.Step 2: Install pytorch and pytorch geometric. We recommend using Pytorch 2.0 and corresponding Pytorch geometric bindings. We recommend following the guides foroffical pytorch installandofficial pytorch-geometric install. We summarize the commands below:Mac:# CUDA is not available on MacOS, please use default package
pip install torch torchvision torchaudio
pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_convUbuntu:pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/${CUDA}
pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.0.0+${CUDA}.htmlwhere ${CUDA} is the CUDA version. We have tested our code on cu118.Step 3: Install AgentTorch specific dependencies as below:cd AgentTorch
pip3 install -r requirements.txt3. AgentTorch overviewCreating a new simulator using AgentTorch involves the following steps:Defining the configuration: Here we define the variables and functions to be used in the simulator. In this module aConfiguratorobject is to be created to which the variables and functions to be used in the simulator are added as properties. These are then used to instantiate aRunnerobject. An example for this can be found innca_simulator.py.Defining the trainer: This module loads the configuration, the various variables and functions that form the substeps and executes the main simulation and learning loop. Any learning related loss and optimization function need to be defined here. An example for this can be found in "models/nca/trainer.py"Defining substeps: As described in the figure above, each simulation comprises of multiple substeps. Each substep comprises of the following four functions: observation, action, transition and reward. Each of these need to be defined in a separate module, using the base classes forSubstepObservation,SubstepTransition,SubstepPolicyprovided insubstep.py. Since these functions need to be differentiable, we provide several differentiable utilities inhelpers_soft.py. These can be used to create differentiable variants of operations such as maximum, logical comparison etc. An example for substep definition can be found innca_evolve.py,covid_quarantine.pyUsing helpers: AgentTorch has several useful functions defined inhelpersthat can be used in defining the various functions. These include library of utilities to support differentiability of substeps, loading public data sources such as from US census and, initialization of state properties and environment networks. For instance,helpers_soft.pyinclude differentiable utilities andhelpers_general.pyincludes uitilies for data reading and writing.A detailed code specific documentation is provided increate model docs4. Running examplesYou can run a sample experiment with the following command:cd models/nca
python trainer.py --c config.yamlcd models/opinion
python trainer.py --c config.yaml5. Starter GuideGenerate and Interpretconfig.yamlfileAn interactive notebook with step-by-step guide to define and understand aconfig.yamlis given inconfig_example_docs.Build your own AgentTorch modelA step-by-step guide to start a new AgentTorch project is given instarter documentation6. IssuesThe AgentTorch project is under active development and are continually fixing issues. Please feel free to leave a comment atTroubleshooting issuesCitationIf you use this project or code in your work, please cite it using the following BibTeX entry:@inproceedings{chopra2024framework,
title = {A Framework for Learning in Agent-Based Models},
author = {Chopra, Ayush and Subramanian, Jayakumar and Krishnamurthy, Balaji and Raskar, Ramesh},
booktitle = {Proceedings of the 23rd International Conference on Autonomous Agents and Multi-agent Systems},
year = {2024},
organization = {International Foundation for Autonomous Agents and Multiagent Systems},
}