Skip to content

Commit

Permalink
adds versioning for release
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronzo committed May 30, 2024
1 parent 25a3da0 commit 85aa820
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# graph-diffusers
Diffusion patterns for graph machine learning
Diffusion patterns for graph machine learning based on GraphBLAS.
1 change: 1 addition & 0 deletions graph_diffusers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from graph_diffusers import models, operators, io
from graph_diffusers._version import __version__

__all__ = [
"models",
Expand Down
1 change: 1 addition & 0 deletions graph_diffusers/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.0"
39 changes: 23 additions & 16 deletions graph_diffusers/io/torch.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import graphblas as gb
from typing import TYPE_CHECKING, Optional, Union, Hashable
from typing import TYPE_CHECKING, Optional, Hashable
import functools as ft
import torch
from torch_sparse import SparseTensor
import warnings
from graph_diffusers import _extras

if TYPE_CHECKING:
from graph_diffusers._typing import _GraphblasModule as gb
from numpy.typing import DTypeLike

# TODO check if torch_sparse installed
if _extras.TORCH_SPARSE:
from torch_sparse import SparseTensor as _SparseTensor
else:

class _SparseTensor: ...


def torch_to_graphblas(
Expand All @@ -19,7 +23,7 @@ def torch_to_graphblas(
weighted: bool = False,
dtype: "Optional[DTypeLike]" = None,
) -> gb.Matrix:
if isinstance(edge_index, SparseTensor):
if isinstance(edge_index, _SparseTensor):
return torch_sparse_tensor_to_graphblas(edge_index, weighted=weighted, dtype=dtype)
if edge_index.is_sparse_csr:
return torch_sparse_csr_to_graphblas(edge_index, weighted=weighted, dtype=dtype)
Expand All @@ -37,30 +41,33 @@ def torch_sparse_csr_to_graphblas(
return _torch_sparse_csr_to_graphblas(adj_t, weighted=weighted, dtype=dtype)


def torch_sparse_tensor_to_graphblas(
adj_t: SparseTensor, *, weighted: bool = False, dtype: "Optional[DTypeLike]" = None
) -> gb.Matrix:
return torch_sparse_csr_to_graphblas(
adj_t.to_torch_sparse_csr_tensor(),
weighted=weighted,
dtype=dtype,
)


def torch_edge_index_to_graphblas(
edge_index: Union[torch.Tensor, SparseTensor],
edge_index: torch.Tensor,
*,
num_nodes: Optional[int] = None,
dtype: "Optional[DTypeLike]" = None,
) -> gb.Matrix:
if not isinstance(dtype, Hashable):
warnings.warn(
f"Unhashable dtype {dtype} passed when converting from torch to graphblas." "The result will not be cached."
f"Unhashable dtype {dtype} passed when converting from torch to graphblas. The result will not be cached."
)
return _torch_edge_index_to_graphblas.__wrapped__(edge_index, num_nodes=num_nodes, dtype=dtype)
return _torch_edge_index_to_graphblas(edge_index, num_nodes=num_nodes, dtype=dtype)


if _extras.TORCH_SPARSE:
import torch_sparse

def torch_sparse_tensor_to_graphblas(
adj_t: torch_sparse.SparseTensor, *, weighted: bool = False, dtype: "Optional[DTypeLike]" = None
) -> gb.Matrix:
return torch_sparse_csr_to_graphblas(
adj_t.to_torch_sparse_csr_tensor(),
weighted=weighted,
dtype=dtype,
)


@ft.lru_cache(maxsize=1)
def _torch_sparse_csr_to_graphblas(
adj_t: torch.Tensor,
Expand Down
22 changes: 20 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
[tool.poetry]
name = "graph-diffusers"
version = "0.1.0-dev"
description = "Diffusion operators for graph machine learning"
version = "0.0.0"
description = "Diffusion operators for graph machine learning based on GraphBLAS"
authors = ["Aaron Zolnai-Lucas <[email protected]>"]
license = "MIT"
readme = "README.md"
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Intended Audience :: Education",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"

]
urls = { Homepage = "https://github.com/aaronzo/graph-diffusers" }

[[tool.poetry.source]]
name = "pytorch-cpu"
Expand Down
56 changes: 56 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
set -e

repository="$1"
version="$2"

cwd=$(pwd)
cd `dirname $0`

if [ -z "$repository" ]; then
echo "Usage: $0 <repository> <version>"
exit 1
fi

if [ -z "$version" ]; then
echo "Usage: $0 <repository> <version>"
exit 1
fi

echo "Running poetry lock and install ..."
poetry lock --no-update
poetry install

echo "Setting package version ..."
poetry version $2
echo "__version__ = \"$2\"" > graph_diffusers/_version.py

echo "Running tests ..."
poetry run pytest tests/

echo "Running tests without torch_sparse ..."
poetry run pip uninstall -y torch_sparse
poetry run pytest tests/

echo "Running tests without torch ..."
poetry run pip uninstall -y torch
poetry run pytest tests/

echo "Restoring environment ..."
poetry install

echo "Cleaning up dist/ ..."
rm -rf dist/

echo "Publishing to $repository ..."
poetry publish \
--repository $repository \
--build \
--no-interaction

git tag -m "Release $version" $version
git push origin $version

echo "Done!"

cd $cwd

0 comments on commit 85aa820

Please sign in to comment.