Skip to content

Commit 41159c0

Browse files
authored
ci: Merge MLIR Backend (#758)
1 parent 9beb711 commit 41159c0

File tree

5 files changed

+36
-49
lines changed

5 files changed

+36
-49
lines changed

.coveragerc

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ source=
44

55
omit=
66
sparse/_version.py
7-
sparse/tests/*
8-
sparse/numba_backend/tests/*
7+
**/tests/*
98

109
[report]
1110
exclude_lines =

.github/workflows/ci.yml

+15-36
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
os: [ubuntu-latest]
13+
os: ['ubuntu-latest']
1414
python: ['3.10', '3.11', '3.12']
1515
pip_opts: ['']
1616
numba_boundscheck: [0]
@@ -34,51 +34,30 @@ jobs:
3434
steps:
3535
- name: Checkout Repo
3636
uses: actions/checkout@v4
37-
- name: Set up Python
38-
uses: actions/setup-python@v5
37+
- uses: mamba-org/setup-micromamba@v1
3938
with:
40-
python-version: ${{ matrix.python }}
41-
cache: 'pip'
39+
environment-file: ci/environment.yml
40+
init-shell: >-
41+
bash
42+
cache-environment: true
43+
cache-downloads: true
44+
post-cleanup: 'all'
45+
create-args: >-
46+
python=${{ matrix.python }}
47+
${{ matrix.pip_opts }}
4248
- name: Install package
4349
run: |
4450
pip install -e '.[tests]'
45-
if [ "${{ matrix.pip_opts }}" != "" ]; then
46-
pip install "${{ matrix.pip_opts }}" numba
47-
fi
4851
- name: Run tests
4952
run: |
50-
SPARSE_BACKEND=Numba pytest --pyargs sparse --cov-report=xml:coverage_Numba.xml -n 4 -vvv
51-
SPARSE_BACKEND=Finch pytest --pyargs sparse/tests --cov-report=xml:coverage_Finch.xml -n 4 -vvv
53+
SPARSE_BACKEND=Numba pytest --pyargs sparse --cov-report=xml:coverage_Numba.xml -n auto -vvv
54+
SPARSE_BACKEND=Finch pytest --pyargs sparse/tests --cov-report=xml:coverage_Finch.xml -n auto -vvv
55+
SPARSE_BACKEND=MLIR pytest --pyargs sparse/mlir_backend --cov-report=xml:coverage_MLIR.xml -n auto -vvv
5256
- uses: codecov/codecov-action@v4
5357
if: always()
5458
with:
5559
files: ./**/coverage*.xml
5660

57-
test_mlir:
58-
runs-on: ubuntu-latest
59-
steps:
60-
- name: Checkout Repo
61-
uses: actions/checkout@v4
62-
- name: Setup Conda
63-
uses: conda-incubator/setup-miniconda@v3
64-
with:
65-
python-version: '3.10'
66-
channels: conda-forge
67-
activate-environment: sparse-dev
68-
miniforge-variant: Mambaforge
69-
miniforge-version: latest
70-
use-mamba: true
71-
- name: Update Conda Environment
72-
run: |
73-
mamba env update -n sparse-dev -f ci/environment.yml
74-
mamba run pip install '.[tests]'
75-
mamba install conda-forge::mlir-python-bindings
76-
- name: Build and run tests
77-
shell: bash -l {0}
78-
run: |
79-
conda activate sparse-dev
80-
SPARSE_BACKEND=MLIR pytest sparse/mlir_backend -v
81-
8261
examples:
8362
runs-on: ubuntu-latest
8463
steps:
@@ -147,7 +126,7 @@ jobs:
147126
SPARSE_BACKEND: ${{ matrix.backend }}
148127
run: |
149128
cd ${GITHUB_WORKSPACE}/array-api-tests
150-
pytest array_api_tests -v -c pytest.ini -n 4 --max-examples=2 --derandomize --disable-deadline -o xfail_strict=True --xfails-file ${GITHUB_WORKSPACE}/ci/${{ matrix.backend }}-array-api-xfails.txt --skips-file ${GITHUB_WORKSPACE}/ci/${{ matrix.backend }}-array-api-skips.txt
129+
pytest array_api_tests -v -c pytest.ini -n auto --max-examples=2 --derandomize --disable-deadline -o xfail_strict=True --xfails-file ${GITHUB_WORKSPACE}/ci/${{ matrix.backend }}-array-api-xfails.txt --skips-file ${GITHUB_WORKSPACE}/ci/${{ matrix.backend }}-array-api-skips.txt
151130
152131
on:
153132
# Trigger the workflow on push or pull request,

ci/environment.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
name: sparse-dev
22
channels:
33
- conda-forge
4+
- nodefaults
45
dependencies:
56
- python
6-
- pip
7+
- numpy
8+
- numba
9+
- scipy
10+
- dask
11+
- pytest
12+
- pytest-cov
13+
- pytest-xdist
14+
- mlir-python-bindings
15+
- pip:
16+
- finch-tensor >=0.1.31
17+
- pytest-codspeed

sparse/mlir_backend/_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
SCRIPT_PATH = pathlib.Path(__file__).parent
99

1010
MLIR_C_RUNNER_UTILS = ctypes.util.find_library("mlir_c_runner_utils")
11-
libc = ctypes.CDLL(ctypes.util.find_library("c"))
11+
libc = ctypes.CDLL(ctypes.util.find_library("c")) if os.name != "nt" else ctypes.cdll.msvcrt
1212
libc.free.argtypes = [ctypes.c_void_p]
1313
libc.free.restype = None
1414

sparse/mlir_backend/tests/test_simple.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
pytest.skip("skipping MLIR tests", allow_module_level=True)
1010

1111

12+
def assert_csr_equal(expected: sps.csr_array, actual: sps.csr_array) -> None:
13+
np.testing.assert_array_equal(expected.todense(), actual.todense())
14+
15+
1216
def test_constructors(rng):
1317
SHAPE = (10, 5)
1418
DENSITY = 0.5
@@ -20,9 +24,7 @@ def test_constructors(rng):
2024
c_tensor = sparse.asarray(c)
2125

2226
a_retured = a_tensor.to_scipy_sparse()
23-
np.testing.assert_array_equal(a_retured.indices, a.indices)
24-
np.testing.assert_array_equal(a_retured.indptr, a.indptr)
25-
np.testing.assert_array_equal(a_retured.data, a.data)
27+
assert_csr_equal(a, a_retured)
2628

2729
c_returned = c_tensor.to_scipy_sparse()
2830
np.testing.assert_array_equal(c_returned, c)
@@ -42,15 +44,11 @@ def test_add(rng):
4244

4345
actual = sparse.add(a_tensor, b_tensor).to_scipy_sparse()
4446
expected = a + b
45-
np.testing.assert_array_equal(actual.indices, expected.indices)
46-
np.testing.assert_array_equal(actual.indptr, expected.indptr)
47-
np.testing.assert_array_equal(actual.data, expected.data)
47+
assert_csr_equal(expected, actual)
4848

4949
actual = sparse.add(a_tensor, c_tensor).to_scipy_sparse()
5050
expected = sps.csr_matrix(a + c)
51-
np.testing.assert_array_equal(actual.indices, expected.indices)
52-
np.testing.assert_array_equal(actual.indptr, expected.indptr)
53-
np.testing.assert_array_equal(actual.data, expected.data)
51+
assert_csr_equal(expected, actual)
5452

5553
actual = sparse.add(c_tensor, a_tensor).to_scipy_sparse()
5654
expected = a + c

0 commit comments

Comments
 (0)