diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index c7817c4a..0e7a8e37 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,36 +1,34 @@ -name: CodSpeed - -on: +--- +name: CodSpeed Benchmarks +"on": + pull_request: + types: + - opened + - reopened + - synchronize push: branches: - - "main" - pull_request: - # `workflow_dispatch` allows CodSpeed to trigger backtest - # performance analysis in order to generate initial data. - workflow_dispatch: - + - main + workflow_dispatch: ~ jobs: benchmarks: - name: Run benchmarks + name: Run Benchmarks + permissions: + contents: read runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 - - name: Install OpenMPI - run: sudo apt install -y openmpi-bin openmpi-doc libopenmpi-dev - - - name: Setup rust toolchain, cache and cargo-codspeed binary - uses: moonrepo/setup-rust@v1 + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Setup Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Install Rust Tool + uses: taiki-e/install-action@v2 with: - channel: stable - cache-target: release - bins: cargo-codspeed - - - name: Build the benchmark target(s) - run: cargo codspeed build --profile dist-release - - - name: Run the benchmarks + tool: cargo-codspeed + - run: cargo codspeed build + - name: CodSpeed Action uses: CodSpeedHQ/action@v4 with: mode: simulation run: cargo codspeed run - token: ${{ secrets.CODSPEED_TOKEN }} + token: ${{ secrets.CODSPEED_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d7191405..aa20d1dc 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,11 +1,15 @@ +--- name: Coverage - -on: +"on": pull_request: paths: - "**.rs" - "**.py" - ".github/workflows/coverage.yml" + types: + - opened + - reopened + - synchronize push: branches: - main @@ -17,60 +21,78 @@ on: secrets: codecov_token: required: true - workflow_dispatch: + workflow_dispatch: ~ jobs: coverage-rust: + permissions: + contents: read runs-on: ubuntu-latest env: CARGO_TERM_COLOR: always steps: - - uses: actions/checkout@v6 - - name: Install OpenMPI - run: sudo apt install -y clang mpich libmpich-dev - - name: Install Rust - run: rustup update nightly - - name: Install Just - uses: taiki-e/install-action@just - - name: Install cargo-llvm-cov - uses: taiki-e/install-action@cargo-llvm-cov - - name: Generate Rust code coverage - run: just coverage-rust - - name: Upload coverage report - uses: actions/upload-artifact@v5 + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Setup Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: nightly + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 + - name: Install Rust Tool + uses: taiki-e/install-action@v2 + with: + tool: cargo-llvm-cov + - run: cargo llvm-cov --workspace --lcov --output-path coverage-rust.lcov --summary-only --exclude-from-report py-laddu + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: coverage-rust path: coverage-rust.lcov + name: coverage-rust coverage-python: + permissions: + contents: read runs-on: ubuntu-latest + env: + CARGO_TERM_COLOR: always steps: - - uses: actions/checkout@v6 - - name: Install uv + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Setup Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Setup uv uses: astral-sh/setup-uv@v7 - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - - name: Install Just - uses: taiki-e/install-action@just - - name: Generate Python code coverage - run: just coverage-python - - name: Upload coverage report - uses: actions/upload-artifact@v5 + - run: |- + uv venv + . .venv/bin/activate + echo PATH=$PATH >> $GITHUB_ENV + uvx --with "maturin[patchelf]>=1.7,<2" maturin build --manifest-path py-laddu-cpu/Cargo.toml --release -o py-laddu-cpu/dist + uv pip install --no-cache-dir --find-links py-laddu-cpu/dist laddu-cpu + uv pip install --no-cache-dir -e "py-laddu[tests]" + pytest --cov --cov-report xml:coverage-python.xml + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: coverage-python path: coverage-python.xml + name: coverage-python upload-coverage: - needs: [coverage-rust, coverage-python] + permissions: + contents: read + needs: + - coverage-rust + - coverage-python runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 - - name: Download coverage reports - uses: actions/download-artifact@v6 + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Download Artifact + uses: actions/download-artifact@v7 with: merge-multiple: true - - name: Upload coverage reports to Codecov + - name: Upload coverage uses: codecov/codecov-action@v5 with: - token: ${{ secrets.CODECOV_TOKEN }} - files: coverage-rust.lcov,coverage-python.xml fail_ci_if_error: true - verbose: true + files: "coverage-rust.lcov,coverage-python.xml" root_dir: ${{ github.workspace }} + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true \ No newline at end of file diff --git a/.github/workflows/python-release.yml b/.github/workflows/python-release.yml index c8fafa4e..f8f54a47 100644 --- a/.github/workflows/python-release.yml +++ b/.github/workflows/python-release.yml @@ -1,357 +1,789 @@ -name: Python Release - -on: - workflow_dispatch: +--- +name: Build and Release laddu (Python) +"on": + pull_request: + types: + - opened + - reopened + - synchronize push: branches: - main - pull_request: - types: [opened, reopened, ready_for_review, synchronize] - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -permissions: - contents: read - + tags: + - py-laddu* + - "!py-laddu-cpu*" + - "!py-laddu-mpi*" + workflow_dispatch: ~ jobs: - cpu-linux: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false + build-check-test: + permissions: + contents: read + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Setup Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy + - name: Setup uv + uses: astral-sh/setup-uv@v7 + with: + python-version: "3.10" + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 + - run: cargo clippy + - name: Install Rust Tool + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack + - run: cargo hack check --rust-version --feature-powerset --no-dev-deps + - run: cargo hack test --feature-powerset + - run: |- + uv venv + . .venv/bin/activate + echo PATH=$PATH >> $GITHUB_ENV + uvx --with "maturin[patchelf]>=1.7,<2" maturin build --manifest-path py-laddu-cpu/Cargo.toml --release -o py-laddu-cpu/dist + uv pip install --no-cache-dir --find-links py-laddu-cpu/dist laddu-cpu + uv pip install --no-cache-dir -e "py-laddu[tests]" + - run: uvx ruff check . --extend-exclude=.yamloom.py + - run: uvx ty check . --exclude=.yamloom.py + - run: uv run pytest + linux-cpu: + name: Build Linux Wheels (cpu) + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: ubuntu-22.04 target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: ubuntu-22.04 target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: ubuntu-22.04 target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: ubuntu-22.04 target: armv7 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: ubuntu-22.04 target: s390x + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: ppc64le + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 with: - python-version: 3.x - - name: Install build dependencies - run: sudo apt-get update && sudo apt-get install -y build-essential clang + python-version-file: version.txt - name: Build wheels uses: PyO3/maturin-action@v1 with: - target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-cpu/Cargo.toml --zig - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} manylinux: auto - - name: Build free-threaded wheels - uses: PyO3/maturin-action@v1 - with: target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-cpu/Cargo.toml --zig -i python3.13t - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - manylinux: auto - - name: Upload wheels - uses: actions/upload-artifact@v5 + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-cpu/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: cpu-linux-${{ matrix.platform.target }} path: dist - - cpu-musllinux: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false + name: cpu-linux-${{ matrix.platform.target }} + musllinux-cpu: + name: Build (musl) Linux Wheels (cpu) + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: ubuntu-22.04 target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: ubuntu-22.04 target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: ubuntu-22.04 target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: ubuntu-22.04 target: armv7 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 with: - python-version: 3.x + python-version-file: version.txt - name: Build wheels uses: PyO3/maturin-action@v1 with: - target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-cpu/Cargo.toml - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} manylinux: musllinux_1_2 - - name: Build free-threaded wheels - uses: PyO3/maturin-action@v1 - with: target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-cpu/Cargo.toml -i python3.13t - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - manylinux: musllinux_1_2 - - name: Upload wheels - uses: actions/upload-artifact@v5 + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-cpu/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: cpu-musllinux-${{ matrix.platform.target }} path: dist - - cpu-windows: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false + name: cpu-musllinux-${{ matrix.platform.target }} + windows-cpu: + name: Build Windows Wheels (cpu) + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: windows-latest target: x64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 python_arch: x64 + - runner: windows-latest + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + python_arch: x86 - runner: windows-11-arm target: aarch64 + python_versions: + - "3.12" + - "3.13" + - "3.14" python_arch: arm64 + fail-fast: false steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 with: - python-version: 3.x + python-version-file: version.txt architecture: ${{ matrix.platform.python_arch }} - name: Build wheels uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-cpu/Cargo.toml - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - - uses: actions/setup-python@v5 + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-cpu/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - python-version: 3.13t - architecture: ${{ matrix.platform.python_arch }} - - name: Build free-threaded wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-cpu/Cargo.toml -i python3.13t - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - - name: Upload wheels - uses: actions/upload-artifact@v5 - with: - name: cpu-windows-${{ matrix.platform.target }} path: dist - - cpu-macos: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false + name: cpu-windows-${{ matrix.platform.target }} + macos-cpu: + name: Build macOS Wheels (cpu) + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: macos-15-intel target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: macos-latest target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 with: - python-version: 3.x + python-version-file: version.txt - name: Build wheels uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-cpu/Cargo.toml - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - - name: Build free-threaded wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-cpu/Cargo.toml -i python3.13t - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - - name: Upload wheels - uses: actions/upload-artifact@v5 + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-cpu/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: cpu-macos-${{ matrix.platform.target }} path: dist - - cpu-sdist: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false - runs-on: ubuntu-latest + name: cpu-macos-${{ matrix.platform.target }} + linux-mpi: + name: Build Linux Wheels (mpi) + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-22.04 + target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: armv7 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: s390x + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: ppc64le + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false steps: - - uses: actions/checkout@v6 - - name: Build sdist + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 + - name: Build wheels uses: PyO3/maturin-action@v1 with: - command: sdist - args: --out dist --manifest-path py-laddu-cpu/Cargo.toml - - name: Upload sdist - uses: actions/upload-artifact@v5 + manylinux: auto + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-mpi/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: cpu-sdist path: dist - - mpi-linux: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false + name: mpi-linux-${{ matrix.platform.target }} + musllinux-mpi: + name: Build (musl) Linux Wheels (mpi) + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: ubuntu-22.04 target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: armv7 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 - with: - python-version: 3.x - - name: Install Clang - run: | - set -e - sudo apt-get update - sudo apt-get install -y libclang-dev build-essential - - uses: mpi4py/setup-mpi@v1 + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 - name: Build wheels uses: PyO3/maturin-action@v1 with: + manylinux: musllinux_1_2 target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-mpi/Cargo.toml --zig - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - manylinux: auto - - name: Build free-threaded wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-mpi/Cargo.toml --zig -i python3.13t - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - manylinux: auto - - name: Upload wheels - uses: actions/upload-artifact@v5 + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-mpi/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: mpi-linux-${{ matrix.platform.target }} path: dist - - mpi-windows: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false + name: mpi-musllinux-${{ matrix.platform.target }} + windows-mpi: + name: Build Windows Wheels (mpi) + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: windows-latest target: x64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 python_arch: x64 + - runner: windows-latest + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + python_arch: x86 + - runner: windows-11-arm + target: aarch64 + python_versions: + - "3.12" + - "3.13" + - "3.14" + python_arch: arm64 + fail-fast: false steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 with: - python-version: 3.x + python-version-file: version.txt architecture: ${{ matrix.platform.python_arch }} - - uses: mpi4py/setup-mpi@v1 + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 - name: Build wheels uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-mpi/Cargo.toml - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - - uses: actions/setup-python@v5 + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-mpi/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - python-version: 3.13t - architecture: ${{ matrix.platform.python_arch }} - - name: Build free-threaded wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-mpi/Cargo.toml -i python3.13t - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - - name: Upload wheels - uses: actions/upload-artifact@v5 - with: - name: mpi-windows-${{ matrix.platform.target }} path: dist - - mpi-macos: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false + name: mpi-windows-${{ matrix.platform.target }} + macos-mpi: + name: Build macOS Wheels (mpi) + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: macos-15-intel target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 - runner: macos-latest target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 - with: - python-version: 3.x - - uses: mpi4py/setup-mpi@v1 + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 - name: Build wheels uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-mpi/Cargo.toml - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - - name: Build free-threaded wheels + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-mpi/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + - name: Upload Artifact + uses: actions/upload-artifact@v6 + with: + path: dist + name: mpi-macos-${{ matrix.platform.target }} + sdist-cpu: + name: Build Source Distribution + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ubuntu-22.04 + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Build sdist uses: PyO3/maturin-action@v1 with: - target: ${{ matrix.platform.target }} - args: --release --out dist --manifest-path py-laddu-mpi/Cargo.toml -i python3.13t - sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - - name: Upload wheels - uses: actions/upload-artifact@v5 + command: sdist + args: "--out dist --manifest-path py-laddu-cpu/Cargo.toml" + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: mpi-macos-${{ matrix.platform.target }} path: dist - - mpi-sdist: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false - runs-on: ubuntu-latest + name: cpu-sdist + sdist-mpi: + name: Build Source Distribution + permissions: + contents: read + needs: + - build-check-test + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v6 + - name: Checkout Repository + uses: actions/checkout@v6 - name: Build sdist uses: PyO3/maturin-action@v1 with: command: sdist - args: --out dist --manifest-path py-laddu-mpi/Cargo.toml - - name: Upload sdist - uses: actions/upload-artifact@v5 + args: "--out dist --manifest-path py-laddu-mpi/Cargo.toml" + - name: Upload Artifact + uses: actions/upload-artifact@v6 with: - name: mpi-sdist path: dist - + name: mpi-sdist release: name: Release - runs-on: ubuntu-latest - if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} needs: - - cpu-linux - - cpu-musllinux - - cpu-windows - - cpu-macos - - cpu-sdist - - mpi-linux - - mpi-windows - - mpi-macos - - mpi-sdist + - linux-cpu + - musllinux-cpu + - windows-cpu + - macos-cpu + - linux-mpi + - musllinux-mpi + - windows-mpi + - macos-mpi + - sdist-cpu + - sdist-mpi + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ubuntu-22.04 environment: pypi - permissions: - id-token: write - contents: write steps: - - uses: actions/checkout@v6 - - uses: actions/download-artifact@v6 - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: astral-sh/setup-uv@v7 - - name: Prepare wheel artifacts - run: | - set -euo pipefail - mkdir -p dist/cpu dist/mpi - cp cpu-*/* dist/cpu/ - cp mpi-*/* dist/mpi/ - - name: Publish py-laddu-cpu to PyPI - run: uv publish --trusted-publishing always dist/cpu/* - - name: Publish py-laddu-mpi to PyPI - run: uv publish --trusted-publishing always dist/mpi/* - - name: Build py-laddu distributions - run: | - mkdir -p dist/laddu - uv build py-laddu --out-dir dist/laddu - - name: Publish py-laddu wrapper - run: uv publish --trusted-publishing always dist/laddu/* + - name: Download Artifact + uses: actions/download-artifact@v7 + - name: Setup uv + uses: astral-sh/setup-uv@v7 + - run: uv publish --trusted-publishing always cpu-*/* + - run: uv publish --trusted-publishing always mpi-*/* + - run: |- + uv build py-laddu --out-dir dist + uv publish --trusted-publishing always dist/* \ No newline at end of file diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 00000000..dccf331f --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,30 @@ +--- +name: Release Please +"on": + push: + branches: + - main +jobs: + release-please: + permissions: + contents: read + runs-on: ubuntu-latest + steps: + - name: Run release-please + uses: googleapis/release-please-action@v4 + with: + token: ${{ secrets.RELEASE_PLEASE }} + id: release + - name: Checkout Repository + if: ${{ fromJSON(steps.release.outputs.releases_created) }} + uses: actions/checkout@v6 + - name: Setup Rust + if: ${{ fromJSON(steps.release.outputs.releases_created) }} + uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Install Rust Tool + if: ${{ fromJSON(steps.release.outputs.releases_created) }} + uses: taiki-e/install-action@v2 + with: + tool: cargo-workspaces + - if: ${{ fromJSON(steps.release.outputs.releases_created) }} + run: cargo workspaces publish --from-git --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --yes \ No newline at end of file diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml deleted file mode 100644 index 3c29a0af..00000000 --- a/.github/workflows/release-plz.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Release Plz - -permissions: - pull-requests: write - contents: write - -on: - push: - branches: - - main - -jobs: - release-plz: - name: Release-plz - runs-on: ubuntu-latest - concurrency: - group: release-plz-${{ github.ref }} - cancel-in-progress: false - steps: - - name: Checkout repository - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - name: Install OpenMPI - run: sudo apt install -y openmpi-bin openmpi-doc libopenmpi-dev - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - - name: Run release-plz - uses: release-plz/action@v0.5 - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/release-sync.yml b/.github/workflows/release-sync.yml deleted file mode 100644 index 1c92e54a..00000000 --- a/.github/workflows/release-sync.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Release Version Sync - -on: - pull_request: - branches: ["main"] - types: [opened, reopened, synchronize] - -permissions: - contents: write - pull-requests: read - -env: - CARGO_TERM_COLOR: always - -jobs: - sync-wrapper: - if: contains(github.head_ref, 'release-plz') - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - with: - ref: ${{ github.head_ref }} - - uses: astral-sh/setup-uv@v7 - - name: Install Just - uses: taiki-e/install-action@just - - name: Sync Python wrapper versions - run: | - set -euo pipefail - just sync-versions - if git diff --quiet; then - echo "Versions already in sync" - exit 0 - fi - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git commit -am "chore: sync Python wrapper versions" - git push diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 35aef13a..00000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Rust - -on: - push: - branches: ["main"] - tags: ["*"] - pull_request: - types: [opened, reopened, synchronize, ready_for_review] - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -env: - CARGO_TERM_COLOR: always - -jobs: - clippy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install deps (OpenMPI, clang) - run: | - sudo apt update - sudo apt install -y clang libopenmpi-dev - - uses: dtolnay/rust-toolchain@stable - with: - components: clippy - - name: Install Just - uses: taiki-e/install-action@just - - name: Clippy - run: just lint-rust-mpi - - build-check-test: - if: github.event_name != 'pull_request' || github.event.pull_request.draft == false - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - - name: Install deps (OpenMPI, clang) - run: | - sudo apt update - sudo apt install -y clang libopenmpi-dev - - - name: Toolchain - uses: dtolnay/rust-toolchain@stable - - - name: Install cargo-hack - uses: taiki-e/install-action@cargo-hack - - name: Install Just - uses: taiki-e/install-action@just - - name: Install nextest - uses: taiki-e/install-action@nextest - - name: Install uv - uses: astral-sh/setup-uv@v7 - - - name: Run cargo-hack check - run: just hack-check - - - name: Run tests - run: just test diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml new file mode 100644 index 00000000..c272663f --- /dev/null +++ b/.github/workflows/test-build.yml @@ -0,0 +1,618 @@ +--- +name: Build laddu (Python) +"on": workflow_dispatch +jobs: + linux-cpu: + name: Build Linux Wheels (cpu) + permissions: + contents: read + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-22.04 + target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: armv7 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: s390x + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: ppc64le + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + manylinux: auto + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-cpu/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + musllinux-cpu: + name: Build (musl) Linux Wheels (cpu) + permissions: + contents: read + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-22.04 + target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: armv7 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + manylinux: musllinux_1_2 + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-cpu/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + windows-cpu: + name: Build Windows Wheels (cpu) + permissions: + contents: read + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: windows-latest + target: x64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + python_arch: x64 + - runner: windows-latest + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + python_arch: x86 + - runner: windows-11-arm + target: aarch64 + python_versions: + - "3.12" + - "3.13" + - "3.14" + python_arch: arm64 + fail-fast: false + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + architecture: ${{ matrix.platform.python_arch }} + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-cpu/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + macos-cpu: + name: Build macOS Wheels (cpu) + permissions: + contents: read + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: macos-15-intel + target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: macos-latest + target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-cpu/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + linux-mpi: + name: Build Linux Wheels (mpi) + permissions: + contents: read + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-22.04 + target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: armv7 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: s390x + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: ppc64le + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + manylinux: auto + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-mpi/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + musllinux-mpi: + name: Build (musl) Linux Wheels (mpi) + permissions: + contents: read + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-22.04 + target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: ubuntu-22.04 + target: armv7 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + manylinux: musllinux_1_2 + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-mpi/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + windows-mpi: + name: Build Windows Wheels (mpi) + permissions: + contents: read + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: windows-latest + target: x64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + python_arch: x64 + - runner: windows-latest + target: x86 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + python_arch: x86 + - runner: windows-11-arm + target: aarch64 + python_versions: + - "3.12" + - "3.13" + - "3.14" + python_arch: arm64 + fail-fast: false + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + architecture: ${{ matrix.platform.python_arch }} + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-mpi/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} + macos-mpi: + name: Build macOS Wheels (mpi) + permissions: + contents: read + if: ${{ (startsWith(github.ref, 'refs/tags/py-laddu') || (github.event_name == 'workflow_dispatch')) }} + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: macos-15-intel + target: x86_64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + - runner: macos-latest + target: aarch64 + python_versions: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - 3.13t + - "3.14" + - 3.14t + - pypy3.11 + fail-fast: false + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - run: printf "%s\n" ${{ join(matrix.platform.python_versions, ' ') }} >> version.txt + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version-file: version.txt + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + sccache: ${{ !(startsWith(github.ref, 'refs/tags/')) }} + args: --release --out dist --manifest-path crates/py-laddu-mpi/Cargo.toml --interpreter ${{ join(matrix.platform.python_versions, ' ') }} \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a385699d..a9a74d5d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,13 +11,19 @@ repos: entry: cargo clippy --all-targets language: system pass_filenames: false - - id: ruff - name: ruff - entry: ruff check - language: system - pass_filenames: false - id: ty name: ty entry: ty check py-laddu language: system pass_filenames: false + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.0 + hooks: + - id: ruff-check + args: [ --fix ] + - id: ruff-format + - repo: https://github.com/denehoffman/yamloom + rev: yamloom-v0.5.5 + hooks: + - id: yamloom-sync + files: ^(\.github/workflows/.*\.ya?ml|\.yamloom\.py)$ diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 00000000..bc770d03 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,10 @@ +{ + "crates/laddu": "0.14.1", + "crates/laddu-amplitudes": "0.14.0", + "crates/laddu-core": "0.14.0", + "crates/laddu-extensions": "0.14.1", + "crates/laddu-python": "0.14.0", + "py-laddu-cpu": "0.14.1", + "py-laddu-mpi": "0.14.1", + "py-laddu": "0.14.1" +} diff --git a/.yamloom.py b/.yamloom.py new file mode 100644 index 00000000..944de444 --- /dev/null +++ b/.yamloom.py @@ -0,0 +1,558 @@ +from __future__ import annotations + +from dataclasses import dataclass + +from yamloom import ( + Environment, + Events, + Job, + Matrix, + PullRequestEvent, + PushEvent, + Strategy, + Workflow, + WorkflowCallEvent, + WorkflowDispatchEvent, + WorkflowSecret, + action, + script, +) +from yamloom.actions.ci.coverage import Codecov +from yamloom.actions.github.artifacts import DownloadArtifact, UploadArtifact +from yamloom.actions.github.release import ReleasePlease +from yamloom.actions.github.scm import Checkout +from yamloom.actions.packaging.python import Maturin +from yamloom.actions.toolchains.python import SetupPython, SetupUV +from yamloom.actions.toolchains.rust import InstallRustTool, SetupRust +from yamloom.actions.toolchains.system import SetupMPI +from yamloom.expressions import context + + +@dataclass +class Target: + runner: str + target: str + skip_python_versions: list[str] | None = None + + +DEFAULT_PYTHON_VERSIONS = [ + '3.7', + '3.8', + '3.9', + '3.10', + '3.11', + '3.12', + '3.13', + '3.13t', + '3.14', + '3.14t', + 'pypy3.11', +] + + +@dataclass +class TargetJob: + job_name: str + short_name: str + targets: list[Target] + + +TARGET_JOBS_CPU = [ + TargetJob( + 'Build Linux Wheels', + 'linux', + [ + Target( + 'ubuntu-22.04', + target, + ) + for target in [ + 'x86_64', + 'x86', + 'aarch64', + 'armv7', + 's390x', + 'ppc64le', + ] + ], + ), + TargetJob( + 'Build (musl) Linux Wheels', + 'musllinux', + [ + Target( + 'ubuntu-22.04', + target, + ) + for target in [ + 'x86_64', + 'x86', + 'aarch64', + 'armv7', + ] + ], + ), + TargetJob( + 'Build Windows Wheels', + 'windows', + [ + Target('windows-latest', 'x64'), + Target('windows-latest', 'x86', ['pypy3.11']), + Target( + 'windows-11-arm', + 'aarch64', + ['3.7', '3.8', '3.9', '3.10', '3.11', '3.13t', '3.14t', 'pypy3.11'], + ), + ], + ), + TargetJob( + 'Build macOS Wheels', + 'macos', + [ + Target( + 'macos-15-intel', + 'x86_64', + ), + Target( + 'macos-latest', + 'aarch64', + ), + ], + ), +] + +TARGET_JOBS_MPI = [ + TargetJob( + 'Build Linux Wheels', + 'linux', + [ + Target( + 'ubuntu-22.04', + target, + ) + for target in [ + 'x86_64', + 'x86', + 'aarch64', + 'armv7', + 's390x', + 'ppc64le', + ] + ], + ), + TargetJob( + 'Build (musl) Linux Wheels', + 'musllinux', + [ + Target( + 'ubuntu-22.04', + target, + ) + for target in [ + 'x86_64', + 'x86', + 'aarch64', + 'armv7', + ] + ], + ), + TargetJob( + 'Build Windows Wheels', + 'windows', + [ + Target('windows-latest', 'x64'), + Target('windows-latest', 'x86', ['pypy3.11']), + Target( + 'windows-11-arm', + 'aarch64', + ['3.7', '3.8', '3.9', '3.10', '3.11', '3.13t', '3.14t', 'pypy3.11'], + ), + ], + ), + TargetJob( + 'Build macOS Wheels', + 'macos', + [ + Target( + 'macos-15-intel', + 'x86_64', + ), + Target( + 'macos-latest', + 'aarch64', + ), + ], + ), +] + + +def resolve_python_versions(skip: list[str] | None) -> list[str]: + if not skip: + return DEFAULT_PYTHON_VERSIONS + skipped = set(skip) + return [version for version in DEFAULT_PYTHON_VERSIONS if version not in skipped] + + +def create_build_job( + job_name: str, + name: str, + targets: list[Target], + *, + mpi: bool, + needs: list[str] | None = None, + upload: bool = True, +) -> Job: + def platform_entry(target: Target) -> dict[str, object]: + entry = { + 'runner': target.runner, + 'target': target.target, + 'python_versions': resolve_python_versions(target.skip_python_versions), + } + python_arch = ( + ('arm64' if target.target == 'aarch64' else target.target) + if name == 'windows' + else None + ) + if python_arch is not None: + entry['python_arch'] = python_arch + return entry + + return Job( + steps=[ + Checkout(), + script( + f'printf "%s\n" {context.matrix.platform.python_versions.as_array().join(" ")} >> version.txt', + ), + SetupPython( + python_version_file='version.txt', + architecture=context.matrix.platform.python_arch.as_str() + if name == 'windows' + else None, + ), + ] + + ([SetupMPI()] if mpi else []) + + [ + Maturin( + name='Build wheels', + target=context.matrix.platform.target.as_str(), + args=f'--release --out dist --manifest-path crates/py-laddu-{"mpi" if mpi else "cpu"}/Cargo.toml --interpreter {context.matrix.platform.python_versions.as_array().join(" ")}', + sccache=~context.github.ref.startswith('refs/tags/'), + manylinux='musllinux_1_2' + if name == 'musllinux' + else ('auto' if name == 'linux' else None), + ), + ] + + ( + [ + UploadArtifact( + path='dist', + artifact_name=f'{"mpi" if mpi else "cpu"}-{name}-{context.matrix.platform.target}', + ) + ] + if upload + else [] + ), + name=f'{job_name} ({"mpi" if mpi else "cpu"})', + runs_on=context.matrix.platform.runner.as_str(), + strategy=Strategy( + fast_fail=False, + matrix=Matrix( + platform=[platform_entry(target) for target in targets], + ), + ), + needs=needs, + condition=context.github.ref.startswith('refs/tags/py-laddu') + | (context.github.event_name == 'workflow_dispatch'), + ) + + +test_build_workflow = Workflow( + name='Build laddu (Python)', + on=Events( + workflow_dispatch=WorkflowDispatchEvent(), + ), + jobs={ + **{ + f'{tj.short_name}-cpu': create_build_job( + tj.job_name, tj.short_name, tj.targets, mpi=False, upload=False + ) + for tj in TARGET_JOBS_CPU + }, + **{ + f'{tj.short_name}-mpi': create_build_job( + tj.job_name, tj.short_name, tj.targets, mpi=True, upload=False + ) + for tj in TARGET_JOBS_CPU + }, + }, +) + + +python_release_workflow = Workflow( + name='Build and Release laddu (Python)', + on=Events( + push=PushEvent( + branches=['main'], tags=['py-laddu*', '!py-laddu-cpu*', '!py-laddu-mpi*'] + ), + pull_request=PullRequestEvent(opened=True, synchronize=True, reopened=True), + workflow_dispatch=WorkflowDispatchEvent(), + ), + jobs={ + 'build-check-test': Job( + steps=[ + Checkout(), + SetupRust(components=['clippy']), + SetupUV(python_version='3.10'), + SetupMPI(), + script('cargo clippy'), + InstallRustTool(tool=['cargo-hack']), + script( + 'cargo hack check --rust-version --feature-powerset --no-dev-deps' + ), + script('cargo hack test --feature-powerset'), + script( + 'uv venv', + '. .venv/bin/activate', + 'echo PATH=$PATH >> $GITHUB_ENV', + 'uvx --with "maturin[patchelf]>=1.7,<2" maturin build --manifest-path py-laddu-cpu/Cargo.toml --release -o py-laddu-cpu/dist', + 'uv pip install --no-cache-dir --find-links py-laddu-cpu/dist laddu-cpu', + 'uv pip install --no-cache-dir -e "py-laddu[tests]"', + ), + script('uvx ruff check . --extend-exclude=.yamloom.py'), + script('uvx ty check . --exclude=.yamloom.py'), + script('uv run pytest'), + ], + runs_on='ubuntu-latest', + ), + **{ + f'{tj.short_name}-cpu': create_build_job( + tj.job_name, + tj.short_name, + tj.targets, + needs=['build-check-test'], + mpi=False, + ) + for tj in TARGET_JOBS_CPU + }, + **{ + f'{tj.short_name}-mpi': create_build_job( + tj.job_name, + tj.short_name, + tj.targets, + needs=['build-check-test'], + mpi=True, + ) + for tj in TARGET_JOBS_CPU + }, + 'sdist-cpu': Job( + steps=[ + Checkout(), + Maturin( + name='Build sdist', + command='sdist', + args='--out dist --manifest-path py-laddu-cpu/Cargo.toml', + ), + UploadArtifact(path='dist', artifact_name='cpu-sdist'), + ], + name='Build Source Distribution', + runs_on='ubuntu-22.04', + needs=['build-check-test'], + condition=context.github.ref.startswith('refs/tags/py-laddu') + | (context.github.event_name == 'workflow_dispatch'), + ), + 'sdist-mpi': Job( + steps=[ + Checkout(), + Maturin( + name='Build sdist', + command='sdist', + args='--out dist --manifest-path py-laddu-mpi/Cargo.toml', + ), + UploadArtifact(path='dist', artifact_name='mpi-sdist'), + ], + name='Build Source Distribution', + runs_on='ubuntu-22.04', + needs=['build-check-test'], + condition=context.github.ref.startswith('refs/tags/py-laddu') + | (context.github.event_name == 'workflow_dispatch'), + ), + 'release': Job( + steps=[ + DownloadArtifact(), + SetupUV(), + script( + 'uv publish --trusted-publishing always cpu-*/*', + ), + script( + 'uv publish --trusted-publishing always mpi-*/*', + ), + script( + 'uv build py-laddu --out-dir dist', + 'uv publish --trusted-publishing always dist/*', + ), + ], + name='Release', + runs_on='ubuntu-22.04', + condition=context.github.ref.startswith('refs/tags/py-laddu') + | (context.github.event_name == 'workflow_dispatch'), + needs=[ + *[f'{tj.short_name}-cpu' for tj in TARGET_JOBS_CPU], + *[f'{tj.short_name}-mpi' for tj in TARGET_JOBS_MPI], + 'sdist-cpu', + 'sdist-mpi', + ], + environment=Environment('pypi'), + ), + }, +) + +release_please_workflow = Workflow( + name='Release Please', + on=Events( + push=PushEvent( + branches=['main'], + ), + ), + jobs={ + 'release-please': Job( + steps=[ + ReleasePlease( + id='release', + token=context.secrets.RELEASE_PLEASE, + ), + Checkout( + condition=ReleasePlease.releases_created( + 'release' + ).from_json_to_bool() + ), + SetupRust( + condition=ReleasePlease.releases_created( + 'release' + ).from_json_to_bool() + ), + InstallRustTool( + tool=['cargo-workspaces'], + condition=ReleasePlease.releases_created( + 'release' + ).from_json_to_bool(), + ), + script( + f'cargo workspaces publish --from-git --token {context.secrets.CARGO_REGISTRY_TOKEN} --yes', + condition=ReleasePlease.releases_created( + 'release' + ).from_json_to_bool(), + ), + ], + runs_on='ubuntu-latest', + ) + }, +) + +benchmark_workflow = Workflow( + name='CodSpeed Benchmarks', + on=Events( + push=PushEvent(branches=['main']), + pull_request=PullRequestEvent(opened=True, synchronize=True, reopened=True), + workflow_dispatch=WorkflowDispatchEvent(), + ), + jobs={ + 'benchmarks': Job( + steps=[ + Checkout(), + SetupRust(), + InstallRustTool(tool=['cargo-codspeed']), + script('cargo codspeed build'), + action( + 'CodSpeed Action', + 'CodSpeedHQ/action', + ref='v4', + with_opts={ + 'mode': 'simulation', + 'run': 'cargo codspeed run', + 'token': context.secrets.CODSPEED_TOKEN, + }, + ), + ], + name='Run Benchmarks', + runs_on='ubuntu-latest', + ) + }, +) + +coverage_workflow = Workflow( + name='Coverage', + on=Events( + push=PushEvent( + branches=['main'], paths=['**.rs', '**.py', '.github/workflows/coverage.yml'] + ), + pull_request=PullRequestEvent( + opened=True, + synchronize=True, + reopened=True, + paths=['**.rs', '**.py', '.github/workflows/coverage.yml'], + ), + workflow_call=WorkflowCallEvent( + secrets={'codecov_token': WorkflowSecret(required=True)} + ), + workflow_dispatch=WorkflowDispatchEvent(), + ), + jobs={ + 'coverage-rust': Job( + steps=[ + Checkout(), + SetupRust(toolchain='nightly'), + SetupMPI(), + InstallRustTool(tool=['cargo-llvm-cov']), + script( + 'cargo llvm-cov --workspace --lcov --output-path coverage-rust.lcov --summary-only --exclude-from-report py-laddu' + ), + UploadArtifact(path='coverage-rust.lcov', artifact_name='coverage-rust'), + ], + runs_on='ubuntu-latest', + env={'CARGO_TERM_COLOR': 'always'}, + ), + 'coverage-python': Job( + steps=[ + Checkout(), + SetupRust(), + SetupUV(), + script( + 'uv venv', + '. .venv/bin/activate', + 'echo PATH=$PATH >> $GITHUB_ENV', + 'uvx --with "maturin[patchelf]>=1.7,<2" maturin build --manifest-path py-laddu-cpu/Cargo.toml --release -o py-laddu-cpu/dist', + 'uv pip install --no-cache-dir --find-links py-laddu-cpu/dist laddu-cpu', + 'uv pip install --no-cache-dir -e "py-laddu[tests]"', + 'pytest --cov --cov-report xml:coverage-python.xml', + ), + UploadArtifact( + path='coverage-python.xml', artifact_name='coverage-python' + ), + ], + runs_on='ubuntu-latest', + env={'CARGO_TERM_COLOR': 'always'}, + ), + 'upload-coverage': Job( + steps=[ + Checkout(), + DownloadArtifact(merge_multiple=True), + Codecov( + token=context.secrets.CODECOV_TOKEN, + files='coverage-rust.lcov,coverage-python.xml', + fail_ci_if_error=True, + verbose=True, + root_dir=context.github.workspace, + ), + ], + runs_on='ubuntu-latest', + needs=['coverage-rust', 'coverage-python'], + ), + }, +) + +if __name__ == '__main__': + test_build_workflow.dump('.github/workflows/test-build.yml') + python_release_workflow.dump('.github/workflows/python-release.yml') + release_please_workflow.dump('.github/workflows/release-please.yml') + benchmark_workflow.dump('.github/workflows/benchmark.yml') + coverage_workflow.dump('.github/workflows/coverage.yml') diff --git a/Cargo.toml b/Cargo.toml index 60a0845f..a0fb7739 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,18 +54,16 @@ laddu-extensions = { version = "0.14.1", path = "crates/laddu-extensions" } laddu-python = { version = "0.14.0", path = "crates/laddu-python" } [profile.release] -lto = "thin" +lto = "fat" debug = false +codegen-units = 1 -[profile.debug-release] +[profile.bench] inherits = "release" -debug = true -[profile.dist-release] +[profile.debug-release] inherits = "release" -codegen-units = 1 -debug = false -lto = "fat" +debug = true [profile.profiling] inherits = "release" diff --git a/Justfile b/Justfile index 5b22ecc6..b9fc6889 100644 --- a/Justfile +++ b/Justfile @@ -15,11 +15,11 @@ create-venv: # Build the laddu-cpu wheel build-python-cpu: create-venv - uvx --with "maturin[patchelf]>=1.7,<2" maturin build --manifest-path py-laddu-cpu/Cargo.toml --release -o py-laddu-cpu/dist + uvx --with "maturin[patchelf]" maturin build --manifest-path py-laddu-cpu/Cargo.toml --release -o py-laddu-cpu/dist # Build the laddu-mpi wheel build-python-mpi: create-venv - uvx --with "maturin[patchelf]>=1.7,<2" maturin build --manifest-path py-laddu-mpi/Cargo.toml --release -o py-laddu-mpi/dist + uvx --with "maturin[patchelf]" maturin build --manifest-path py-laddu-mpi/Cargo.toml --release -o py-laddu-mpi/dist # Build both laddu-cpu and laddu-mpi wheels build-python: build-python-cpu build-python-mpi diff --git a/crates/laddu-core/src/data.rs b/crates/laddu-core/src/data.rs index 8af0f78c..d2f253e1 100644 --- a/crates/laddu-core/src/data.rs +++ b/crates/laddu-core/src/data.rs @@ -1,3 +1,6 @@ +#[cfg(feature = "mpi")] +use crate::mpi::LadduMPI; +#[cfg(feature = "rayon")] use accurate::{sum::Klein, traits::*}; use arrow::{ array::{Float32Array, Float64Array}, @@ -5,26 +8,23 @@ use arrow::{ record_batch::RecordBatch, }; use auto_ops::impl_op_ex; +#[cfg(feature = "mpi")] +use mpi::{datatype::PartitionMut, topology::SimpleCommunicator, traits::*}; +use oxyroot::{Branch, Named, ReaderTree, RootFile, WriterTree}; use parking_lot::Mutex; use parquet::arrow::{arrow_reader::ParquetRecordBatchReaderBuilder, ArrowWriter}; #[cfg(feature = "mpi")] use parquet::file::metadata::ParquetMetaData; -use serde::{Deserialize, Serialize}; -use std::ops::{Deref, DerefMut, Index, IndexMut}; -use std::path::Path; -use std::{fmt::Display, fs::File}; -use std::{path::PathBuf, sync::Arc}; - -use oxyroot::{Branch, Named, ReaderTree, RootFile, WriterTree}; - #[cfg(feature = "rayon")] use rayon::prelude::*; - -#[cfg(feature = "mpi")] -use mpi::{datatype::PartitionMut, topology::SimpleCommunicator, traits::*}; - -#[cfg(feature = "mpi")] -use crate::mpi::LadduMPI; +use serde::{Deserialize, Serialize}; +use std::{ + fmt::Display, + fs::File, + ops::{Deref, DerefMut, Index, IndexMut}, + path::{Path, PathBuf}, + sync::Arc, +}; #[cfg(feature = "mpi")] type WorldHandle = SimpleCommunicator; @@ -1978,7 +1978,7 @@ fn find_float_column_from_candidates<'a>( return Err(LadduError::InvalidColumnType { name: candidate.clone(), datatype: other.to_string(), - }) + }); } }; } diff --git a/crates/laddu-core/test_data/write_data.py b/crates/laddu-core/test_data/write_data.py index 56178ab1..530d7b54 100755 --- a/crates/laddu-core/test_data/write_data.py +++ b/crates/laddu-core/test_data/write_data.py @@ -19,10 +19,12 @@ def read_parquet() -> pl.DataFrame: def convert_to_f64(df: pl.DataFrame) -> pl.DataFrame: - return df.lazy().select(*[pl.col(col).cast(pl.Float64) for col in df.columns]).collect() + return ( + df.lazy().select(*[pl.col(col).cast(pl.Float64) for col in df.columns]).collect() + ) -def write_root(tree: str = 'events'): +def write_root(tree: str = 'events') -> None: df_parquet_f32 = read_parquet() file_root_f32 = uproot.recreate('data_f32.root') file_root_f32.mktree(tree, df_parquet_f32.to_dict()) @@ -31,7 +33,7 @@ def write_root(tree: str = 'events'): file_root_f64.mktree(tree, df_parquet_f64.to_dict()) -def write_amptools(tree: str = 'kin'): +def write_amptools(tree: str = 'kin') -> None: df_parquet_f32 = read_parquet() file_amptools = uproot.recreate('data_amptools.root') df_dict_f32 = df_parquet_f32.to_dict() @@ -42,20 +44,46 @@ def write_amptools(tree: str = 'kin'): 'Pz_Beam': df_dict_f32['beam_pz'], 'NumFinalState': np.full(len(df_dict_f32['proton_e']), 3, dtype=np.int32), 'E_FinalState': ak.Array( - np.array([df_dict_f32['proton_e'], df_dict_f32['kshort1_e'], df_dict_f32['kshort2_e']]).transpose().tolist() + np.array( + [ + df_dict_f32['proton_e'], + df_dict_f32['kshort1_e'], + df_dict_f32['kshort2_e'], + ] + ) + .transpose() + .tolist() ), 'Px_FinalState': ak.Array( - np.array([df_dict_f32['proton_px'], df_dict_f32['kshort1_px'], df_dict_f32['kshort2_px']]) + np.array( + [ + df_dict_f32['proton_px'], + df_dict_f32['kshort1_px'], + df_dict_f32['kshort2_px'], + ] + ) .transpose() .tolist() ), 'Py_FinalState': ak.Array( - np.array([df_dict_f32['proton_py'], df_dict_f32['kshort1_py'], df_dict_f32['kshort2_py']]) + np.array( + [ + df_dict_f32['proton_py'], + df_dict_f32['kshort1_py'], + df_dict_f32['kshort2_py'], + ] + ) .transpose() .tolist() ), 'Pz_FinalState': ak.Array( - np.array([df_dict_f32['proton_pz'], df_dict_f32['kshort1_pz'], df_dict_f32['kshort2_pz']]) + np.array( + [ + df_dict_f32['proton_pz'], + df_dict_f32['kshort1_pz'], + df_dict_f32['kshort2_pz'], + ] + ) .transpose() .tolist() ), @@ -70,20 +98,46 @@ def write_amptools(tree: str = 'kin'): 'Pz_Beam': df_dict_f32['beam_pz'], 'NumFinalState': np.full(len(df_dict_f32['proton_e']), 3, dtype=np.int32), 'E_FinalState': ak.Array( - np.array([df_dict_f32['proton_e'], df_dict_f32['kshort1_e'], df_dict_f32['kshort2_e']]).transpose().tolist() + np.array( + [ + df_dict_f32['proton_e'], + df_dict_f32['kshort1_e'], + df_dict_f32['kshort2_e'], + ] + ) + .transpose() + .tolist() ), 'Px_FinalState': ak.Array( - np.array([df_dict_f32['proton_px'], df_dict_f32['kshort1_px'], df_dict_f32['kshort2_px']]) + np.array( + [ + df_dict_f32['proton_px'], + df_dict_f32['kshort1_px'], + df_dict_f32['kshort2_px'], + ] + ) .transpose() .tolist() ), 'Py_FinalState': ak.Array( - np.array([df_dict_f32['proton_py'], df_dict_f32['kshort1_py'], df_dict_f32['kshort2_py']]) + np.array( + [ + df_dict_f32['proton_py'], + df_dict_f32['kshort1_py'], + df_dict_f32['kshort2_py'], + ] + ) .transpose() .tolist() ), 'Pz_FinalState': ak.Array( - np.array([df_dict_f32['proton_pz'], df_dict_f32['kshort1_pz'], df_dict_f32['kshort2_pz']]) + np.array( + [ + df_dict_f32['proton_pz'], + df_dict_f32['kshort1_pz'], + df_dict_f32['kshort2_pz'], + ] + ) .transpose() .tolist() ), @@ -92,7 +146,7 @@ def write_amptools(tree: str = 'kin'): file_amptools_pol.mktree(tree, df_amptools_pol_dict) -def main(): +def main() -> None: df_parquet_f32 = read_parquet() convert_to_f64(df_parquet_f32).write_parquet('data_f64.parquet') write_root() diff --git a/crates/laddu-extensions/src/ganesh_ext.rs b/crates/laddu-extensions/src/ganesh_ext.rs index a29512aa..ee11eb2f 100644 --- a/crates/laddu-extensions/src/ganesh_ext.rs +++ b/crates/laddu-extensions/src/ganesh_ext.rs @@ -192,6 +192,7 @@ where } impl CostFunction for NLL { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate(&self, parameters: &DVector, args: &MaybeThreadPool) -> LadduResult { #[cfg(feature = "rayon")] { @@ -206,6 +207,7 @@ impl CostFunction for NLL { } } impl Gradient for NLL { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn gradient( &self, parameters: &DVector, @@ -224,6 +226,7 @@ impl Gradient for NLL { } } impl LogDensity for NLL { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn log_density(&self, parameters: &DVector, args: &MaybeThreadPool) -> LadduResult { #[cfg(feature = "rayon")] { @@ -330,6 +333,7 @@ impl NLL { } impl CostFunction for StochasticNLL { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate(&self, parameters: &DVector, args: &MaybeThreadPool) -> LadduResult { #[cfg(feature = "rayon")] { @@ -344,6 +348,7 @@ impl CostFunction for StochasticNLL { } } impl Gradient for StochasticNLL { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn gradient( &self, parameters: &DVector, @@ -362,6 +367,7 @@ impl Gradient for StochasticNLL { } } impl LogDensity for StochasticNLL { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn log_density(&self, parameters: &DVector, args: &MaybeThreadPool) -> LadduResult { #[cfg(feature = "rayon")] { @@ -468,6 +474,7 @@ impl StochasticNLL { } impl CostFunction for LikelihoodEvaluator { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate(&self, parameters: &DVector, args: &MaybeThreadPool) -> LadduResult { #[cfg(feature = "rayon")] { @@ -482,6 +489,7 @@ impl CostFunction for LikelihoodEvaluator { } } impl Gradient for LikelihoodEvaluator { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn gradient( &self, parameters: &DVector, @@ -500,6 +508,7 @@ impl Gradient for LikelihoodEvaluator { } } impl LogDensity for LikelihoodEvaluator { + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn log_density(&self, parameters: &DVector, args: &MaybeThreadPool) -> LadduResult { #[cfg(feature = "rayon")] { diff --git a/crates/laddu-extensions/src/likelihoods.rs b/crates/laddu-extensions/src/likelihoods.rs index 5066fe8f..c5675e14 100644 --- a/crates/laddu-extensions/src/likelihoods.rs +++ b/crates/laddu-extensions/src/likelihoods.rs @@ -1814,6 +1814,7 @@ impl PyNLL { /// If there was an error building the thread pool /// #[pyo3(signature = (parameters, *, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate(&self, parameters: Vec, threads: Option) -> PyResult { #[cfg(feature = "rayon")] { @@ -1849,6 +1850,7 @@ impl PyNLL { /// ``numpy`` array /// #[pyo3(signature = (parameters, *, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate_gradient<'py>( &self, py: Python<'py>, @@ -1902,6 +1904,7 @@ impl PyNLL { /// ``numpy`` array /// #[pyo3(signature = (parameters, *, mc_evaluator = None, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn project<'py>( &self, py: Python<'py>, @@ -1973,6 +1976,7 @@ impl PyNLL { /// If `arg` or any items of `arg` are not registered Amplitudes /// #[pyo3(signature = (parameters, arg, *, mc_evaluator = None, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn project_with<'py>( &self, py: Python<'py>, @@ -3589,6 +3593,7 @@ impl PyLikelihoodEvaluator { /// If there was an error building the thread pool /// #[pyo3(signature = (parameters, *, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate(&self, parameters: Vec, threads: Option) -> PyResult { #[cfg(feature = "rayon")] { @@ -3625,6 +3630,7 @@ impl PyLikelihoodEvaluator { /// ``numpy`` array /// #[pyo3(signature = (parameters, *, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate_gradient<'py>( &self, py: Python<'py>, diff --git a/crates/laddu-python/src/amplitudes.rs b/crates/laddu-python/src/amplitudes.rs index e0896510..4edad797 100644 --- a/crates/laddu-python/src/amplitudes.rs +++ b/crates/laddu-python/src/amplitudes.rs @@ -494,6 +494,7 @@ impl PyEvaluator { /// If there was an error building the thread pool /// #[pyo3(signature = (parameters, *, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate<'py>( &self, py: Python<'py>, @@ -538,6 +539,7 @@ impl PyEvaluator { /// If there was an error building the thread pool /// #[pyo3(signature = (parameters, indices, *, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate_batch<'py>( &self, py: Python<'py>, @@ -585,6 +587,7 @@ impl PyEvaluator { /// ``numpy`` array /// #[pyo3(signature = (parameters, *, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate_gradient<'py>( &self, py: Python<'py>, @@ -646,6 +649,7 @@ impl PyEvaluator { /// ``numpy`` array /// #[pyo3(signature = (parameters, indices, *, threads=None))] + #[cfg_attr(not(feature = "rayon"), allow(unused_variables))] fn evaluate_gradient_batch<'py>( &self, py: Python<'py>, diff --git a/py-laddu-cpu/Cargo.toml b/py-laddu-cpu/Cargo.toml index 7511978b..7a7228fd 100644 --- a/py-laddu-cpu/Cargo.toml +++ b/py-laddu-cpu/Cargo.toml @@ -22,8 +22,9 @@ laddu-python = { workspace = true } pyo3 = { workspace = true, features = [ "num-complex", - "abi3-py37", + "abi3", "extension-module", + "generate-import-lib" ] } [features] diff --git a/py-laddu-cpu/pyproject.toml b/py-laddu-cpu/pyproject.toml index 5e78025c..df6ca757 100644 --- a/py-laddu-cpu/pyproject.toml +++ b/py-laddu-cpu/pyproject.toml @@ -37,105 +37,9 @@ uproot = ["uproot"] [tool.maturin] bindings = "pyo3" strip = true -profile = "dist-release" +profile = "release" sdist-include = ['../Cargo.lock'] -[tool.ruff] -target-version = "py37" -indent-width = 4 -line-length = 90 -fix = true -exclude = [ - ".bzr", - ".direnv", - ".eggs", - ".git", - ".git-rewrite", - ".hg", - ".ipynb_checkpoints", - ".mypy_cache", - ".nox", - ".pants.d", - ".pyenv", - ".pytest_cache", - ".pytype", - ".ruff_cache", - ".svn", - ".tox", - ".venv", - ".vscode", - "__pypackages__", - "_build", - "buck-out", - "build", - "dist", - "node_modules", - "site-packages", - "venv", -] - -[tool.ruff.lint] -select = [ - "ANN", # flake8-annotations - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "D", # flake8-docstrings - "E", # pycodestyle - "EM", # flake8-errmsg - "F", # pyflakes - "FA", # flake8-future-annotations - "FBT001", # flake8-boolean-trap - "I", # isort - "ICN", # flake8-import-conventions - "INT", # flake8-gettext - "PERF", # perflint - "PIE", # flake8-pie - "PT", # flake8-pytest-style - "PTH", # flake8-use-pathlib - "PYI", # flake8-pyi - "RUF", # ruff-specific rules - "SIM", # flake8-simplify - "TCH", # flake8-type-checking - "TD", # flake8-todos - "TID", # flake8-tidy-imports - "TRY", # tryceratops - "UP", # pyupgrade - "W", # pycodestyle -] -ignore = [ - "D100", # Missing docstring in public module - "D101", # Missing docstring in public class - "D102", # Missing docstring in public method - "D103", # Missing docstring in public function - "D104", # Missing docstring in public package - "D105", # Missing docstring in magic method - # ------------------------------------------------------------------ - "ANN401", # Dynamically typed expressions (Any) are disallowed - "E501", # Line length regulated by formatter - "PT011", # pytest.raises is too broad, set match or use a more specific exception - "PYI041", # Use float instead of int | float - "RUF005", # Consider expression instead of concatenation - "SIM102", # Use a single `if` statement instead of nested `if` statements - "SIM114", # Combine `if` branches - "TD002", # Missing author in TODO - "TD003", # Missing issue link on the line following this TODO - "TRY003", # Avoid specifying long messages outside the exception class - "PYI021", # Avoid docstring in stub file - "E741", # Ambiguous variable names - "RUF001", # Ambiguous character in string -] - -[tool.ruff.lint.pydocstyle] -convention = "numpy" - -[tool.ruff.format] -line-ending = "auto" -quote-style = "single" -indent-style = "space" -skip-magic-trailing-comma = false -docstring-code-format = false -docstring-code-line-length = "dynamic" - [tool.coverage.run] source = ["laddu"] omit = [ diff --git a/py-laddu-mpi/Cargo.toml b/py-laddu-mpi/Cargo.toml index f3032f5a..eb0406e1 100644 --- a/py-laddu-mpi/Cargo.toml +++ b/py-laddu-mpi/Cargo.toml @@ -22,8 +22,9 @@ laddu-python = { workspace = true } pyo3 = { workspace = true, features = [ "num-complex", - "abi3-py37", + "abi3", "extension-module", + "generate-import-lib" ] } [features] diff --git a/py-laddu-mpi/pyproject.toml b/py-laddu-mpi/pyproject.toml index 9ae950aa..452a7cbf 100644 --- a/py-laddu-mpi/pyproject.toml +++ b/py-laddu-mpi/pyproject.toml @@ -37,105 +37,10 @@ uproot = ["uproot"] [tool.maturin] bindings = "pyo3" strip = true -profile = "dist-release" +profile = "release" sdist-include = ['../Cargo.lock'] features = ["mpi"] -[tool.ruff] -target-version = "py37" -indent-width = 4 -line-length = 90 -fix = true -exclude = [ - ".bzr", - ".direnv", - ".eggs", - ".git", - ".git-rewrite", - ".hg", - ".ipynb_checkpoints", - ".mypy_cache", - ".nox", - ".pants.d", - ".pyenv", - ".pytest_cache", - ".pytype", - ".ruff_cache", - ".svn", - ".tox", - ".venv", - ".vscode", - "__pypackages__", - "_build", - "buck-out", - "build", - "dist", - "node_modules", - "site-packages", - "venv", -] - -[tool.ruff.lint] -select = [ - "ANN", # flake8-annotations - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "D", # flake8-docstrings - "E", # pycodestyle - "EM", # flake8-errmsg - "F", # pyflakes - "FA", # flake8-future-annotations - "FBT001", # flake8-boolean-trap - "I", # isort - "ICN", # flake8-import-conventions - "INT", # flake8-gettext - "PERF", # perflint - "PIE", # flake8-pie - "PT", # flake8-pytest-style - "PTH", # flake8-use-pathlib - "PYI", # flake8-pyi - "RUF", # ruff-specific rules - "SIM", # flake8-simplify - "TCH", # flake8-type-checking - "TD", # flake8-todos - "TID", # flake8-tidy-imports - "TRY", # tryceratops - "UP", # pyupgrade - "W", # pycodestyle -] -ignore = [ - "D100", # Missing docstring in public module - "D101", # Missing docstring in public class - "D102", # Missing docstring in public method - "D103", # Missing docstring in public function - "D104", # Missing docstring in public package - "D105", # Missing docstring in magic method - # ------------------------------------------------------------------ - "ANN401", # Dynamically typed expressions (Any) are disallowed - "E501", # Line length regulated by formatter - "PT011", # pytest.raises is too broad, set match or use a more specific exception - "PYI041", # Use float instead of int | float - "RUF005", # Consider expression instead of concatenation - "SIM102", # Use a single `if` statement instead of nested `if` statements - "SIM114", # Combine `if` branches - "TD002", # Missing author in TODO - "TD003", # Missing issue link on the line following this TODO - "TRY003", # Avoid specifying long messages outside the exception class - "PYI021", # Avoid docstring in stub file - "E741", # Ambiguous variable names -] - -[tool.ruff.lint.pydocstyle] -convention = "numpy" - -[tool.ruff.format] -line-ending = "auto" -quote-style = "single" -indent-style = "space" -skip-magic-trailing-comma = false -docstring-code-format = false -docstring-code-line-length = "dynamic" - [tool.coverage.run] source = ["laddu"] omit = [ diff --git a/py-laddu/examples/example_1/example_1.py b/py-laddu/examples/example_1/example_1.py index 8f40cd62..6805883e 100755 --- a/py-laddu/examples/example_1/example_1.py +++ b/py-laddu/examples/example_1/example_1.py @@ -27,6 +27,7 @@ from pathlib import Path from time import perf_counter +import laddu as ld import matplotlib.pyplot as plt import numpy as np import uncertainties.umath as unp @@ -36,8 +37,6 @@ from rich.table import Table from uncertainties import ufloat -import laddu as ld - def main(bins: int, niters: int, nboot: int) -> None: script_dir = Path(os.path.realpath(__file__)).parent.resolve() diff --git a/py-laddu/examples/example_1/example_1_mcmc.py b/py-laddu/examples/example_1/example_1_mcmc.py index 848394d1..d49d34ba 100644 --- a/py-laddu/examples/example_1/example_1_mcmc.py +++ b/py-laddu/examples/example_1/example_1_mcmc.py @@ -14,13 +14,12 @@ import pickle from pathlib import Path +import laddu as ld import matplotlib.pyplot as plt import numpy as np from corner import corner from loguru import logger -import laddu as ld - # This custom terminator differs from the one provided by `laddu`. Rather than tracing the # walker positions and calculating the IAT, this first projects the current walker positions diff --git a/py-laddu/examples/example_2/example_2.py b/py-laddu/examples/example_2/example_2.py index 9f275914..d64add4c 100755 --- a/py-laddu/examples/example_2/example_2.py +++ b/py-laddu/examples/example_2/example_2.py @@ -24,12 +24,11 @@ from pathlib import Path from typing import TYPE_CHECKING +import laddu as ld import matplotlib.pyplot as plt import numpy as np from docopt import docopt -import laddu as ld - if TYPE_CHECKING: from numpy.typing import NDArray diff --git a/py-laddu/examples/example_mpi/example_mpi.py b/py-laddu/examples/example_mpi/example_mpi.py index 5359f244..8785e832 100755 --- a/py-laddu/examples/example_mpi/example_mpi.py +++ b/py-laddu/examples/example_mpi/example_mpi.py @@ -12,9 +12,8 @@ from dataclasses import dataclass from pathlib import Path -import numpy as np - import laddu as ld +import numpy as np @dataclass diff --git a/py-laddu/pyproject.toml b/py-laddu/pyproject.toml index 001f49b3..e866facc 100644 --- a/py-laddu/pyproject.toml +++ b/py-laddu/pyproject.toml @@ -36,7 +36,7 @@ description = "Python bindings for laddu" license = "MIT" readme = "README.md" dependencies = [ - "laddu-cpu == 0.14.1", + "laddu-cpu == 0.14.1", # x-release-please-version # WARNING: DO NOT EDIT "numpy", ] @@ -49,7 +49,7 @@ pandas = ["pandas"] polars = ["polars"] tests = ["pytest", "pytest-cov", "pandas", "polars", "uproot"] uproot = ["uproot"] -mpi = ["laddu-mpi == 0.14.1"] +mpi = ["laddu-mpi == 0.14.1"] # x-release-please-version #WARNING: DO NOT EDIT [tool.maturin] bindings = "pyo3" @@ -57,102 +57,6 @@ strip = true profile = "dist-release" sdist-include = ['../Cargo.lock'] -[tool.ruff] -target-version = "py38" -indent-width = 4 -line-length = 90 -fix = true -exclude = [ - ".bzr", - ".direnv", - ".eggs", - ".git", - ".git-rewrite", - ".hg", - ".ipynb_checkpoints", - ".mypy_cache", - ".nox", - ".pants.d", - ".pyenv", - ".pytest_cache", - ".pytype", - ".ruff_cache", - ".svn", - ".tox", - ".venv", - ".vscode", - "__pypackages__", - "_build", - "buck-out", - "build", - "dist", - "node_modules", - "site-packages", - "venv", -] - -[tool.ruff.lint] -select = [ - "ANN", # flake8-annotations - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "D", # flake8-docstrings - "E", # pycodestyle - "EM", # flake8-errmsg - "F", # pyflakes - "FA", # flake8-future-annotations - "FBT001", # flake8-boolean-trap - "I", # isort - "ICN", # flake8-import-conventions - "INT", # flake8-gettext - "PERF", # perflint - "PIE", # flake8-pie - "PT", # flake8-pytest-style - "PTH", # flake8-use-pathlib - "PYI", # flake8-pyi - "RUF", # ruff-specific rules - "SIM", # flake8-simplify - "TCH", # flake8-type-checking - "TD", # flake8-todos - "TID", # flake8-tidy-imports - "TRY", # tryceratops - "UP", # pyupgrade - "W", # pycodestyle -] -ignore = [ - "D100", # Missing docstring in public module - "D101", # Missing docstring in public class - "D102", # Missing docstring in public method - "D103", # Missing docstring in public function - "D104", # Missing docstring in public package - "D105", # Missing docstring in magic method - # ------------------------------------------------------------------ - "ANN401", # Dynamically typed expressions (Any) are disallowed - "E501", # Line length regulated by formatter - "PT011", # pytest.raises is too broad, set match or use a more specific exception - "PYI041", # Use float instead of int | float - "RUF005", # Consider expression instead of concatenation - "SIM102", # Use a single `if` statement instead of nested `if` statements - "SIM114", # Combine `if` branches - "TD002", # Missing author in TODO - "TD003", # Missing issue link on the line following this TODO - "TRY003", # Avoid specifying long messages outside the exception class - "PYI021", # Avoid docstring in stub file - "E741", # Ambiguous variable names - "RUF001", # Ambiguous character in string -] - -[tool.ruff.lint.pydocstyle] -convention = "numpy" - -[tool.ruff.format] -line-ending = "auto" -quote-style = "single" -indent-style = "space" -skip-magic-trailing-comma = false -docstring-code-format = false -docstring-code-line-length = "dynamic" - [tool.coverage.run] source = ["laddu"] omit = [ diff --git a/py-laddu/tests/test_amplitudes.py b/py-laddu/tests/test_amplitudes.py index 5f69b8b3..fb7fa61d 100644 --- a/py-laddu/tests/test_amplitudes.py +++ b/py-laddu/tests/test_amplitudes.py @@ -1,5 +1,4 @@ import pytest - from laddu import ( ComplexScalar, Dataset, @@ -486,7 +485,7 @@ def test_tree_printing() -> None: └─ × ├─ parametric_1(id=0) └─ parametric_2(id=1) -""" +""" # noqa: RUF001 ) diff --git a/py-laddu/tests/test_breit_wigner.py b/py-laddu/tests/test_breit_wigner.py index 89b27a45..b2e282a7 100644 --- a/py-laddu/tests/test_breit_wigner.py +++ b/py-laddu/tests/test_breit_wigner.py @@ -1,5 +1,4 @@ import pytest - from laddu import BreitWigner, Dataset, Event, Mass, Vec3, parameter P4_NAMES = ['beam', 'proton', 'kshort1', 'kshort2'] diff --git a/py-laddu/tests/test_common.py b/py-laddu/tests/test_common.py index 0d88ec4e..e406499d 100644 --- a/py-laddu/tests/test_common.py +++ b/py-laddu/tests/test_common.py @@ -1,6 +1,5 @@ import numpy as np import pytest - from laddu import ( ComplexScalar, Dataset, diff --git a/py-laddu/tests/test_data.py b/py-laddu/tests/test_data.py index 41ae7820..a3b77d3f 100644 --- a/py-laddu/tests/test_data.py +++ b/py-laddu/tests/test_data.py @@ -3,12 +3,11 @@ import tempfile from pathlib import Path +import laddu.io as ldio import numpy as np import pandas as pd import polars as pl import pytest - -import laddu.io as ldio from laddu import Dataset, Event, Mass, Vec3, Vec4 P4_NAMES = ['beam', 'proton', 'kshort1', 'kshort2'] diff --git a/py-laddu/tests/test_extensions.py b/py-laddu/tests/test_extensions.py index adf2e34d..9aa60aee 100644 --- a/py-laddu/tests/test_extensions.py +++ b/py-laddu/tests/test_extensions.py @@ -3,7 +3,6 @@ import math import pytest - from laddu import ( NLL, Dataset, diff --git a/py-laddu/tests/test_kmatrix.py b/py-laddu/tests/test_kmatrix.py index 0221e982..851d8fdf 100644 --- a/py-laddu/tests/test_kmatrix.py +++ b/py-laddu/tests/test_kmatrix.py @@ -1,5 +1,4 @@ import pytest - from laddu import Dataset, Event, Mass, Vec3, parameter from laddu.amplitudes.kmatrix import ( KopfKMatrixA0, diff --git a/py-laddu/tests/test_phase_space_factor.py b/py-laddu/tests/test_phase_space_factor.py index 58bd8458..eba518b3 100644 --- a/py-laddu/tests/test_phase_space_factor.py +++ b/py-laddu/tests/test_phase_space_factor.py @@ -1,5 +1,4 @@ import pytest - from laddu import ( Dataset, Event, diff --git a/py-laddu/tests/test_piecewise.py b/py-laddu/tests/test_piecewise.py index 3b83ef33..8df16837 100644 --- a/py-laddu/tests/test_piecewise.py +++ b/py-laddu/tests/test_piecewise.py @@ -1,6 +1,5 @@ import numpy as np import pytest - from laddu import Dataset, Event, Mass, Vec3, parameter from laddu.amplitudes.piecewise import ( PiecewiseComplexScalar, diff --git a/py-laddu/tests/test_serde.py b/py-laddu/tests/test_serde.py index 67cc5873..1670a50b 100644 --- a/py-laddu/tests/test_serde.py +++ b/py-laddu/tests/test_serde.py @@ -1,7 +1,6 @@ import pickle import pytest - from laddu import Dataset, Event, Mass, Scalar, Vec3, parameter from laddu.amplitudes.kmatrix import ( KopfKMatrixF0, diff --git a/py-laddu/tests/test_variables.py b/py-laddu/tests/test_variables.py index dc0f9003..efb9f9b6 100644 --- a/py-laddu/tests/test_variables.py +++ b/py-laddu/tests/test_variables.py @@ -1,5 +1,4 @@ import pytest - from laddu import ( Angles, CosTheta, diff --git a/py-laddu/tests/test_vectors.py b/py-laddu/tests/test_vectors.py index c839dbb2..76790326 100644 --- a/py-laddu/tests/test_vectors.py +++ b/py-laddu/tests/test_vectors.py @@ -1,6 +1,5 @@ import numpy as np import pytest - from laddu import Vec3, Vec4 diff --git a/py-laddu/tests/test_ylm.py b/py-laddu/tests/test_ylm.py index b4b71da2..d3e55840 100644 --- a/py-laddu/tests/test_ylm.py +++ b/py-laddu/tests/test_ylm.py @@ -1,5 +1,4 @@ import pytest - from laddu import Angles, Dataset, Event, Topology, Vec3, Ylm P4_NAMES = ['beam', 'proton', 'kshort1', 'kshort2'] diff --git a/py-laddu/tests/test_zlm.py b/py-laddu/tests/test_zlm.py index dd8c8e5a..97627363 100644 --- a/py-laddu/tests/test_zlm.py +++ b/py-laddu/tests/test_zlm.py @@ -1,5 +1,4 @@ import pytest - from laddu import Angles, Dataset, Event, Polarization, Topology, Vec3, Zlm from laddu.amplitudes.zlm import PolPhase diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 00000000..4cf6e857 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,88 @@ +{ + "plugins": [ + { "type": "cargo-workspace", "merge": false }, + { "type": "sentence-case" }, + { + "type": "linked-versions", + "groupName": "laddu", + "components": ["laddu", "py-laddu", "py-laddu-cpu", "py-laddu-mpi"] + } + ], + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "release-type": "rust", + "packages": { + "crates/laddu": { + "component": "laddu", + "extra-files": [ + { + "type": "toml", + "path": "Cargo.toml", + "jsonpath": "$.workspace.dependencies['laddu'].version" + } + ] + }, + "crates/laddu-amplitudes": { + "component": "laddu-amplitudes", + "extra-files": [ + { + "type": "toml", + "path": "Cargo.toml", + "jsonpath": "$.workspace.dependencies['laddu-amplitudes'].version" + } + ] + }, + "crates/laddu-core": { + "component": "laddu-core", + "extra-files": [ + { + "type": "toml", + "path": "Cargo.toml", + "jsonpath": "$.workspace.dependencies['laddu-core'].version" + } + ] + }, + "crates/laddu-extensions": { + "component": "laddu-extensions", + "extra-files": [ + { + "type": "toml", + "path": "Cargo.toml", + "jsonpath": "$.workspace.dependencies['laddu-extensions'].version" + } + ] + }, + "crates/laddu-python": { + "component": "laddu-python", + "extra-files": [ + { + "type": "toml", + "path": "Cargo.toml", + "jsonpath": "$.workspace.dependencies['laddu-python'].version" + } + ] + }, + "py-laddu-cpu": { + "component": "py-laddu-cpu", + "extra-files": [ + { + "type": "generic", + "path": "py-laddu/pyproject.toml" + } + ] + }, + "py-laddu-mpi": { + "component": "py-laddu-mpi", + "extra-files": [ + { + "type": "generic", + "path": "py-laddu/pyproject.toml" + } + ] + }, + "py-laddu": { + "component": "py-laddu", + "release-type": "python" + } + } +} diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..f9ee7085 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,93 @@ +target-version = "py37" +indent-width = 4 +line-length = 90 +fix = true + +[format] +line-ending = "auto" +quote-style = "single" +indent-style = "space" +skip-magic-trailing-comma = false +docstring-code-format = false +docstring-code-line-length = "dynamic" + +[lint] +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] +select = [ + "ANN", # flake8-annotations + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "D", # flake8-docstrings + "E", # pycodestyle + "EM", # flake8-errmsg + "F", # pyflakes + "FA", # flake8-future-annotations + "FBT001", # flake8-boolean-trap + "I", # isort + "ICN", # flake8-import-conventions + "INT", # flake8-gettext + "PERF", # perflint + "PIE", # flake8-pie + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "PYI", # flake8-pyi + "RUF", # ruff-specific rules + "SIM", # flake8-simplify + "TD", # flake8-todos + "TID", # flake8-tidy-imports + "TRY", # tryceratops + "UP", # pyupgrade + "W", # pycodestyle +] +ignore = [ + "D100", # Missing docstring in public module + "D101", # Missing docstring in public class + "D102", # Missing docstring in public method + "D103", # Missing docstring in public function + "D104", # Missing docstring in public package + "D105", # Missing docstring in magic method + # ------------------------------------------------------------------ + "ANN401", # Dynamically typed expressions (Any) are disallowed + "E501", # Line length regulated by formatter + "PT011", # pytest.raises is too broad, set match or use a more specific exception + "PYI041", # Use float instead of int | float + "RUF005", # Consider expression instead of concatenation + "SIM102", # Use a single `if` statement instead of nested `if` statements + "SIM114", # Combine `if` branches + "TD002", # Missing author in TODO + "TD003", # Missing issue link on the line following this TODO + "TRY003", # Avoid specifying long messages outside the exception class + "PYI021", # Avoid docstring in stub file + "E741", # Ambiguous variable names +] + + +[lint.pydocstyle] +convention = "numpy"