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

Prepare for 2.2.0 roll #40

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## [v2.2.0 (January 11 2022)](https://pypi.org/project/grandiso/2.2.0/)

- Features
- (#39) Adds streaming match generators (thanks @davidmezzetti!)
- Fixes
- (#37) Improve performance of `find_motifs` by remembering to actually update `_greatest_backbone_count` (thanks @nobutoba!)

## [v2.1.1 (December 21 2021)](https://pypi.org/project/grandiso/2.1.0/)

- Fixes
Expand Down
23 changes: 14 additions & 9 deletions grandiso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
attribute search.
"""

from typing import Dict, Generator, Hashable, List, Optional, Union, Tuple
from typing import Dict, Generator, Hashable, List, Union, Tuple
import itertools
from functools import lru_cache

import networkx as nx

__version__ = "2.1.1"
__version__ = "2.2.0"


@lru_cache()
Expand Down Expand Up @@ -161,8 +161,9 @@ def get_next_backbone_candidates(
# Let's return ALL possible node choices for this next_node. To do this
# without being an insane person, let's filter on max degree in host:
for n in host.nodes:
if is_node_attr_match(next_node, n, motif, host) \
and is_node_structural_match(next_node, n, motif, host):
if is_node_attr_match(
next_node, n, motif, host
) and is_node_structural_match(next_node, n, motif, host):
yield {next_node: n}
return

Expand Down Expand Up @@ -248,7 +249,7 @@ def get_next_backbone_candidates(
# This is neato :) It means that there are multiple edges in the host
# graph that we can use to downselect the number of candidate nodes.
candidate_nodes_set = set()
for (source, _, target) in required_edges:
for source, _, target in required_edges:
if directed:
if source is not None:
# this is a "from" edge:
Expand Down Expand Up @@ -281,9 +282,11 @@ def get_next_backbone_candidates(

def tentative_results():
for c in candidate_nodes:
if c not in backbone.values() \
and is_node_attr_match(next_node, c, motif, host) \
and is_node_structural_match(next_node, c, motif, host):
if (
c not in backbone.values()
and is_node_attr_match(next_node, c, motif, host)
and is_node_structural_match(next_node, c, motif, host)
):
yield {**backbone, next_node: c}

# One last filtering step here. This is to catch the cases where you have
Expand Down Expand Up @@ -323,7 +326,7 @@ def monomorphism_candidates():
# to confirm that no spurious edges exist in the induced subgraph:
def isomorphism_candidates():
for result in monomorphism_candidates():
for (motif_u, motif_v) in itertools.product(result.keys(), result.keys()):
for motif_u, motif_v in itertools.product(result.keys(), result.keys()):
# if the motif has this edge, then it doesn't rule any of the
# above results out as an isomorphism.
# if the motif does NOT have the edge, then NO RESULT may have
Expand All @@ -338,6 +341,7 @@ def isomorphism_candidates():

yield from isomorphism_candidates()


def uniform_node_interestingness(motif: nx.Graph) -> dict:
"""
Sort the nodes in a motif by their interestingness.
Expand Down Expand Up @@ -422,6 +426,7 @@ def walk(path):
for path in paths:
yield from walk(path)


def find_motifs(
motif: nx.Graph,
host: nx.Graph,
Expand Down
2 changes: 1 addition & 1 deletion grandiso/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

try:
SimpleQueue = queue.SimpleQueue
except:
except ImportError:
SimpleQueue = queue.Queue


Expand Down
4 changes: 1 addition & 3 deletions grandiso/test_grandiso.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import time
import copy
import random
import pytest

Expand Down Expand Up @@ -318,7 +316,7 @@ def _random_host(directed=False, n=20, p=0.1):
def _random_directed_motif():
motif = _random_motif()
dmotif = nx.DiGraph()
for (u, v) in motif.edges():
for u, v in motif.edges():
dmotif.add_edge(*random.choice([(u, v), (v, u)]))
return dmotif

Expand Down
8 changes: 5 additions & 3 deletions grandiso/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@


@pytest.mark.parametrize(
"queue,queue_args", all_queues,
"queue,queue_args",
all_queues,
)
def test_empty(queue, queue_args):
q = queue(*queue_args)
assert q.empty()
q.put(1)
assert q.empty() == False
assert q.empty() is False
q.get()
assert q.empty()


@pytest.mark.parametrize(
"queue,queue_args", all_queues,
"queue,queue_args",
all_queues,
)
def test_can_put_and_pop(queue, queue_args):
q = queue(*queue_args)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="grandiso",
version="2.1.1",
version="2.2.0",
author="Jordan Matelsky",
author_email="[email protected]",
description="Performant subgraph isomorphism",
Expand All @@ -18,4 +18,5 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
install_requires=["networkx>=2.5.1"],
)
Loading