Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance updates, part 3: document changes to infrastructure + fix docker build #8

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Gratopy Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
- name: Check code formatting
run: uv tool run ruff format --check
- name: Run linting
run: uv tool run ruff check
41 changes: 0 additions & 41 deletions .github/workflows/python-app.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will install Python dependencies, run tests and lint with a multiple versions of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Gratopy Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
- name: Install system dependencies
run: |
sudo apt-get install pocl-opencl-icd libopenblas-dev
- name: Install gratopy and Python dependencies
run: uv sync
- name: Run tests
run: uv run pytest
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Compiled python modules.
*.pyc

# Setuptools distribution folder.
# package distribution folder
/dist/

# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info
# documentation
doc/build

# virtual environments
.venv
Expand Down
7 changes: 0 additions & 7 deletions MANIFEST.in

This file was deleted.

25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,24 @@ Calling
pip install .
```

inside the main folder then installs the toolbox.
Gratopy supports setuptools for installation such that
inside the main folder then installs the toolbox.
Gratopy uses [`uv`](https://docs.astral.sh/uv/) as its project and dependency
management tool, which allows setting up a dedicated development environment
by running

```bash
python setup.py install
uv sync
```

has the same effect.
For more details we refer to the [documentation](https://gratopy.readthedocs.io/).

As a further alternative, if no dedicated installation is needed for the toolbox, the code can simply be downloaded and the contents of the `gratopy` directory can be imported as a module. Please make sure to have the following Python modules installed, most of which should be standard.

## Requirements
Most notably, `gratopy` is built using [PyOpenCL](https://pypi.org/project/pyopencl/), which
might require additional care in order to correctly install and configure it: depending on the
used platform and GPU, suitable drivers must be installed. We refer to
[PyOpenCL's documentation](https://documen.tician.de/pyopencl/) for detailed instructions.

* [pyopencl>=2019.1](https://pypi.org/project/pyopencl/)
* [numpy>=1.17.0](https://pypi.org/project/numpy/)
* [scipy>=1.3.0](https://pypi.org/project/scipy/)
* [matplotlib>=3.2.0](https://pypi.org/project/matplotlib/)
* [Pillow>=6.0.0](https://pypi.org/project/Pillow/)
* [Mako>=1.1.0](https://pypi.org/project/Mako/)

Note that in particular, correctly installing and configuring PyOpenCL might take some time, as dependent on the used platform/GPU, suitable drivers must be installed. We refer to [PyOpenCL's documentation](https://documen.tician.de/pyopencl/).

The full list of requirements can be found in [`pyproject.toml`](/pyproject.toml).

## Getting started
We refer to the extensive [documentation](https://gratopy.readthedocs.io/), in particular to the [getting started](https://gratopy.readthedocs.io/en/latest/getting_started.html) guide, as well as to the test files for the [Radon transform](https://gratopy.readthedocs.io/en/latest/_modules/test_radon.html) and [fanbeam transform](https://gratopy.readthedocs.io/en/latest/_modules/test_fanbeam.html). The following [rudimentary example](https://gratopy.readthedocs.io/en/latest/getting_started.html#first-example-radon-transform) is also included in the documentation.
Expand Down
32 changes: 19 additions & 13 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,36 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))

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


# -- Project information -----------------------------------------------------

project = 'gratopy'
copyright = '2021, Kristian Bredies, Richard Huber'
author = 'Kristian Bredies, Richard Huber'
project = "gratopy"
copyright = "2021, Kristian Bredies, Richard Huber"
author = "Kristian Bredies, Richard Huber"

# The full version, including alpha/beta/rc tags
release = '0.1.0'
release = "0.1.0"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosectionlabel', 'sphinx.ext.viewcode', 'sphinx.ext.intersphinx']
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosectionlabel",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
]

autosectionlabel_prefix_document = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -48,7 +54,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand All @@ -57,9 +63,9 @@
html_static_path = []

intersphinx_mapping = {
"https://docs.python.org/dev": None,
"https://numpy.org/doc/stable/": None,
"https://documen.tician.de/pyopencl/": None,
"https://matplotlib.org/stable/": None,
"https://docs.scipy.org/doc/scipy/": None
"python": ("https://docs.python.org/dev", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pyopencl": ("https://documen.tician.de/pyopencl/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
}
52 changes: 30 additions & 22 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
Installation
============

Gratopy supports common Python package distribution frameworks such as
setuptools_ or pip_.
Stable releases can be found on the
`GitHub Release page <https://github.com/kbredies/gratopy/releases>`__
and are distributed via the
`Python Packaging Index, PyPI <https://pypi.org/project/gratopy/>`__.


.. _setuptools: https://pypi.org/project/setuptools/
.. _pip: https://pypi.org/project/pip/

Installation in Python
Expand All @@ -22,32 +24,39 @@ Alternatively, the release can be downloaded from https://github.com/kbredies/gr

pip install .

Also, setuptools_ can be used for installation via
::

python setup.py install
In case installation fails due to the dependency on other packages
(see `pyproject.toml <https://github.com/kbredies/gratopy/blob/master/pyproject.toml>`_),
it is advised to install the packages by hand before retrying to install gratopy.

In case installation fails due to the dependency on other packages (see `requirements.txt <https://github.com/kbredies/gratopy/blob/master/requirements.txt>`_), it is advised to install the packages by hand before retrying to install gratopy. In particular, the PyOpenCL package may require some additional
In particular, the PyOpenCL package may require some additional
effort as it depends on additional drivers and C libraries which might needed to be installed by hand. We refer to the documentation of PyOpenCL_.

.. _pyopencl: https://documen.tician.de/pyopencl/

For development, we recommend installing the project and dependency management
tool `uv <https://docs.astral.sh/uv/>`__. The local development environment
is then setup from within the cloned repository by running

::

uv sync


Testing correct installation
----------------------------



The release archive (or GitHub repository) includes a ``tests`` folder which contains a variety of tests that allow to observe visually and numerically whether gratopy was installed correctly and works as desired.

One can perform these tests by using, for instance, pytest_
One can perform these tests by using, for instance, pytest_ (which, if you are not using ``uv``
for managing a local development environment, needs to be installed by running
``pip install pytest``). The tests are then executed by running
::

pytest

or nose_
::

nosetests
or ``uv run pytest`` when using ``uv``.

In case multiple OpenCL devices are registered in :mod:`pyopencl`, but the default device is not suitably configured for the tests to work, one might need to choose the context to use manually. This a-priori choice of context to use in :mod:`pyopencl` can be done via
::
Expand All @@ -70,20 +79,19 @@ By default, the plots of the tests are disabled, but can be activated, e.g., by
Moreover, the :ref:`getting-started` guide contains two example code segments which can be executed to quickly check that no errors occur and the output is as desired.

.. _pytest: https://pypi.org/project/pytest/
.. _nose: https://pypi.org/project/nose/

Requirements
------------

The `requirements.txt <https://github.com/kbredies/gratopy/blob/master/requirements.txt>`_ file specifies Python packages
required for the use of gratopy. Amongst them the most relevant are
The `pyproject.toml <https://github.com/kbredies/gratopy/blob/master/pyproject.toml>`_ file specifies Python packages
required for the use of ``gratopy``. Amongst them the most relevant are

* `pyopencl>=2019.1 <https://pypi.org/project/pyopencl/>`_
* `numpy>=1.17.0 <https://pypi.org/project/numpy/>`_
* `scipy>=1.3.0 <https://pypi.org/project/scipy/>`_
* `matplotlib>=3.2.0 <https://pypi.org/project/matplotlib/>`_
* `Pillow>=6.0.0 <https://pypi.org/project/Pillow/>`_
* `Mako>=1.1.0 <https://pypi.org/project/Mako/>`_
* `pyopencl <https://pypi.org/project/pyopencl/>`_
* `numpy <https://pypi.org/project/numpy/>`_
* `scipy <https://pypi.org/project/scipy/>`_
* `matplotlib <https://pypi.org/project/matplotlib/>`_
* `Pillow <https://pypi.org/project/Pillow/>`_
* `Mako <https://pypi.org/project/Mako/>`_

Most users aiming for scientific computing applications will probably have these packages already installed as they can be considered standard for numerical computations in Python.
Let us again point out that correctly installing PyOpenCL might take some time and effort though, as dependent on the used hardware/GPU, the installation of suitable drivers might be required, see, for instance, https://documen.tician.de/pyopencl/.
7 changes: 3 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ ENV NVIDIA_DRIVER_CAPABILITIES compute,utility

# Install gratopy

RUN pip install -U pip
RUN curl -LsSf https://astral.sh/uv/install.sh | sh

WORKDIR /usr/local/gratopy
ADD . .

RUN pip install -r requirements.txt && pip install pytest notebook
RUN pip install .
RUN uv sync && uv pip install notebook

CMD ["/usr/bin/python3"]
CMD ["uv", "run", "python"]
4 changes: 2 additions & 2 deletions docker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ It is also possible to spin up a local Jupyter server in order to
interact with `gratopy` in a Jupyter notebook from a browser on your
host machine. To do so, run the image with
```
docker run --rm [GPU options] -p 8888:8888 gratopy:latest jupyter notebook --ip=0.0.0.0 --allow-root
docker run --rm [GPU options] -p 8888:8888 gratopy:latest uv run jupyter notebook --ip=0.0.0.0 --allow-root
```
and navigate to the link to `http://127.0.0.1:8888/?token=...` that is
shown in your terminal.
Expand All @@ -80,7 +80,7 @@ from the repository root.
The docker container ships with `gratopy`s test suite, which can be
run via
```sh
docker run --rm -it [GPU options] gratopy:latest pytest
docker run --rm -it [GPU options] gratopy:latest uv run pytest
```


Expand Down
23 changes: 20 additions & 3 deletions gratopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,27 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from .gratopy import RADON, PARALLEL, FAN, FANBEAM, VERSION
from .gratopy import forwardprojection, backprojection, ProjectionSettings, \
landweber, conjugate_gradients, total_variation, normest, weight_sinogram
from .gratopy import (
forwardprojection,
backprojection,
ProjectionSettings,
landweber,
conjugate_gradients,
total_variation,
normest,
weight_sinogram,
)
from .phantom import ct_shepp_logan as phantom


# internal functions
from .gratopy import radon, radon_ad, radon_struct, fanbeam, fanbeam_ad, fanbeam_struct, create_code, read_angles
from .gratopy import (
radon,
radon_ad,
radon_struct,
fanbeam,
fanbeam_ad,
fanbeam_struct,
create_code,
read_angles,
)
Loading