Skip to content

Commit

Permalink
Merge pull request #52 from zfit/flake8
Browse files Browse the repository at this point in the history
style: enforce flake8 and prettier
  • Loading branch information
redeboer authored May 28, 2021
2 parents 47fa84b + 4e685a0 commit 22cdd81
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 121 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

name: tests

on: [ push ]
on: [push]

jobs:
codecov:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ 3.8 ]
python-version: [3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -38,7 +38,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.6, 3.7, 3.9 ]
python-version: [3.6, 3.7, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
47 changes: 23 additions & 24 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@

name: Build and deploy

on: [ push ]
on: [push]

jobs:
build_deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install setuptools wheel twine
- name: Install pep517
run: >-
pip install pep517
- name: Build a binary wheel and a source tarball
run: >-
python -m
pep517.build --source --binary --out-dir dist/ .
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
pip install --upgrade pip
pip install setuptools wheel twine
- name: Install pep517
run: >-
pip install pep517
- name: Build a binary wheel and a source tarball
run: >-
python -m
pep517.build --source --binary --out-dir dist/ .
- name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_PHASESPACE_TOKEN }}
- name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_PHASESPACE_TOKEN }}
56 changes: 32 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
repos:
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: check-toml
- id: debug-statements
Expand All @@ -20,14 +24,17 @@ repos:
rev: v1.4
hooks:
- id: docformatter
args: [ -r, --in-place, --wrap-descriptions, '120', --wrap-summaries, '120', -- ]


args:
- -r
- --in-place
- --wrap-descriptions=110
- --wrap-summaries=110

- repo: https://github.com/mattlqx/pre-commit-sign
rev: v1.1.3
hooks:
- id: sign-commit

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.8.0 # Use the ref you want to point at
hooks:
Expand All @@ -36,40 +43,41 @@ repos:
- id: python-no-eval
- id: rst-directive-colons

- repo: https://gitlab.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/PyCQA/isort
rev: 5.8.0
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v2.18.2
rev: v2.18.3
hooks:
- id: pyupgrade
args: [ --py36-plus ]

# Notebook formatting
- repo: https://github.com/nbQA-dev/nbQA
rev: 0.9.0
hooks:
- id: nbqa-isort
additional_dependencies: [ isort==5.6.4 ]

- id: nbqa-pyupgrade
additional_dependencies: [ pyupgrade==2.7.4 ]
args: [ --py36-plus ]
args: [--py36-plus]

- repo: https://github.com/mgedmin/check-manifest
rev: '0.46'
rev: "0.46"
hooks:
- id: check-manifest
stages: [ manual ]
stages: [manual]

# TODO(py37): add the following once 3.6 is gone. Changes the Type hints.
# - repo: https://github.com/sondrelg/pep585-upgrade
# rev: '5f7033a0d0174c65105b041500060b993c1bc211' # Use the sha / tag you want to point at
# hooks:
# - id: upgrade-type-hints
# args: [ '--futures=true' ]
# - repo: https://github.com/sondrelg/pep585-upgrade
# rev: "5f7033a0d0174c65105b041500060b993c1bc211" # Use the sha / tag you want to point at
# hooks:
# - id: upgrade-type-hints
# args: ["--futures=true"]

- repo: https://github.com/psf/black
rev: 21.5b1
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.3.0
hooks:
- id: prettier
13 changes: 5 additions & 8 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,19 @@ Ready to contribute? Here's how to set up `phasespace` for local development.

$ mkvirtualenv phasespace
$ cd phasespace/
$ python setup.py develop
$ pip install -e .[dev]

4. Create a branch for local development::

$ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.

5. When you're done making changes, check that your changes pass flake8 and the
tests, including testing other Python versions with tox::
5. When you're done making changes, check that your changes pass pre-commit and the
tests:

$ flake8 phasespace tests
$ python setup.py test or py.test
$ tox

To get flake8 and tox, just pip install them into your virtualenv.
$ pytest
$ pre-commit run -a

6. Commit your changes and push your branch to GitHub::

Expand Down
23 changes: 7 additions & 16 deletions benchmark/bench_phasespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@

import os
import sys
from timeit import default_timer

import tensorflow as tf

from phasespace import phasespace

sys.path.append(os.path.dirname(__file__))

# from .monitoring import Timer

# !/usr/bin/env python
# -*- coding: utf-8 -*-
# =============================================================================
# @file monitoring.py
# @author Albert Puig ([email protected])
# @date 14.02.2017
# =============================================================================
"""Various code monitoring utilities."""

import os
from timeit import default_timer


def memory_usage():
"""Get memory usage of current process in MiB.
Expand Down Expand Up @@ -99,8 +86,12 @@ def __exit__(self, *args):

# to play around with optimization, no big effect though
NUM_PARALLEL_EXEC_UNITS = 1
# config = tf.ConfigProto(intra_op_parallelism_threads=NUM_PARALLEL_EXEC_UNITS, inter_op_parallelism_threads=1,
# allow_soft_placement=True, device_count={'CPU': NUM_PARALLEL_EXEC_UNITS})
# config = tf.ConfigProto(
# intra_op_parallelism_threads=NUM_PARALLEL_EXEC_UNITS,
# inter_op_parallelism_threads=1,
# allow_soft_placement=True,
# device_count={"CPU": NUM_PARALLEL_EXEC_UNITS},
# )

B_MASS = 5279.0
B_AT_REST = tf.stack((0.0, 0.0, 0.0, B_MASS), axis=-1)
Expand Down
7 changes: 0 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@
# absolute, like shown here.
#


import os
import sys

sys.path.insert(0, os.path.abspath(".."))

import sphinx_bootstrap_theme
import tensorflow as tf

import phasespace

Expand Down
30 changes: 15 additions & 15 deletions paper/paper.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'phasespace: $n$-body phase space generation in Python'
title: "phasespace: $n$-body phase space generation in Python"
tags:
- high energy physics
- tensorflow
Expand All @@ -12,8 +12,8 @@ authors:
orcid: 0000-0002-7312-3699
affiliation: "1"
affiliations:
- name: Physik-Institut, Universität Zürich, Zürich (Switzerland)
index: 1
- name: Physik-Institut, Universität Zürich, Zürich (Switzerland)
index: 1
date: 3 June 2019
bibliography: paper.bib
---
Expand All @@ -25,21 +25,21 @@ They are used to study a wide variety of aspects of a physics analysis, such as
While it is possible to encode complex physics dynamics into these simulations at the cost of increased complexity and larger computer requirements, in many cases it is enough to generate these simulated samples as if only kinematic physics occurred, i.e., in an isotropic way.
This type of generation, called "phase space generation", is very fast and offers simple and predictable patterns, making it an attractive first step in many physics analyses.

The ``phasespace`` package implements phase space event generation based on the Raubold and Lynch method described in [@James:1968gu].
This method was previously implemented in the ``GENBOD`` function of the FORTRAN-based ``CERNLIB`` library. It was posteriorly ported to C++ for the ROOT toolkit [@Brun:1997pa] as the ``TGenPhaseSpace`` class, which is currently the most used implementation in particle physics.
The ``phasespace`` package provides a pure Python implementation of the Raubold and Lynch method using the *Tensorflow* platform [@tensorflow2015-whitepaper] as its computational backend.
Unlike ``TGenPhaseSpace``, the ``phasespace`` approach offers seamless integration with the scientific Python ecosystem (*numpy*, *pandas*, *scikit-learn*...) while at the same time provides excellent performance and scalability both in CPUs and GPUs thanks to *Tensorflow*.
The `phasespace` package implements phase space event generation based on the Raubold and Lynch method described in [@James:1968gu].
This method was previously implemented in the `GENBOD` function of the FORTRAN-based `CERNLIB` library. It was posteriorly ported to C++ for the ROOT toolkit [@Brun:1997pa] as the `TGenPhaseSpace` class, which is currently the most used implementation in particle physics.
The `phasespace` package provides a pure Python implementation of the Raubold and Lynch method using the _Tensorflow_ platform [@tensorflow2015-whitepaper] as its computational backend.
Unlike `TGenPhaseSpace`, the `phasespace` approach offers seamless integration with the scientific Python ecosystem (_numpy_, _pandas_, _scikit-learn_...) while at the same time provides excellent performance and scalability both in CPUs and GPUs thanks to _Tensorflow_.

In addition, ``phasespace`` allows the generation of complex multi-decay chains, including non-constant masses as is needed for the simulation of resonant particles.
This functionality opens the door for its use as the basis for importance sampling in Dalitz and amplitude decay fitters, which typically need to implement their own solution based on ``TGenPhaseSpace``;
in this sense, ``phasespace`` is currently being used for the implementation of amplitude fit sampling in the ``zfit`` fitter [@zfit].
In addition, `phasespace` allows the generation of complex multi-decay chains, including non-constant masses as is needed for the simulation of resonant particles.
This functionality opens the door for its use as the basis for importance sampling in Dalitz and amplitude decay fitters, which typically need to implement their own solution based on `TGenPhaseSpace`;
in this sense, `phasespace` is currently being used for the implementation of amplitude fit sampling in the `zfit` fitter [@zfit].

The correctness of ``phasespace`` is continuously validated through its test suite against ``TGenPhaseSpace`` and the ``RapidSim`` package [@Cowan:2016tnm], an application for the simulation of heavy-quark hadron decays;
this latter application also uses ``TGenPhaseSpace``, but adds features such as multi-decay chains and simulation of the kinematics found in colliders such as the LHC.
The correctness of `phasespace` is continuously validated through its test suite against `TGenPhaseSpace` and the `RapidSim` package [@Cowan:2016tnm], an application for the simulation of heavy-quark hadron decays;
this latter application also uses `TGenPhaseSpace`, but adds features such as multi-decay chains and simulation of the kinematics found in colliders such as the LHC.

In summary, ``phasespace`` is designed to fill an important gap in the recent paradigm shift of particle physics analysis towards integration with the scientific Python ecosystem. To do so it also has more advanced functionality than its C++-based predecessors.
With its ease of use, clear interface and direct interoperability with other packages, ``phasespace`` provides a solid foundation to build upon in the quest for a full Python-based particle physics analysis software stack.
The source code for ``phasespace`` has been archived to Zenodo with the linked DOI: [@zenodo].
In summary, `phasespace` is designed to fill an important gap in the recent paradigm shift of particle physics analysis towards integration with the scientific Python ecosystem. To do so it also has more advanced functionality than its C++-based predecessors.
With its ease of use, clear interface and direct interoperability with other packages, `phasespace` provides a solid foundation to build upon in the quest for a full Python-based particle physics analysis software stack.
The source code for `phasespace` has been archived to Zenodo with the linked DOI: [@zenodo].

# Acknowledgements

Expand Down
6 changes: 3 additions & 3 deletions phasespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import tensorflow as tf

from . import random
from .phasespace import GenParticle, nbody_decay


def _set_eager_mode():
import os
Expand All @@ -21,6 +24,3 @@ def _set_eager_mode():


_set_eager_mode()

from . import random
from .phasespace import GenParticle, nbody_decay
Loading

0 comments on commit 22cdd81

Please sign in to comment.