mihirkatare / DeepMEM

Deep Learning Implementations for Sustainable Matrix Element Method Calculations [ IRIS-HEP Fellowship ]
Apache License 2.0
2 stars 0 forks source link

DeepMEM

GitHub Project NSF Award Number

PyPI version Supported Python versions

pre-commit.ci status Code style: black

This repository contains the code that was used for the IRIS-HEP Fellowship project: Deep Learning Implementations for Sustainable Matrix Element Method Calculations.

IRIS-HEP Fellowship Presentation: Deep Learning for the Matrix Element Method, Mihir Katare, 18 Oct 2021, Recording: Deep Learning for the Matrix Element Method


Project Description

The Matrix Element Method (MEM) is a powerful statistical analysis technique for experimental and simulated particle physics data. It has several benefits over black-box methods like neural networks, owing to its transparent and interpretable results. The drawback of MEM; however, is the significant amount of computationally intensive calculations involved in its execution, which impedes research that relies on it. This project aims to improve the viability of MEM, by implementing deep learning techniques to accurately and efficiently approximate MEM calculations - providing the much required speedup over the traditional approach, while preserving its interpretability. The implemented model can be used as a good approximation during the exploratory phase of research, and the full ME calculations can be used for the final runs, making the workflow for research involving MEM much more efficient.


Installation

From PyPI

deepmem is distributed on PyPI and can be installed in your Python virtual environment with pip

$ python -m pip install deepmem

From version control

deepmem can also be installed from source by cloning a version of this repository and then from the top level of the repository locally installing in your Python virtual environment with pip

$ python -m pip install .

Developers will probably want to create an editable install so their code changes are automatically picked up without having to reinstall

$ python -m pip install --editable .

Requirements for deployment

The code is stable in python 3.8.5. Use the requirements.txt file to install the dependencies using pip or package installer of choice.


Explanation of inputs

To run this code simply run deepmem with the required shell arguments and input file modifications.

The code takes two types of inputs:

Examples:

Go through the input file at input_files/input.json and modify the paths to the data, where to save and load models, scalers, etc. Then run the following code to train the model on the options in the input_files/input.json using the 0th numbered CUDA GPU for 50 epochs:

$ deepmem --device=0 --epochs=50 --mode=train

Thereafter run the following code to run the testing phase once again using the options in the input_files/input.json using the 0th numbered CUDA GPU for inference:

$ deepmem --device=0 --mode=test

It should save a histogram with a visual explanation of the model performance in post/histogram.png (path can be changed in input file)

Shell Arguments Explanation:

$ deepmem --help
usage: deepmem [-h] [--loader LOADER] [--device DEVICE] [--epochs EPOCHS] [--inputfile INPUTFILE] [--mode MODE]

optional arguments:
  -h, --help            show this help message and exit
  --loader LOADER
  --device DEVICE
  --epochs EPOCHS
  --inputfile INPUTFILE
  --mode MODE           'train' or 'test'

Pass these to deepmem when running the code.

  1. --loader: [Default: hybridMT] Which dataloader implementation to use out of [inbuilt, hybrid, hybridMT] AT THE MOMENT ONLY hybridMT is properly supported. It loads all the data into memory and can be use for reasonably sized datasets (works comfortably with ~300k events on DGX)

  2. --device: [Default: None] Which numbered cuda device to use for training. Using None will select the CPU instead (Not recommended)

  3. --epochs: [Default: 10] Number of epochs to train for

  4. --inputfile: [Default: input_files/input.json] Path to the input file

  5. --mode: [Default: train] Whether to run in training mode or testing mode

Input File Options Explanation:

for example: If prefixes are [ ["lep1"] , ["lep2", "j1_"] , ["MET"] ] and suffixes are [ ["PT"] , ["PT", "Eta"] , ["", "_Phi"]] the dataloader wil load the following variables from the input file lep1_PT, "lep2_PT, lep2_Eta, j1_PT, j1_Eta, MET, MET_Phi. It is basically all combinations of prefixes and suffixes from lists at the same index.