From b7f45366931f97ff6a034a24bee37a89ec0d8114 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 7 Aug 2024 08:35:00 -0500 Subject: [PATCH 1/2] Add conda-recipe-cf and workflow to build project with NumPy 2.0 using conda-forge only, and test with NumPy 1.26 and post 2 --- .github/workflows/conda-package-cf.yml | 256 +++++++++++++++++++++++++ conda-recipe-cf/bld.bat | 3 + conda-recipe-cf/build.sh | 10 + conda-recipe-cf/meta.yaml | 46 +++++ conda-recipe/run_test.py | 0 5 files changed, 315 insertions(+) create mode 100644 .github/workflows/conda-package-cf.yml create mode 100644 conda-recipe-cf/bld.bat create mode 100644 conda-recipe-cf/build.sh create mode 100644 conda-recipe-cf/meta.yaml delete mode 100644 conda-recipe/run_test.py diff --git a/.github/workflows/conda-package-cf.yml b/.github/workflows/conda-package-cf.yml new file mode 100644 index 0000000..32384eb --- /dev/null +++ b/.github/workflows/conda-package-cf.yml @@ -0,0 +1,256 @@ +name: Conda package with conda-forge channel only + +on: push + +permissions: read-all + +env: + PACKAGE_NAME: mkl_fft + MODULE_NAME: mkl_fft + TEST_ENV_NAME: test_mkl_fft + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.9', '3.10', '3.11', '3.12'] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set pkgs_dirs + run: | + echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc + - name: Cache conda packages + uses: actions/cache@v4 + env: + CACHE_NUMBER: 0 # Increase to reset cache + with: + path: ~/.conda/pkgs + key: + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }} + restore-keys: | + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- + + - name: Add conda to system path + run: echo $CONDA/bin >> $GITHUB_PATH + - name: Install conda-build + run: conda install conda-build + - name: Build conda package with NumPy 2 + run: | + CHANNELS="-c conda-forge --override-channels" + VERSIONS="--python ${{ matrix.python }} --numpy 2" + TEST="--no-test" + + conda build \ + $TEST \ + $VERSIONS \ + $CHANNELS \ + conda-recipe-cf + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} + path: /usr/share/miniconda/conda-bld/linux-64/${{ env.PACKAGE_NAME }}-*.tar.bz2 + + test: + needs: build + runs-on: ${{ matrix.runner }} + + strategy: + matrix: + python_ver: ['3.9', '3.10', '3.11', '3.12'] + numpy: ['numpy"<2"', 'numpy">=2"'] + experimental: [false] + runner: [ubuntu-latest] + continue-on-error: ${{ matrix.experimental }} + env: + CHANNELS: -c conda-forge --override-channels + + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python_ver }} + - name: Add conda to system path + run: echo $CONDA/bin >> $GITHUB_PATH + - name: Install conda-build + run: conda install conda-build + - name: Create conda channel + run: | + mkdir -p $GITHUB_WORKSPACE/channel/linux-64 + mv ${PACKAGE_NAME}-*.tar.bz2 $GITHUB_WORKSPACE/channel/linux-64 + conda index $GITHUB_WORKSPACE/channel + # Test channel + conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels + + - name: Collect dependencies + run: | + CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}" + conda create -n ${{ env.TEST_ENV_NAME }} $PACKAGE_NAME python=${{ matrix.python_ver }} ${{ matrix.numpy }} $CHANNELS --only-deps --dry-run > lockfile + - name: Display lockfile + run: cat lockfile + - name: Set pkgs_dirs + run: | + echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc + - name: Cache conda packages + uses: actions/cache@v4 + env: + CACHE_NUMBER: 0 # Increase to reset cache + with: + path: ~/.conda/pkgs + key: + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python_ver }}-${{hashFiles('lockfile') }} + restore-keys: | + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python_ver }}- + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- + + - name: Install mkl_fft + run: | + CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}" + conda create -n ${{ env.TEST_ENV_NAME }} python=${{ matrix.python_ver }} ${{ matrix.numpy }} $PACKAGE_NAME pytest $CHANNELS + # Test installed packages + conda list -n ${{ env.TEST_ENV_NAME }} + - name: Run tests + run: | + source $CONDA/etc/profile.d/conda.sh + conda activate ${{ env.TEST_ENV_NAME }} + pytest -v --pyargs $MODULE_NAME + + build_windows: + runs-on: windows-2019 + + strategy: + matrix: + python: ['3.9', '3.10', '3.11', '3.12'] + env: + conda-bld: C:\Miniconda\conda-bld\win-64\ + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: conda-incubator/setup-miniconda@v3 + with: + auto-activate-base: true + conda-build-version: "*" + activate-environment: true + python-version: ${{ matrix.python }} + + - name: Cache conda packages + uses: actions/cache@v4 + env: + CACHE_NUMBER: 3 # Increase to reset cache + with: + path: /home/runner/conda_pkgs_dir + key: + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }} + restore-keys: | + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- + - name: Build conda package with NumPy 2.0 + run: conda build --no-test --python ${{ matrix.python }} --numpy 2 -c conda-forge --override-channels conda-recipe-cf + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} + path: ${{ env.conda-bld }}${{ env.PACKAGE_NAME }}-*.tar.bz2 + + test_windows: + needs: build_windows + runs-on: ${{ matrix.runner }} + defaults: + run: + shell: cmd /C CALL {0} + strategy: + matrix: + python_ver: ['3.9', '3.10', '3.11', '3.12'] + numpy: ['numpy"<2"', 'numpy">=2"'] + experimental: [false] + runner: [windows-2019] + continue-on-error: ${{ matrix.experimental }} + env: + workdir: '${{ github.workspace }}' + CHANNELS: -c conda-forge --override-channels + + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python_ver }} + - uses: conda-incubator/setup-miniconda@v3 + with: + auto-update-conda: true + conda-build-version: '*' + miniconda-version: 'latest' + activate-environment: mkl_fft_test + python-version: ${{ matrix.python_ver }} + - name: Create conda channel with the artifact bit + shell: cmd /C CALL {0} + run: | + echo ${{ env.workdir }} + mkdir ${{ env.workdir }}\channel\win-64 + move ${{ env.PACKAGE_NAME }}-*.tar.bz2 ${{ env.workdir }}\channel\win-64 + dir ${{ env.workdir }}\channel\win-64 + - name: Index the channel + shell: cmd /C CALL {0} + run: conda index ${{ env.workdir }}\channel + + - name: Dump mkl_fft version info from created channel into ver.json + shell: cmd /C CALL {0} + run: | + conda search ${{ env.PACKAGE_NAME }} -c ${{ env.workdir }}/channel --override-channels --info --json > ${{ env.workdir }}\ver.json + - name: Output content of produced ver.json + shell: pwsh + run: Get-Content -Path ${{ env.workdir }}\ver.json + - name: Collect dependencies + shell: cmd /C CALL {0} + run: | + IF NOT EXIST ver.json ( + copy /Y ${{ env.workdir }}\ver.json . + ) + SET "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%" + FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO ( + SET PACKAGE_VERSION=%%F + ) + conda install -n mkl_fft_test ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python_ver }} ${{ matrix.numpy }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }} --only-deps --dry-run > lockfile + - name: Display lockfile content + shell: pwsh + run: Get-Content -Path .\lockfile + - name: Cache conda packages + uses: actions/cache@v4 + env: + CACHE_NUMBER: 0 # Increase to reset cache + with: + path: /home/runner/conda_pkgs_dir + key: + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python_ver }}-${{hashFiles('lockfile') }} + restore-keys: | + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python_ver }}- + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- + - name: Install mkl_fft + shell: cmd /C CALL {0} + run: | + @ECHO ON + IF NOT EXIST ver.json ( + copy /Y ${{ env.workdir }}\ver.json . + ) + set "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%" + FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO ( + SET PACKAGE_VERSION=%%F + ) + SET "TEST_DEPENDENCIES=pytest pytest-cov" + conda install -n mkl_fft_test ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% %TEST_DEPENDENCIES% python=${{ matrix.python }} ${{ matrix.numpy }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }} + - name: Report content of test environment + shell: cmd /C CALL {0} + run: | + echo "Value of CONDA enviroment variable was: " %CONDA% + echo "Value of CONDA_PREFIX enviroment variable was: " %CONDA_PREFIX% + conda info && conda list -n mkl_fft_test + - name: Run tests + shell: cmd /C CALL {0} + run: >- + conda activate mkl_fft_test && python -m pytest -v -s --pyargs ${{ env.MODULE_NAME }} + diff --git a/conda-recipe-cf/bld.bat b/conda-recipe-cf/bld.bat new file mode 100644 index 0000000..becc8af --- /dev/null +++ b/conda-recipe-cf/bld.bat @@ -0,0 +1,3 @@ +set MKLROOT=%PREFIX% +%PYTHON% -m pip install --no-build-isolation --no-deps . +if errorlevel 1 exit 1 diff --git a/conda-recipe-cf/build.sh b/conda-recipe-cf/build.sh new file mode 100644 index 0000000..de18657 --- /dev/null +++ b/conda-recipe-cf/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash -x + +if [ `uname` == Darwin ]; then + export MACOSX_DEPLOYMENT_TARGET=10.9 +fi + +export MKLROOT=$PREFIX +export CFLAGS="-I$PREFIX/include $CFLAGS" +$PYTHON -m pip install --no-build-isolation --no-deps . + diff --git a/conda-recipe-cf/meta.yaml b/conda-recipe-cf/meta.yaml new file mode 100644 index 0000000..cede0a4 --- /dev/null +++ b/conda-recipe-cf/meta.yaml @@ -0,0 +1,46 @@ +{% set version = "1.3.10" %} +{% set buildnumber = 0 %} + +package: + name: mkl_fft + version: {{ version }} + +source: + path: ../ + +build: + number: {{ buildnumber }} + ignore_run_exports: + - blas + +requirements: + build: + - {{ compiler('c') }} + host: + - python + - setuptools + - mkl-devel + - cython + - numpy + run: + - python + - mkl + - mkl-service + - numpy + +test: + commands: + - pytest -v --pyargs mkl_fft + requires: + - pytest + imports: + - mkl_fft + - mkl_fft.interfaces + - mkl_fft.interfaces.numpy_fft + - mkl_fft.interfaces.scipy_fft + +about: + home: http://github.com/IntelPython/mkl_fft + license: BSD-3 + license_file: LICENSE.txt + summary: NumPy-based implementation of Fast Fourier Transform using Intel (R) Math Kernel Library diff --git a/conda-recipe/run_test.py b/conda-recipe/run_test.py deleted file mode 100644 index e69de29..0000000 From 6b2e298cda74bb880536dfd4386dd8985800b563 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 7 Aug 2024 08:35:19 -0500 Subject: [PATCH 2/2] Replace -c main with -c conda-forge --- .github/workflows/conda-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index 2b1cd37..e0d15aa 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -67,7 +67,7 @@ jobs: runner: [ubuntu-latest] continue-on-error: ${{ matrix.experimental }} env: - CHANNELS: -c https://software.repos.intel.com/python/conda -c main --override-channels + CHANNELS: -c https://software.repos.intel.com/python/conda -c conda-forge --override-channels steps: - name: Download artifact