Skip to content

Commit 742ac13

Browse files
authored
Upgrade grandiso to use generator API (#102)
* Upgrade grandiso dependency * Use generator API from grandiso * Update changelog
1 parent 42335b8 commit 742ac13

File tree

4 files changed

+20
-29
lines changed

4 files changed

+20
-29
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
- **0.9.1**
4+
- Features:
5+
- `GrandIsoExecutor`: Adds support for the `grandiso.find_motifs_iter` generator API in grandiso v1.2.0; this reduces the runtime of queries with nonzero `limit` #102
36
- **0.9.0** (March 23 2021)
47
- Features:
58
- `Neo4jExecutor#create_index`. This function call adds an index to the database on the node attribute specified, in order to improve query performance (#95)

dotmotif/executors/GrandIsoExecutor.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""
1616

1717
import networkx as nx
18-
from grandiso import find_motifs
18+
from grandiso import find_motifs_iter
1919

2020
from .NetworkXExecutor import NetworkXExecutor
2121

@@ -52,7 +52,7 @@ def find(self, motif, limit: int = None):
5252
# should be smart enough to know what you want while avoiding adding
5353
# complexity. Anyway, soapbox over.) To that end, this confirmation
5454
# that the motif is directed is kinda... Unimportant.
55-
graph_matcher = find_motifs
55+
graph_matcher = find_motifs_iter
5656

5757
if motif.ignore_direction or not self.graph.is_directed:
5858
graph_constructor = nx.Graph
@@ -67,33 +67,18 @@ def find(self, motif, limit: int = None):
6767
elif attrs["exists"] is False:
6868
# Collect a list of neg-edges to check for again in a moment
6969
must_not_exist_edges.append((u, v))
70-
graph_matches = graph_matcher(only_positive_edges_motif, self.graph)
7170

7271
def _doesnt_have_any_of_motifs_negative_edges(mapping):
7372
for u, v in must_not_exist_edges:
7473
if self.graph.has_edge(mapping[u], mapping[v]):
7574
return False
7675
return True
7776

78-
# Another note. In the NetworkX executor, results are returned in what
79-
# I perceive to be silly order. Why would you tell me "what nodes are
80-
# the result of the mapping to B from A" rather that just "here's the
81-
# mapping from A to B"...? I digress. Anyhow, in the NX executor we
82-
# have to flip the results. Here, we don't. That's why there's a code
83-
# block dict-comprehension missing from this function. Neato.
84-
85-
# Now, filter out those that have edges they should not:
86-
results = [
87-
mapping
88-
for mapping in graph_matches
89-
if _doesnt_have_any_of_motifs_negative_edges(mapping)
90-
]
91-
92-
# Now, filter on attributes:
93-
res = [
94-
r
95-
for r in results
96-
if (
77+
graph_matches = graph_matcher(only_positive_edges_motif, self.graph)
78+
79+
results = []
80+
for r in graph_matches:
81+
if _doesnt_have_any_of_motifs_negative_edges(r) and (
9782
self._validate_edge_constraints(
9883
r, self.graph, motif.list_edge_constraints()
9984
)
@@ -111,6 +96,9 @@ def _doesnt_have_any_of_motifs_negative_edges(mapping):
11196
(not motif.exclude_automorphisms)
11297
or all(r[a] <= r[b] for (a, b) in motif.list_automorphisms())
11398
)
114-
)
115-
]
116-
return res
99+
):
100+
results.append(r)
101+
if limit and len(results) >= limit:
102+
return results
103+
104+
return results

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ py2neo
77
dask[dataframe]
88
tamarind>=0.2.0
99
neuprint-python
10-
grandiso>=1.1.0
10+
grandiso>=1.2.0

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
twine upload dist/*
1212
"""
1313

14-
VERSION = "0.9.0"
14+
VERSION = "0.9.1"
1515

1616
here = os.path.abspath(os.path.dirname(__file__))
1717
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
@@ -25,7 +25,7 @@
2525
description=("Find graph motifs using simple, intuitive notation"),
2626
long_description=long_description,
2727
long_description_content_type="text/markdown",
28-
license="ISC",
28+
license="Apache 2.0",
2929
keywords=["graph", "motif"],
3030
url="https://github.com/aplbrain/dotmotif/tarball/" + VERSION,
3131
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
@@ -40,7 +40,7 @@
4040
"dask[dataframe]",
4141
"tamarind>=0.1.5",
4242
"neuprint-python",
43-
"grandiso",
43+
"grandiso>=1.2.0",
4444
],
4545
include_package_data=True,
4646
)

0 commit comments

Comments
 (0)