Skip to content

Commit

Permalink
Upgrade grandiso to use generator API (#102)
Browse files Browse the repository at this point in the history
* Upgrade grandiso dependency

* Use generator API from grandiso

* Update changelog
  • Loading branch information
j6k4m8 committed May 6, 2021
1 parent 42335b8 commit 742ac13
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog

- **0.9.1**
- Features:
- `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
- **0.9.0** (March 23 2021)
- Features:
- `Neo4jExecutor#create_index`. This function call adds an index to the database on the node attribute specified, in order to improve query performance (#95)
Expand Down
38 changes: 13 additions & 25 deletions dotmotif/executors/GrandIsoExecutor.py
Expand Up @@ -15,7 +15,7 @@
"""

import networkx as nx
from grandiso import find_motifs
from grandiso import find_motifs_iter

from .NetworkXExecutor import NetworkXExecutor

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

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

def _doesnt_have_any_of_motifs_negative_edges(mapping):
for u, v in must_not_exist_edges:
if self.graph.has_edge(mapping[u], mapping[v]):
return False
return True

# Another note. In the NetworkX executor, results are returned in what
# I perceive to be silly order. Why would you tell me "what nodes are
# the result of the mapping to B from A" rather that just "here's the
# mapping from A to B"...? I digress. Anyhow, in the NX executor we
# have to flip the results. Here, we don't. That's why there's a code
# block dict-comprehension missing from this function. Neato.

# Now, filter out those that have edges they should not:
results = [
mapping
for mapping in graph_matches
if _doesnt_have_any_of_motifs_negative_edges(mapping)
]

# Now, filter on attributes:
res = [
r
for r in results
if (
graph_matches = graph_matcher(only_positive_edges_motif, self.graph)

results = []
for r in graph_matches:
if _doesnt_have_any_of_motifs_negative_edges(r) and (
self._validate_edge_constraints(
r, self.graph, motif.list_edge_constraints()
)
Expand All @@ -111,6 +96,9 @@ def _doesnt_have_any_of_motifs_negative_edges(mapping):
(not motif.exclude_automorphisms)
or all(r[a] <= r[b] for (a, b) in motif.list_automorphisms())
)
)
]
return res
):
results.append(r)
if limit and len(results) >= limit:
return results

return results
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -7,4 +7,4 @@ py2neo
dask[dataframe]
tamarind>=0.2.0
neuprint-python
grandiso>=1.1.0
grandiso>=1.2.0
6 changes: 3 additions & 3 deletions setup.py
Expand Up @@ -11,7 +11,7 @@
twine upload dist/*
"""

VERSION = "0.9.0"
VERSION = "0.9.1"

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

0 comments on commit 742ac13

Please sign in to comment.