Skip to content

Instantly share code, notes, and snippets.

@matthewfeickert
Last active October 7, 2019 02:34
Show Gist options
  • Save matthewfeickert/d1509ce6108d127ec10f807e5080b6f7 to your computer and use it in GitHub Desktop.
Save matthewfeickert/d1509ce6108d127ec10f807e5080b6f7 to your computer and use it in GitHub Desktop.
MG5aMC_PythonMEs Minimal Working Example

MG5aMC_PythonMEs Minimal Working Example

Kyle notified people over email and Twitter that Valentin Hirschi had gotten MadGraph to export matrix element codes for Feynman diagrams into a form that can be used by differentiable machine learning libraries (e.g., TensorFlow and PyTorch). The project is called MG5aMC_PythonMEs. This is a short walkthrough of doing the simplest possible thing: just running the code that MG5aMC_PythonMEs generates. As I don't have much experience with MadGraph5_aMC@NLO and its installation and use instructions are quite bad I threw together a Docker image that at leasts somewhat works. This walkthrough will use that.

To be clear, this is never how you would actually do anything with a Docker image. This is just throwing things against the wall at the moment.

Pull the Docker image

Get the Docker image I made from the Docker Hub image registry

docker pull matthewfeickert/madgraph5-amc-nlo

Run the Docker container interactively with a local volume mount

I'm assuming you're in the directory of this Gist, so just volume mount locally

docker run --rm -it -v $PWD:/home/docker/data matthewfeickert/madgraph5-amc-nlo:latest /bin/bash

then inside the container navigate to the PLUGIN directory of the MG5_aMC_v2_6_6 installation and clone the repo from GitHub (here using HTTPS instead of SSH as I don't want to bother getting SSH agent forwarding for this)

cd ~/MG5_aMC_v2_6_6/PLUGIN/
git clone https://github.com/ValentinHirschi/MG5aMC_PythonMEs.git

A missing required dependency is NumPy, and while in this very early stage example Tensorflow isn't actually required, as Valentin notes:

TF which is for now identical in behaviour to Python but uses daughter classes and templates ready to be specialised for TensorFlow (see README.md)

we'll install Python 2.7 compatible versions of both using the requirements.txt in the Gist that we have access to through the volume mount as this is an application and not a library

cd ..
pip install --user -r ~/data/requirements.txt

Running the Examples

Now from the top level directory of the MG5_aMC_v2_6_6 installation we can run the examples given in the README of Valentin's repo. First generating the Python 2.7 example

./bin/mg5_aMC --mode=MG5aMC_PythonMEs PLUGIN/MG5aMC_PythonMEs/test_MG5aMC_PythonMEs.mg5

and then running it

python2 MG5aMC_PythonMEs_output_example/check_sa.py

and then moving it to the local volume for a later reference

cp -r MG5aMC_PythonMEs_output_example ~/data/

Then running the TensorFlow + Python 2.7 example (which again, isn't different at the moment)

./bin/mg5_aMC --mode=MG5aMC_PythonMEs PLUGIN/MG5aMC_PythonMEs/test_MG5aMC_TFMEs.mg5
python2 MG5aMC_TFMEs_output_example/check_sa.py
cp -r MG5aMC_TFMEs_output_example ~/data/

If you were to now exit the container you would still have the two directories with scripts locally that you can poke at with your favorite editor. These are now truly standalone modules it seems, as you can exit the container and then run the Python 2.7 release container

docker run --rm -it -v $PWD:/home -w /home python:2.7 /bin/bash

get the minimal dependencies again (we'll just skip to only getting NumPy for the sake of time)

pip install --user numpy

and then you're able to run the scripts again

python2 MG5aMC_PythonMEs_output_example/check_sa.py
python2 MG5aMC_TFMEs_output_example/check_sa.py
numpy~=1.16
tensorflow~=1.14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment