Skip to main content

Hadronic Interaction Model interface in Python

Project description


Cosmic ray and HadROnic interactiOn MOnte-carlo frontend

This package implements are generic user interface to popular event generators used in cosmic ray and high-energy particle physics. The purpose of the package is to simplify working with simulations of particle interactions without the need to use Fortran style interfaces to event generators, 'ASCII input cards' and files or C++ dependencies.

Simulate interactions with one of the supported event generators

import numpy as np
import chromo

# Define the parameters of the collisions
kinematics = chromo.kinematics.CenterOfMass(
    13 * chromo.constants.TeV,
    "proton", "proton")
# Create an instance of an event generator
generator = chromo.models.Sibyll23d(kinematics)

nevents = 0
average_pt = 0

# Generate 10000 events
for event in generator(10000):
    # Filter event
    event = event.final_state_charged()
    # do something with event.pid, event.eta, event.en, event.pt, etc.
    # these variables are numpy arrays, that can be histogrammed or counted like
    pt = event.pt[np.abs(event.pid) == 211]
    # The list could be empty
    if len(pt) > 0:
        nevents += 1
        average_pt += np.mean(pt)

average_pt = average_pt / nevents
print("Average pT for charged pions {0:4.3f}".format(average_pt))

Supported models

  • DPMJET-III 3.0.6 & PHOJET 1.12-35
  • DPMJET-III 19.1 & PHOJET 19.1
  • DPMJET-III 19.3 & PHOJET 19.3
  • EPOS-LHC
  • PYTHIA 6.4
  • PYTHIA 8.3
  • QGSJet-01
  • QGSJet-II-03
  • QGSJet-II-04
  • SIBYLL-2.1
  • SIBYLL-2.3
  • SIBYLL-2.3c
  • SIBYLL-2.3d
  • SOPHIA 2.0
  • UrQMD 3.4

Installation

Supported platforms

  • Python 3.8+
  • Linux, Mac OS X, Windows

From PyPI (not yet available)

pip install chromo

The package will be available as a pre-compiled binary wheels in the future, but for now you have to compile it from source, see next subsection.

From source

Installation from source requires a Python installation setup for development, as well as C/C++ and Fortran compilers.

To build from source (the recursive flag is important to check out submodules):

git clone --recursive https://github.com/impy-project/chromo
cd chromo
pip install --prefer-binary -v -e .

This takes a while. The command installs the package in editable mode (for developing the Python layer) and with verbose output, so that you can watch the compilation happening. Warnings can be ignored, but watch out for errors. Pip automatically creates a virtual environment and downloads dependencies for the build, prefering to install binary wheels of older versions of dependencies if the most recent version has no binary wheel, so you don't have to compile dependencies as well.

To run the tests or try the examples, use this modified pip install instead:

pip install --prefer-binary -v -e .'[test,examples]'

which installes chromo and additional optional Python packages that are used in the tests and examples, but not required to run chromo.

For developers

If you want to work on the Fortran sources, it is more convenient to install a development version of Chromo with setuptools.

python setup.py develop

You need to install the build environment manually for this to succeed. Check the key [build-system.requires] in pyproject.toml which packages are required.

Unlike the pip command, this command reuses build artefacts that were previously generated, so you don't have to recompile everything every time. Another convenience for developers is the optional file models.cfg. If it exists, only models are build which are listed there. See default_models.cfg for the full list.

Known issues

If you cannot fix the installation with these hints, please look into the subsection below which explains how to install in chromo in a verified docker environment. The docker environment has a properly set up environment verified by us, so that the installation is guaranteed to succeed.

From source in Docker

This guide works on Linux and OSX. You need a running Docker server. Please google how to set up Docker on your machine.

# download chromo
git clone --recursive https://github.com/impy-project/chromo
cd chromo

# download linux image for x86_64 or see below
docker pull quay.io/pypa/manylinux2014_x86_64

# For aarch64 or VM on Apple Silicon use the following image and
# replace the end of the next command accordingly.
# docker pull quay.io/pypa/manylinux2014_aarch64

# create docker instance and bind chromo directory
docker run --rm -d -it --name chromo -v "$(pwd)":/app quay.io/pypa/manylinux2014_x86_64

# enter your docker instance
docker exec -it chromo /bin/bash

cd /app

# select python version, e.g. 3.9, and enter virtual environment
python3.9 -m venv venv
source venv/bin/activate

# install chromo and dependencies (prefer binary wheels for deps)
pip install --prefer-binary -v -e .

You can now use chromo inside the docker instance. If you run Linux, you can also make a wheel inside docker and install it in your host.

# inside docker
pip install wheel
python setup.py bdist_wheel

# exit docker with ctrl+D
pip install dist/*.whl

This should allow you to use chromo also outside docker. This works only if you use the same Python version inside and outside of docker.

User interface

There are two ways to interact with the code.

  1. As in the example above, via plain python in scripts or Jupyter notebooks. Look at this example.

  2. Via a HEPMC output that can be piped in Rivet or other tools supporting the format.

Running tests

Some notes regarding tests.

  • Tests are run in parallel by default with pytest-xdist. To disable this, use the option -n 0.
  • The test test_generators takes a long time. You can skip it with the option -k "not test_generators".
  • Tests which run a model do so in a separate process, because most models can only be instantiated once. This prevents using --pdb to start the debugger at the point of failure. You can prefix the pytest call like this DEBUG=10 python -m pytest ... to run the model in the current process. This will only work once for each model and lead to failures afterwards.

Authors

  • Anatoli Fedynitch
  • Hans Dembinski
  • Anton Prosekin
  • Sonia El Hadri
  • Keito Watanabe

LICENSE

The source code of chromo is licensed under the BSD 3-clause license (see LICENSE for detail). The source codes of the event generators are individually licensed under different conditions (see the COPYING files located in the subdirectories).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chromo-0.3.0rc1.tar.gz (71.8 MB view details)

Uploaded Source

Built Distributions

chromo-0.3.0rc1-cp311-cp311-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.11 Windows x86-64

chromo-0.3.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

chromo-0.3.0rc1-cp311-cp311-macosx_11_0_arm64.whl (22.4 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

chromo-0.3.0rc1-cp311-cp311-macosx_10_9_x86_64.whl (25.1 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

chromo-0.3.0rc1-cp310-cp310-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.10 Windows x86-64

chromo-0.3.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

chromo-0.3.0rc1-cp310-cp310-macosx_11_0_arm64.whl (22.4 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

chromo-0.3.0rc1-cp310-cp310-macosx_10_9_x86_64.whl (25.1 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

chromo-0.3.0rc1-cp39-cp39-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

chromo-0.3.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

chromo-0.3.0rc1-cp39-cp39-macosx_11_0_arm64.whl (22.4 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

chromo-0.3.0rc1-cp39-cp39-macosx_10_9_x86_64.whl (25.1 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

chromo-0.3.0rc1-cp38-cp38-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

chromo-0.3.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

chromo-0.3.0rc1-cp38-cp38-macosx_10_9_x86_64.whl (25.1 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

Details for the file chromo-0.3.0rc1.tar.gz.

File metadata

  • Download URL: chromo-0.3.0rc1.tar.gz
  • Upload date:
  • Size: 71.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for chromo-0.3.0rc1.tar.gz
Algorithm Hash digest
SHA256 4e0c8fb9024489ebb007c1bb0c985bc80f788f6f5b54561ced70b87181fe3d5d
MD5 0762272465671b65dc1aa6ae4b719097
BLAKE2b-256 ccd151146454b75d64d88d7d12f4cfb15144accd88b75a14ba9b4f5570134054

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7e43e79da131f4a8ff178dd1f29e2870d15b25925161baf0a1ddfe7a61f48c8a
MD5 b4924b2ee30a31b8f0e27a6cf5bcc5f4
BLAKE2b-256 0e5db4352661bf60822f316846162941a25075c58ac1a23685fd2a04e861022c

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b1b216777c16fcd7998718f25c9a25af23f7429273251bd352f26e794f1a663f
MD5 19c1f2ee6e256d480015648349f0b01d
BLAKE2b-256 1dca73edc162c8edc9c4ce6b4186a64fdfe40a44c0a67b58ec12b5dd65c691bf

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fef5c341a451ad3e8aa764693cb411f893eec1c15b331fd508d392dca5ead269
MD5 3bb7f836ca78ddb7cef102d41c06ec9c
BLAKE2b-256 fe2371ad07e67e49e85830b5d35df9efe14296d9be2ab080ece717128fc94353

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9849fe4861234bccf05968fe2a95eba769751e19ddb01fcce2f860d4e02e72e8
MD5 f6ec5be81e967cfaa513af38f1c08d5e
BLAKE2b-256 afd129505d25e13b8d56d6bd29ef48b9bced1478f15fc8a6499f17d224ed70cf

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 38da6c0451172554b79130132e856d6bba499e455214f7f80d7f32a604c31286
MD5 1268fe70451f287cb7895a915418ecff
BLAKE2b-256 9164cb4f6cb9c78ec29c63c3bf722b743a1026940a1b2c2391d9f06192f0c168

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05099b496636c9b98d43b51024ead444632e23b790e375a0bc5e1f40bc0a2609
MD5 78a59431a5e2ad5fdbe1c974d5a5f125
BLAKE2b-256 8336ac90478ae2069b85553cbc670d722d812144ef26552d681fccfd01b8e91d

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd1efd85787b32dc92bf446ffd0786c2e8b4c53cc83f336ae76372148f827bec
MD5 1ddf60f1db1318575a0a952402cb96eb
BLAKE2b-256 ccca2b8a9d5688715346c2ae80de7ffa992f46fba372ea7767e8d8c76458016e

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2d6c3848c601dcd3ff948c18ae306420c28b8ee1b44632c662c6123d72a887a3
MD5 2e339882d2abd1947d5dcb3fbba61e2d
BLAKE2b-256 cf7d261b46932c5ca5feb5b516a69b4032bb7e619d9c430cd105db3f835fac60

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: chromo-0.3.0rc1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 19.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for chromo-0.3.0rc1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2c4673e982833b7bf18f2a6dc6531a13033a7162dada9efbb1b20d36fc0e3dbf
MD5 8932acda7d54b2ff0927d7df6b5fbdce
BLAKE2b-256 e5fab3299d83ac0a00df038715090dc9ed14b237f51bf8c3e96b97eddab47db9

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5666044914a583a07054b5b5d691a8c8bf32496e8d0f4323c942da3dd5c85a6e
MD5 a422b8802700ebdff18130f29284d55e
BLAKE2b-256 67407087dec32b7f231d80cf9ce0866def5dd24833ef8ce003e1638929cf0d26

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2269df314ad088fd825ff9d4146dcec87ae5b1000a62870207edf1c24e9ae47c
MD5 35ccabbf0edc393ed87302d808f6f3ed
BLAKE2b-256 75b724c7a0572d1384337a4139ded02d38c195dd1ae85a311c61548fd77ab7a8

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 be988727dd85add9fae8b69a1940cbfc71da0925e970bd60eca5e3fc42c38b5c
MD5 12da6205f1ff66c141467675b812ed4d
BLAKE2b-256 83fd2dedd1850bd8fbe54d389a3678c7b3e0716b65e7dc05f65b3afd722a8796

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: chromo-0.3.0rc1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 19.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for chromo-0.3.0rc1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 7d48c31c5c0a3444e0855a5fe9886e9354bd97d06697eccd08f073067845dd4a
MD5 2983e5c8c440821b544253ae522b7781
BLAKE2b-256 5ecf286a2a29254afcd9fac981a3f8998fa4a507b926fff92591a91e6d2295d2

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee8f14ba2ff754b17cc1c9dc739e9345d73ed28f2a1c06f6b50792cb18244a20
MD5 1258e79e204ba0ac94d0c79a975105ad
BLAKE2b-256 302d332e343ff940d92445623185f4a5f96618af4f55c83b9e1a71c1d2bd8146

See more details on using hashes here.

File details

Details for the file chromo-0.3.0rc1-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for chromo-0.3.0rc1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0268286428db87e64ad79a19cbfc81b81048a3148fadd092e70467e59bab3045
MD5 6d92cc3de90b7fdf956bf3d42dfba970
BLAKE2b-256 6ec3c0ee41bab37adffad4fd071658c76ce70e6296b204b8acb622b7db46351a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page