Skip to content

Commit

Permalink
Remove pygraphblas conversions (python-graphblas#348)
Browse files Browse the repository at this point in the history
`pygraphblas` appears to be defunct, and we have been unable to test these
conversions for a very long time. I don't think it's necessary to deprecate
these first, since they are and have been unusable.

The benefit of this is cleaner code, cleaner tab-completion, and easier maintenance.

We can revisit this if `pygraphblas` is ever revived (but I hope we can redirect
effort to `python-graphblas`, which I believe is much further along in development).
  • Loading branch information
eriknw authored Dec 20, 2022
1 parent 0a627bc commit f8827cd
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 219 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ jobs:
auto-activate-base: false
- name: Update env
run: |
mamba install -c conda-forge pytest coverage 'black>=20.8b1' flake8 \
coveralls pytest-randomly flake8-comprehensions flake8-bugbear
mamba install -c conda-forge pytest coverage black flake8 \
coveralls=3.3.1 pytest-randomly flake8-comprehensions flake8-bugbear
- name: Style Checks
run: |
flake8
Expand Down Expand Up @@ -87,18 +87,11 @@ jobs:
mamba install -c conda-forge python-suitesparse-graphblas
fi
python setup.py develop --no-deps
# - name: Optional pygraphblas
# if: contains(matrix.cfg.testopts, 'pygraphblas') && (matrix.cfg.pyver != 3.9)
# run: |
# source "$CONDA/etc/profile.d/conda.sh"
# conda activate graphblas
# mamba install -c conda-forge pygraphblas
- name: Verify build
run: |
# Make sure all top-level imports work
./scripts/test_imports.sh
- name: Unit tests
# if: (! contains(matrix.cfg.testopts, 'pygraphblas')) || (matrix.cfg.pyver != 3.9)
run: |
coverage run --branch -m pytest ${{ matrix.cfg.testopts }} -v
# Run tests again with Scalars being C scalars by default
Expand Down Expand Up @@ -130,7 +123,6 @@ jobs:
git diff --exit-code
coverage xml
- name: Coverage
# if: (! contains(matrix.cfg.testopts, 'pygraphblas')) || (matrix.cfg.pyver != 3.9)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: ${{ matrix.cfg.pyver}}/${{ matrix.cfg.testopts }}
Expand All @@ -141,7 +133,6 @@ jobs:
- name: codecov
uses: codecov/codecov-action@v3
- name: Notebooks Execution check
# if: (! contains(matrix.cfg.testopts, 'pygraphblas')) || (matrix.cfg.pyver != 3.9)
run: |
mamba install -c conda-forge matplotlib nbconvert jupyter 'ipython>=7'
jupyter nbconvert --to notebook --execute notebooks/*ipynb
Expand All @@ -156,7 +147,7 @@ jobs:
source "$CONDA/etc/profile.d/conda.sh"
conda config --set always_yes yes --set changeps1 no
conda update -q conda
conda create -n coveralls_final -c conda-forge python=3.9 coveralls
conda create -n coveralls_final -c conda-forge python=3.9 coveralls=3.3.1
- name: Coveralls Finished
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/myint/autoflake
rev: v1.7.7
rev: v2.0.0
hooks:
- id: autoflake
args: [--in-place]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: v5.11.3
hooks:
- id: isort
language_version: python3
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/MarcoGorelli/auto-walrus
rev: v0.2.1
rev: v0.2.2
hooks:
- id: auto-walrus
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
language_version: python3
Expand Down
5 changes: 0 additions & 5 deletions graphblas/core/automethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,6 @@ def to_dicts(self):
return self._get_value("to_dicts")


def to_pygraphblas(self):
return self._get_value("to_pygraphblas")


def to_values(self):
return self._get_value("to_values")

Expand Down Expand Up @@ -352,7 +348,6 @@ def _main():
"isequal",
"name",
"nvals",
"to_pygraphblas",
"wait",
}
scalar = {
Expand Down
3 changes: 0 additions & 3 deletions graphblas/core/infix.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def shape(self):
ss = wrapdoc(Vector.ss)(property(automethods.ss))
to_coo = wrapdoc(Vector.to_coo)(property(automethods.to_coo))
to_dict = wrapdoc(Vector.to_dict)(property(automethods.to_dict))
to_pygraphblas = wrapdoc(Vector.to_pygraphblas)(property(automethods.to_pygraphblas))
to_values = wrapdoc(Vector.to_values)(property(automethods.to_values))
vxm = wrapdoc(Vector.vxm)(property(automethods.vxm))
wait = wrapdoc(Vector.wait)(property(automethods.wait))
Expand Down Expand Up @@ -226,7 +225,6 @@ def shape(self):
to_dcsc = wrapdoc(Matrix.to_dcsc)(property(automethods.to_dcsc))
to_dcsr = wrapdoc(Matrix.to_dcsr)(property(automethods.to_dcsr))
to_dicts = wrapdoc(Matrix.to_dicts)(property(automethods.to_dicts))
to_pygraphblas = wrapdoc(Matrix.to_pygraphblas)(property(automethods.to_pygraphblas))
to_values = wrapdoc(Matrix.to_values)(property(automethods.to_values))
wait = wrapdoc(Matrix.wait)(property(automethods.wait))
# These raise exceptions
Expand Down Expand Up @@ -335,7 +333,6 @@ def is_grbscalar(self):
name = wrapdoc(Scalar.name)(property(automethods.name))
name = name.setter(automethods._set_name)
nvals = wrapdoc(Scalar.nvals)(property(automethods.nvals))
to_pygraphblas = wrapdoc(Scalar.to_pygraphblas)(property(automethods.to_pygraphblas))
value = wrapdoc(Scalar.value)(property(automethods.value))
wait = wrapdoc(Scalar.wait)(property(automethods.wait))
# These raise exceptions
Expand Down
48 changes: 0 additions & 48 deletions graphblas/core/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2915,52 +2915,6 @@ def _delete_element(self, resolved_indexes):
rowidx, colidx = resolved_indexes.indices
call("GrB_Matrix_removeElement", [self, rowidx.index, colidx.index])

def to_pygraphblas(self): # pragma: no cover (outdated)
"""Convert to a ``pygraphblas.Matrix`` without copying data.
This gives control of the underlying GraphBLAS memory to pygraphblas,
meaning further operations on the current :class:`Matrix` object will fail!
This method requires the
`pygraphblas <https://graphegon.github.io/pygraphblas/pygraphblas/index.html>`_
library to be installed.
"""
if backend != "suitesparse":
raise RuntimeError(
f"to_pygraphblas only works with 'suitesparse' backend, not {backend}"
)
import pygraphblas as pg

matrix = pg.Matrix(self.gb_obj, pg.types._gb_type_to_type(self.dtype.gb_obj))
self.gb_obj = ffi_new("GrB_Matrix*")
return matrix

@classmethod
def from_pygraphblas(cls, matrix): # pragma: no cover (outdated)
"""Convert a ``pygraphblas.Matrix`` to a new :class:`Matrix` without copying data.
This gives control of the underlying GraphBLAS memory to python-graphblas,
meaning further operations on the original ``pygraphblas`` matrix object will fail!
This method requires the
`pygraphblas <https://graphegon.github.io/pygraphblas/pygraphblas/index.html>`_
library to be installed.
"""
if backend != "suitesparse":
raise RuntimeError(
f"from_pygraphblas only works with 'suitesparse' backend, not {backend!r}"
)
import pygraphblas as pg

if not isinstance(matrix, pg.Matrix):
raise TypeError(f"Expected pygraphblas.Matrix object. Got type: {type(matrix)}")
dtype = lookup_dtype(matrix.gb_type)
rv = cls(matrix._matrix, dtype)
rv._nrows = matrix.nrows
rv._ncols = matrix.ncols
matrix._matrix = ffi_new("GrB_Matrix*")
return rv


if backend == "suitesparse":
Matrix.ss = class_property(Matrix.ss, ss)
Expand Down Expand Up @@ -3121,7 +3075,6 @@ def shape(self):
to_dcsc = wrapdoc(Matrix.to_dcsc)(property(automethods.to_dcsc))
to_dcsr = wrapdoc(Matrix.to_dcsr)(property(automethods.to_dcsr))
to_dicts = wrapdoc(Matrix.to_dicts)(property(automethods.to_dicts))
to_pygraphblas = wrapdoc(Matrix.to_pygraphblas)(property(automethods.to_pygraphblas))
to_values = wrapdoc(Matrix.to_values)(property(automethods.to_values))
wait = wrapdoc(Matrix.wait)(property(automethods.wait))
# These raise exceptions
Expand Down Expand Up @@ -3211,7 +3164,6 @@ def shape(self):
to_dcsc = wrapdoc(Matrix.to_dcsc)(property(automethods.to_dcsc))
to_dcsr = wrapdoc(Matrix.to_dcsr)(property(automethods.to_dcsr))
to_dicts = wrapdoc(Matrix.to_dicts)(property(automethods.to_dicts))
to_pygraphblas = wrapdoc(Matrix.to_pygraphblas)(property(automethods.to_pygraphblas))
to_values = wrapdoc(Matrix.to_values)(property(automethods.to_values))
wait = wrapdoc(Matrix.wait)(property(automethods.wait))
# These raise exceptions
Expand Down
37 changes: 0 additions & 37 deletions graphblas/core/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,41 +549,6 @@ def __reduce__(self):
def _deserialize(value, dtype, is_cscalar, name):
return Scalar.from_value(value, dtype, is_cscalar=is_cscalar, name=name)

def to_pygraphblas(self): # pragma: no cover (outdated)
"""Convert to a ``pygraphblas.Scalar`` by making a copy of the internal value.
This method requires the
`pygraphblas <https://graphegon.github.io/pygraphblas/pygraphblas/index.html>`_
library to be installed.
"""
if backend != "suitesparse":
raise RuntimeError(
f"to_pygraphblas only works with 'suitesparse' backend, not {backend}"
)
import pygraphblas as pg

return pg.Scalar.from_value(self.value)

@classmethod
def from_pygraphblas(cls, scalar): # pragma: no cover (outdated)
"""Convert a ``pygraphblas.Scalar`` to a new :class:`Scalar` by making
a copy of the internal value.
This method requires the
`pygraphblas <https://graphegon.github.io/pygraphblas/pygraphblas/index.html>`_
library to be installed.
"""
if backend != "suitesparse":
raise RuntimeError(
f"from_pygraphblas only works with 'suitesparse' backend, not {backend!r}"
)
import pygraphblas as pg

if not isinstance(scalar, pg.Scalar):
raise TypeError(f"Expected pygraphblas.Scalar object. Got type: {type(scalar)}")
dtype = lookup_dtype(scalar.gb_type)
return cls.from_value(scalar[0], dtype)

def _as_vector(self, *, name=None):
"""Copy or cast this Scalar to a Vector
Expand Down Expand Up @@ -688,7 +653,6 @@ def _repr_html_(self):
name = wrapdoc(Scalar.name)(property(automethods.name))
name = name.setter(automethods._set_name)
nvals = wrapdoc(Scalar.nvals)(property(automethods.nvals))
to_pygraphblas = wrapdoc(Scalar.to_pygraphblas)(property(automethods.to_pygraphblas))
value = wrapdoc(Scalar.value)(property(automethods.value))
wait = wrapdoc(Scalar.wait)(property(automethods.wait))
# These raise exceptions
Expand Down Expand Up @@ -749,7 +713,6 @@ def is_grbscalar(self):
name = wrapdoc(Scalar.name)(property(automethods.name))
name = name.setter(automethods._set_name)
nvals = wrapdoc(Scalar.nvals)(property(automethods.nvals))
to_pygraphblas = wrapdoc(Scalar.to_pygraphblas)(property(automethods.to_pygraphblas))
value = wrapdoc(Scalar.value)(property(automethods.value))
wait = wrapdoc(Scalar.wait)(property(automethods.wait))
# These raise exceptions
Expand Down
47 changes: 0 additions & 47 deletions graphblas/core/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,51 +1714,6 @@ def _delete_element(self, resolved_indexes):
idx = resolved_indexes.indices[0]
call("GrB_Vector_removeElement", [self, idx.index])

def to_pygraphblas(self): # pragma: no cover (outdated)
"""Convert to a ``pygraphblas.Vector`` without copying data.
This gives control of the underlying GraphBLAS memory to pygraphblas,
meaning further operations on the current :class:`Vector` object will fail!
This method requires the
`pygraphblas <https://graphegon.github.io/pygraphblas/pygraphblas/index.html>`_
library to be installed.
"""
if backend != "suitesparse":
raise RuntimeError(
f"to_pygraphblas only works with 'suitesparse' backend, not {backend}"
)
import pygraphblas as pg

vector = pg.Vector(self.gb_obj, pg.types._gb_type_to_type(self.dtype.gb_obj))
self.gb_obj = ffi_new("GrB_Vector*")
return vector

@classmethod
def from_pygraphblas(cls, vector): # pragma: no cover (outdated)
"""Convert a ``pygraphblas.Vector`` to a new :class:`Vector` without copying data.
This gives control of the underlying GraphBLAS memory to python-graphblas,
meaning further operations on the original ``pygraphblas`` vector object will fail!
This method requires the
`pygraphblas <https://graphegon.github.io/pygraphblas/pygraphblas/index.html>`_
library to be installed.
"""
if backend != "suitesparse":
raise RuntimeError(
f"from_pygraphblas only works with 'suitesparse' backend, not {backend!r}"
)
import pygraphblas as pg

if not isinstance(vector, pg.Vector):
raise TypeError(f"Expected pygraphblas.Vector object. Got type: {type(vector)}")
dtype = lookup_dtype(vector.gb_type)
rv = cls(vector._vector, dtype)
rv._size = vector.size
vector._vector = ffi_new("GrB_Vector*")
return rv

@classmethod
def from_dict(cls, d, dtype=None, *, size=None, name=None):
"""Create a new Vector from a dict with keys as indices and values as values.
Expand Down Expand Up @@ -1919,7 +1874,6 @@ def shape(self):
ss = wrapdoc(Vector.ss)(property(automethods.ss))
to_coo = wrapdoc(Vector.to_coo)(property(automethods.to_coo))
to_dict = wrapdoc(Vector.to_dict)(property(automethods.to_dict))
to_pygraphblas = wrapdoc(Vector.to_pygraphblas)(property(automethods.to_pygraphblas))
to_values = wrapdoc(Vector.to_values)(property(automethods.to_values))
vxm = wrapdoc(Vector.vxm)(property(automethods.vxm))
wait = wrapdoc(Vector.wait)(property(automethods.wait))
Expand Down Expand Up @@ -1995,7 +1949,6 @@ def shape(self):
ss = wrapdoc(Vector.ss)(property(automethods.ss))
to_coo = wrapdoc(Vector.to_coo)(property(automethods.to_coo))
to_dict = wrapdoc(Vector.to_dict)(property(automethods.to_dict))
to_pygraphblas = wrapdoc(Vector.to_pygraphblas)(property(automethods.to_pygraphblas))
to_values = wrapdoc(Vector.to_values)(property(automethods.to_values))
vxm = wrapdoc(Vector.vxm)(property(automethods.vxm))
wait = wrapdoc(Vector.wait)(property(automethods.wait))
Expand Down
4 changes: 1 addition & 3 deletions graphblas/tests/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,6 @@ def test_expr_is_like_matrix(A):
"from_dcsc",
"from_dcsr",
"from_dicts",
"from_pygraphblas",
"from_values",
"resize",
"update",
Expand All @@ -2905,7 +2904,7 @@ def test_expr_is_like_matrix(A):
# so maybe it shouldn't support everything.
if suitesparse:
expected.add("ss")
assert attrs - transposed_attrs == (expected | {"_as_vector", "S", "V", "to_pygraphblas"}) - {
assert attrs - transposed_attrs == (expected | {"_as_vector", "S", "V"}) - {
"_prep_for_extract",
"_extract_element",
}
Expand Down Expand Up @@ -2942,7 +2941,6 @@ def test_index_expr_is_like_matrix(A):
"from_dcsc",
"from_dcsr",
"from_dicts",
"from_pygraphblas",
"from_values",
"resize",
}
Expand Down
Loading

0 comments on commit f8827cd

Please sign in to comment.