Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump version to 3.10 #21

Merged
merged 4 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9"]
python-version: ["3.8", "3.9", "3.10"]
Copy link
Owner

@pedugnat pedugnat Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the major thing with current PR is that python-version will only be ["3.10"] and not ["3.8", "3.9", "3.10"] no ? A lot of new features are not backward compatible (cf. CI)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be best if we only supported 3.10 yes but I wanted to make sure that was ok with you before scrapping 3.8 altogether


steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,6 @@ healthchecksdb
MigrationBackup/

# Virtual environment
venv/
venv*

# End of https://www.gitignore.io/api/osx,python,pycharm,windows,visualstudio,visualstudiocode
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.8
python: python3.10

default_stages: [commit, push]

Expand Down
20 changes: 10 additions & 10 deletions dynnode2vec/biased_random_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Define a BiasedRandomWalk class to perform biased random walks over graphs.
"""
# pylint: disable=invalid-name
from typing import Any, Dict, Iterable, List, Union
from typing import Any, Iterable

import bisect
import random
Expand All @@ -11,7 +11,7 @@
import networkx as nx
import numpy as np

RandomWalks = List[List[Any]]
RandomWalks = list[list[Any]]


class BiasedRandomWalk:
Expand All @@ -29,8 +29,8 @@ def __init__(self, graph: nx.Graph) -> None:
graph, ordering="default", label_attribute="true_label"
)

self.mapping: Dict[int, Any] = nx.get_node_attributes(self.graph, "true_label")
self.reverse_mapping: Dict[Any, int] = {
self.mapping: dict[int, Any] = nx.get_node_attributes(self.graph, "true_label")
self.reverse_mapping: dict[Any, int] = {
true_label: int_id for int_id, true_label in self.mapping.items()
}

Expand All @@ -41,7 +41,7 @@ def map_int_ids_to_true_ids(self, walks: RandomWalks) -> None:
for i, walk in enumerate(walks):
walks[i] = [self.mapping[int_id] for int_id in walk]

def convert_true_ids_to_int_ids(self, nodes: Iterable[Any]) -> List[int]:
def convert_true_ids_to_int_ids(self, nodes: Iterable[Any]) -> list[int]:
"""
Convert list of node labels to list of int ids.
"""
Expand Down Expand Up @@ -72,7 +72,7 @@ def _generate_walk(
iq: float,
weighted: bool,
rn: random.Random,
) -> List[int]:
) -> list[int]:
# pylint: disable=too-many-arguments, too-many-locals
"""
Generate a number of random walks starting from a given node.
Expand All @@ -81,7 +81,7 @@ def _generate_walk(
walk = [node]

previous_node = None
previous_node_neighbours: Any = []
previous_node_neighbours: list[Any] = []

current_node = node

Expand Down Expand Up @@ -123,7 +123,7 @@ def _generate_walk_simple(
iq: float,
weighted: bool,
rn: random.Random,
) -> List[int]:
) -> list[int]:
# pylint: disable=too-many-arguments
"""
Fast implementation for the scenario where:
Expand All @@ -145,14 +145,14 @@ def _generate_walk_simple(

def run(
self,
nodes: List[Any],
nodes: list[Any],
*,
n_walks: int = 10,
walk_length: int = 10,
p: float = 1.0,
q: float = 1.0,
weighted: bool = False,
seed: Union[int, None] = None,
seed: int | None = None,
) -> RandomWalks:
"""
Perform a number of random walks for all the nodes of the graph. The
Expand Down
20 changes: 10 additions & 10 deletions dynnode2vec/dynnode2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Define a DynNode2Vec class to run dynnode2vec algorithm over dynamic graphs.
"""
# pylint: disable=invalid-name
from typing import Any, Iterable, List, Optional, Set, Tuple
from typing import Any, Iterable

from collections import namedtuple
from itertools import chain, starmap
Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(
n_walks_per_node: int = 10,
embedding_size: int = 128,
window: int = 10,
seed: Optional[int] = 0,
seed: int | None = 0,
parallel_processes: int = 4,
plain_node2vec: bool = False,
):
Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(
isinstance(window, int) and embedding_size > 0
), "window should be a strictly positive integer"
assert (
seed is None or isinstance(seed, int)
isinstance(seed, int | None)
) and embedding_size > 0, "seed should be either None or int"
assert (
isinstance(parallel_processes, int) and 0 < parallel_processes < 128
Expand All @@ -90,8 +90,8 @@ def __init__(
self.gensim_workers = max(self.parallel_processes - 1, 12)

def _initialize_embeddings(
self, graphs: List[nx.Graph]
) -> Tuple[Word2Vec, List[Embedding]]:
self, graphs: list[nx.Graph]
) -> tuple[Word2Vec, list[Embedding]]:
"""
Compute normal node2vec embedding at timestep 0.
"""
Expand Down Expand Up @@ -120,7 +120,7 @@ def _initialize_embeddings(
return model, [embedding]

@staticmethod
def get_delta_nodes(current_graph: nx.Graph, previous_graph: nx.Graph) -> Set[Any]:
def get_delta_nodes(current_graph: nx.Graph, previous_graph: nx.Graph) -> set[Any]:
"""
Find nodes in the current graph which have been modified, i.e. they have been added,
or at least one of their edge have been updated.
Expand All @@ -144,7 +144,7 @@ def get_delta_nodes(current_graph: nx.Graph, previous_graph: nx.Graph) -> Set[An
# Delta nodes are new nodes (V_add) and current nodes which edges have changed.
# Since we only care about nodes that have at least one edge, we can
# assume that V_add ⊆ {v_i ∈ V_t | ∃e_i = (v_i, v_j) ∈ (E_add ∪ E_del)}
delta_nodes: Set[Any] = current_graph.nodes & nodes_with_modified_edges
delta_nodes: set[Any] = current_graph.nodes & nodes_with_modified_edges

return delta_nodes

Expand Down Expand Up @@ -174,7 +174,7 @@ def generate_updated_walks(

return updated_walks

def _simulate_walks(self, graphs: List[nx.Graph]) -> Iterable[RandomWalks]:
def _simulate_walks(self, graphs: list[nx.Graph]) -> Iterable[RandomWalks]:
"""
Parallelize the generation of walks on the time steps graphs.
"""
Expand All @@ -186,7 +186,7 @@ def _simulate_walks(self, graphs: List[nx.Graph]) -> Iterable[RandomWalks]:

def _update_embeddings(
self,
embeddings: List[Embedding],
embeddings: list[Embedding],
time_walks: Iterable[RandomWalks],
model: Word2Vec,
) -> None:
Expand Down Expand Up @@ -226,7 +226,7 @@ def _update_embeddings(

embeddings.append(embedding)

def compute_embeddings(self, graphs: List[nx.Graph]) -> List[Embedding]:
def compute_embeddings(self, graphs: list[nx.Graph]) -> list[Embedding]:
"""
Compute dynamic embeddings on a list of graphs.
"""
Expand Down
6 changes: 2 additions & 4 deletions dynnode2vec/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""
Utility file to define miscellaneous functions.
"""
from typing import List

import random

import networkx as nx


def sample_nodes(graph: nx.Graph, k: int) -> List[int]:
def sample_nodes(graph: nx.Graph, k: int) -> list[int]:
"""
Samples nodes randomly from a graph.
"""
Expand All @@ -17,7 +15,7 @@ def sample_nodes(graph: nx.Graph, k: int) -> List[int]:

def create_dynamic_graph(
n_base_nodes: int = 100, n_steps: int = 10, base_density: float = 0.01
) -> List[nx.Graph]:
) -> list[nx.Graph]:
"""
Creates a list of graphs representing the evolution of a dynamic graph,
i.e. graphs that each depend on the previous graph.
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
]



[tool.poetry.dependencies]
python = ">=3.8,<3.9.0"
python = ">=3.8,<3.11"
numpy = "^1.23.1"
networkx = "^2.8.5"
gensim = "^4.2.0"
Expand All @@ -55,7 +56,7 @@ pytest-cov = "^3.0.0"

[tool.black]
# https://github.com/psf/black
target-version = ["py38"]
target-version = ["py38", "py39", "py310"]
line-length = 88
color = true

Expand All @@ -77,7 +78,7 @@ exclude = '''

[tool.isort]
# https://github.com/timothycrosley/isort/
py_version = 38
py_version = 310
line_length = 88

known_typing = ["typing", "types", "typing_extensions", "mypy", "mypy_extensions"]
Expand All @@ -90,7 +91,7 @@ color_output = true

[tool.mypy]
# https://mypy.readthedocs.io/en/latest/config_file.html#using-a-pyproject-toml-file
python_version = 3.8
python_version = 3.9
pretty = true
show_traceback = true
color_output = true
Expand Down