Skip to content

Commit

Permalink
remove six, requirements.txt, update readme instructions (#47)
Browse files Browse the repository at this point in the history
Removes obsolete six from the requirements and in the code
Removes obsolete requirements.txt, the requirements are listed in setup.cfg
README installation instructions were updated to reflect state of the art
  • Loading branch information
HDembinski authored Aug 18, 2022
1 parent 8f13f32 commit 3cc124e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
55 changes: 32 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,35 @@ print("Average pT for charged pions {0:4.3f}".format(average_pt))
- Python 3.6+
- Linux, Mac OS X, or Windows

### Without docker
### From PyPI (not yet available)

If you have trouble with this installation guide, look into the subsection which explains how to install in impy in a fixed docker environment.
pip install impy

The package is (will be) available including pre-compiled binaries. The installation in that case simplifies to (*this does not work yet use installation from source*):
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.

pip install impy
### From source

To build from source (the **recursive** flag is important to checkout the sub-modules):
Installation from source requires a Python installation setup for development, as well as 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/impy
cd impy
pip install -e .
make -j<insert number of CPU cores>
pip install -v -e .

For now, you need to call make by hand, but this will be automated. The command `pip install -e .` installs the package in editable mode (for developers).
This takes a while. The command `pip install -v -e .` 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.

Because of the architectural transition and there are many issues on mac, building from source may be a bit complicated. Using brew gcc and python it is possible to build the code by:
To run the tests or try the examples, it is convenient use this modified `pip install` instead:

CC=gcc-10 CXX=gcc-10 FC=gfortran-10 PYTHON_EXE=/usr/local/opt/python@3.8/bin/python3 make -jXXX
pip install -v -e .'[test,examples]'

Replace `gcc-10` by your version in brew. The official Mac Python is currently broken due to the transition to Apple Silicon, but it is possible to build with a bit of hacking. But currently
I don't use a Mac and cannot debug it.

### With docker
This installs impy and additional optional Python packages to run tests and examples.

This guide works on Linux and OSX. You need a running docker server. Please google how to set up docker on your machine.
If installation from source fails, please look into the subsection below which explains how to install in impy 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 impy
git clone --recursive https://github.com/impy-project/impy
Expand All @@ -80,30 +82,37 @@ This guide works on Linux and OSX. You need a running docker server. Please goog
# docker pull quay.io/pypa/manylinux2014_aarch64

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

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

cd /app

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

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

You can now use impy 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

# compile the FORTRAN interface (this will be automated in the future)
make -j<insert number of CPU cores>
# exit docker with ctrl+D
pip install dist/*.whl

You can now use impy inside the docker instance.
This should allow you to use impy 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](examples/compare_two_models.ipynb).
1. As in the example above, via plain python in scripts or Jupyter notebooks. Look at this [example](examples/compare_models.ipynb).

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

Expand Down
7 changes: 0 additions & 7 deletions requirements.txt

This file was deleted.

3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ install_requires =
numpy
scipy
pyhepmc
six
particletools

[options.packages.find]
Expand All @@ -47,6 +46,8 @@ examples =
boost-histogram
particle
matplotlib
tqmd
joblib

[flake8]
max-line-length = 90
Expand Down
11 changes: 5 additions & 6 deletions src/impy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
such as the rapidity :func:`MCEvent.y` or the laboratory momentum fraction
:func:`MCEvent.xlab`.
"""
import six
from abc import ABCMeta, abstractmethod, abstractproperty
from abc import ABC, abstractmethod, abstractproperty

import numpy as np
from impy import impy_config
Expand Down Expand Up @@ -53,7 +52,7 @@ def __init__(
self._vt_arr = vt_arr


class MCEvent(object, six.with_metaclass(ABCMeta)):
class MCEvent(ABC):
"""The basis of interaction between user and all the event generators.
The derived classes are expected to interact with the particle stack
Expand Down Expand Up @@ -376,7 +375,7 @@ def fw(self):
# =========================================================================
# Settings
# =========================================================================
class Settings(six.with_metaclass(ABCMeta)):
class Settings(ABC):
"""Custom classes derived from this template allow to set certain low
level variables in the generators before or after initialization, or for
each event.
Expand Down Expand Up @@ -424,7 +423,7 @@ def __ne__(self, other_instance):

other_attr = other_instance.__dict__

for attr, value in six.iteritems(self.__dict__):
for attr, value in self.__dict__.items():
if attr == "lib":
continue
elif attr not in other_attr.keys():
Expand All @@ -437,7 +436,7 @@ def __ne__(self, other_instance):
# =========================================================================
# MCRun
# =========================================================================
class MCRun(six.with_metaclass(ABCMeta)):
class MCRun(ABC):
#: Prevent creating multiple classes within same python scope
_is_initialized = []

Expand Down
3 changes: 1 addition & 2 deletions src/impy/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""

import six
import numpy as np
from impy import pdata
from impy.util import info
Expand Down Expand Up @@ -309,7 +308,7 @@ def __setstate__(self, state):
}

def __ne__(self, other):
for key, value in six.iteritems(other.__dict__):
for key, value in other.__dict__.items():
if key == "boost_def":
continue
if value != self.__dict__[key]:
Expand Down
5 changes: 2 additions & 3 deletions src/impy/writer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from abc import ABCMeta, abstractmethod
from six import with_metaclass
from abc import ABC, abstractmethod


class Writer(object, with_metaclass(ABCMeta)):
class Writer(ABC):
@abstractmethod
def write(self, event):
pass
Expand Down

0 comments on commit 3cc124e

Please sign in to comment.