Merge remote-tracking branch 'origin/master' into multigpu

This commit is contained in:
yoshikisd
2025-12-12 00:33:59 +00:00
7 changed files with 207 additions and 112 deletions
+47 -14
View File
@@ -7,11 +7,11 @@ on:
branches: [ master ]
jobs:
test:
test-uv-pip-install:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
continue-on-error: true
steps:
@@ -22,14 +22,43 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install uv
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install -e . --no-deps
pip install uv
- name: Create virtual environment
run: |
uv venv
- name: Install dependencies with uv
run: |
uv pip install ."[tests]"
- name: Run tests
run: pytest
run: |
uv run pytest
test-pip-install:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.14']
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies with pip
run: |
pip install ."[tests]"
- name: Run tests
run: |
pytest
build-docs:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
@@ -52,17 +81,21 @@ jobs:
with:
python-version: '3.9'
- name: Install dependencies
- name: Install uv
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install sphinx sphinx_rtd_theme sphinx-argparse
pip install -e . --no-deps
pip install uv
- name: Create virtual environment
run: |
uv venv
- name: Install dependencies with uv
run: |
uv pip install ."[docs]"
- name: Build docs
working-directory: docs
run: |
make html
uv run python -m sphinx -b html docs/source docs/build/html
- name: List files in docs/build/html
run: |
+12 -5
View File
@@ -19,12 +19,19 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
- name: Install uv
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Build package (setup.py)
pip install uv
- name : Create virtual environment
run: |
python setup.py sdist bdist_wheel
uv venv
- name: Install project with uv
run: |
uv pip install -e .
- name: Build package with uv
run: |
uv build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
+44 -1
View File
@@ -26,14 +26,57 @@ model.compare(dataset) # See how the simulated and measured patterns compare
plt.show()
```
Further documentation is found [here](https://cdtools-developers.github.io/cdtools/).
# Installation
CDTools can be installed in several ways depending on your needs. For most users, installation from pypi is recommended. For developers or those who want the latest features, installation from source is available.
## Installation from pypi
CDTools can be installed via pip as the [cdtools-py](https://pypi.org/project/cdtools-py/) package on [PyPI](https://pypi.org/):
```bash
$ pip install cdtools-py
```
Further documentation is found [here](https://cdtools-developers.github.io/cdtools/).
or using [uv](https://github.com/astral-sh/uv):
```bash
$ uv pip install cdtools-py
```
## Installation from Source
For development or to access the latest features, CDTools can be installed directly from source:
```bash
$ git clone https://github.com/cdtools-developers/cdtools.git
$ cd cdtools
$ pip install -e .
```
or using [uv](https://github.com/astral-sh/uv):
```bash
$ git clone https://github.com/cdtools-developers/cdtools.git
$ cd cdtools
$ uv pip install -e .
```
## Installing for Contributors (with tests and docs dependencies)
If you want to run the test suite or build the documentation, install with the extra dependencies:
```bash
$ pip install -e ."[tests,docs]"
```
or with uv:
```bash
$ uv pip install -e ."[tests,docs]"
```
CDTools was developed in the [photon scattering lab](https://scattering.mit.edu/) at MIT, and further development took place within the [computational x-ray imaging group](https://www.psi.ch/en/cxi) at PSI. The code is distributed under an MIT (a.k.a. Expat) license. If you would like to publish any work that uses CDTools, please contact [Abe Levitan](mailto:abraham.levitan@psi.ch).
+53 -29
View File
@@ -1,7 +1,7 @@
Installation
============
CDTools supports python >=3.8 and can be installed via pip as the the `cdtools-py`_ package on `PyPI`_. If you plan to contribute to the code or need a custom environment, installation from source is also possible.
CDTools supports python >=3.9 and can be installed via pip as the the `cdtools-py`_ package on `PyPI`_. If you plan to contribute to the code or need a custom environment, installation from source is also possible.
.. _`cdtools-py`: https://pypi.org/project/cdtools-py/
.. _`PyPI`: https://pypi.org/
@@ -15,6 +15,14 @@ To install from `PyPI`_, run:
$ pip install cdtools-py
or you can use `uv`_ for a faster installation:
.. _`uv`: https://github.com/astral-sh/uv
.. code:: bash
$ uv pip install cdtools-py
Pytorch, a major dependence of CDTools, often needs to be installed with a specific CUDA version for machine compatability. If you run into issues with pytorch, consider first installing pytorch into your environment using the instructions on `the pytorch site`_.
.. _`the pytorch site`: https://pytorch.org/get-started/locally/
@@ -31,18 +39,51 @@ The source code for CDTools is hosted on `Github`_.
.. _`Github`: https://github.com/cdtools-developers/cdtools
Step 2: Install Dependencies
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The major dependency for CDTools is pytorch version 2.3.0 or greater. Because the details of the pytorch installation can vary depending on platform and GPU availability, it is recommended that you first install pytorch using the instructions on `the pytorch site`_. The remaining dependencies can be installed by running the following command from the top level directory of the git repository:
To download the source code, you can either clone the repository using git:
.. code:: bash
$ pip install -r requirements.txt
Note that several optional dependencies used for testing and documentation will also be installed. The full set of dependencies and minimum requirements are listed below. CDTools is reguarly tested with the latest versions of these packages and with python 3.8 through 3.12.
$ git clone https://github.com/cdtools-developers/cdtools.git
Required dependencies:
or you can download a zip file of the repository from the `releases page`_.
.. _`releases page`: https://github.com/cdtools-developers/cdtools/releases
Step 2: Install
^^^^^^^^^^^^^^^
Move to the directory where you downloaded the source code. It is recommended that you create a new python virtual environment to install CDTools into.
Installation using pip and uv. Editable mode is recommended for development purposes and is added with the `-e` flag.
.. code:: bash
$ pip install -e .
or using uv:
.. code:: bash
$ uv pip install -e .
To install the required test and documentation dependencies as well, use:
.. code:: bash
$ pip install -e ."[tests,docs]"
or using uv:
.. code:: bash
$ uv pip install -e ."[tests,docs]"
CDTools is reguarly tested with the latest versions of these packages and with python 3.9 through 3.14.
Required dependencies (see pyproject.toml for all details):
* `numpy <http://www.numpy.org>`_ >= 1.0
* `scipy <http://www.scipy.org>`_ >= 1.0
@@ -63,30 +104,13 @@ Optional dependencies for building docs:
* `sphinx_rtd_theme <https://sphinx-rtd-theme.readthedocs.io/en/stable/>`_ >= 0.5.1
Step 3: Install
^^^^^^^^^^^^^^^
To install CDTools, run the following command from the top level directory of the git repository:
.. code:: bash
$ pip install -e . --no-deps
This will install CDTools in developer mode, so that changes to the code will propagate to the installed version immediately. This is best if you plan to actively develop CDTools. If you simply need a custom environment, you can also install CDTools in standard mode using:
.. code:: bash
$ pip install . --no-deps
Step 4: Run The Tests
^^^^^^^^^^^^^^^^^^^^^
Optional step 4: Run The Tests
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To ensure that the installation has worked correctly, it is recommended that you run the unit tests. Execute the following command from the top level directory of the git repository:
.. code:: bash
$ pytest
$ python -m pytest
If any tests fail, make sure that you have all the noted dependencies properly installed. If you do, and things still aren't working, `open an issue on the github page <https://github.com/cdtools-developers/cdtools/issues>`_ and we'll get to the bottom of it.
+51 -1
View File
@@ -1,3 +1,53 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "cdtools-py"
description = "Tools for coherent diffractive imaging and ptychography"
readme = "README.md"
requires-python = ">=3.9"
license = { file = "LICENSE.txt" }
authors = [
{ name = "Abe Levitan", email = "abraham.levitan@psi.ch" },
{ name = "Dayne Y. Sasaki" },
{ name = "Damian Guenzing" },
{ name = "Madelyn Cain" },
{ name = "Anastasiia Kutakh" }
]
maintainers = [
{ name = "Abe Levitan", email = "abraham.levitan@psi.ch" }
]
keywords = ["ptychography", "CDI", "imaging", "torch", "differentiable"]
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License"
]
urls = { "Homepage" = "https://github.com/cdtools-developers/cdtools", "Documentation" = "https://cdtools-developers.github.io/cdtools/" }
dependencies = [
"numpy>=1.0",
"scipy>=1.0",
"matplotlib>=2.0",
"torch>=2.3.0",
"h5py>=2.1",
"python-dateutil",
]
dynamic = ["version"]
[tool.setuptools.dynamic]
version = {attr = "cdtools._version.__version__"}
[project.optional-dependencies]
tests = [
"pytest",
"pooch"
]
docs = [
"sphinx>=4.3.0",
"sphinx-argparse",
"sphinx_rtd_theme>=0.5.1"
]
[tool.ruff]
# Decrease the maximum line length to 79 characters.
line-length = 79
-11
View File
@@ -1,11 +0,0 @@
numpy>=1.0
scipy>=1.0
matplotlib>=2.0 # 2.0 introduces better colormaps which are used by default
torch>=1.9.0 #1.9.0 implements support for autograd on indexed complex tensors
h5py>=2.1
python-dateutil
pytest
pooch
sphinx>=4.3.0 # Fixes a bug with bulleted lists
sphinx-argparse
sphinx_rtd_theme>=0.5.1 # Fixes a bug with bulleted lists
-51
View File
@@ -1,51 +0,0 @@
import setuptools
import os
import re
with open("README.md", "r") as fh:
long_description = fh.read()
# read version from src/cdtools/_version.py
version_file = os.path.join("src/cdtools", "_version.py")
with open(version_file) as f:
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", f.read(), re.M)
if not version_match:
raise RuntimeError("Unable to find version string.")
version = version_match.group(1)
setuptools.setup(
name="cdtools-py",
version=version,
python_requires='>3.8', # recommended minimum version for pytorch 2.3.0
author="Abe Levitan",
author_email="abraham.levitan@psi.ch",
description="Tools for coherent diffractive imaging and ptychography",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/cdtools-developers/cdtools",
install_requires=[
"numpy>=1.0",
"scipy>=1.0",
"matplotlib>=2.0", # 2.0 has better colormaps which are used by default
"python-dateutil",
"torch>=2.3.0", #2.3.0 is the earliest release for which L-BFGS works directly on complex-valued leaf tensors
"h5py>=2.1"],
extras_require={
'tests': [
"pytest",
"pooch",
],
'docs': [
"sphinx>=4.3.0",
"sphinx-argparse",
"sphinx_rtd_theme>=0.5.1"
]
},
package_dir={"": "src"},
packages=setuptools.find_packages("src"),
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
)