Skip to content

Commit

Permalink
Merge pull request #28 from kkaris/extend-subgraph-timeout
Browse files Browse the repository at this point in the history
Extend subgraph timeout
  • Loading branch information
kkaris authored Jun 9, 2023
2 parents 2a53464 + 3aea81c commit 248239c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
sudo apt-get install libstdc++6 graphviz python3-dev libgraphviz-dev pkg-config
python -m pip install --upgrade pip
pip install -e .[tests]
pip install termcolor cachetools
pip install termcolor cachetools httpx
git clone https://github.com/indralab/depmap_analysis.git
- name: Run unit tests
run: |
Expand Down
4 changes: 4 additions & 0 deletions indra_network_search/data_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - In FilterOptions, set overall weighted based on values of weighted
# context weighted. See here for more info:
# https://stackoverflow.com/q/54023782/10478812
# - Make the is_empty method also look into the children of the object?
import logging
from collections import Counter
from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
Expand Down Expand Up @@ -77,6 +78,7 @@
"SubgraphResults",
"MultiInteractorsResults",
"DEFAULT_TIMEOUT",
"MAX_TIMEOUT",
"WEIGHT_NAME_MAPPING",
"basemodels_equal",
"basemodel_in_iterable",
Expand All @@ -89,6 +91,7 @@

# Set defaults
DEFAULT_TIMEOUT = 30
MAX_TIMEOUT = 590 # Less than timeout on the load balancer and nginx
WEIGHT_NAME_MAPPING = {
"belief": "weight",
"context": "context_weight",
Expand Down Expand Up @@ -571,6 +574,7 @@ class SubgraphRestQuery(BaseModel):
"""Subgraph query"""

nodes: conlist(item_type=Node, min_items=1, max_items=4000)
timeout: confloat(ge=1, le=MAX_TIMEOUT) = MAX_TIMEOUT


class SubgraphOptions(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion indra_network_search/frontend/src/views/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</p>
<p>
This project's backend is powered by <a href="https://fastapi.tiangolo.com/" target="_blank">FastAPI</a>.
The frontend is made 100 % in <a href="https://v3.vuejs.org/" target="_blank">Vue 3</a>.
The frontend is made 100 % in <a href="https://vuejs.org/" target="_blank">Vue 3</a>.
</p>
</div>
</template>
1 change: 1 addition & 0 deletions indra_network_search/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ def result_options(self) -> Dict[str, Any]:
"original_nodes": self.query.nodes,
"nodes_in_graph": self._nodes_in_graph,
"not_in_graph": self._not_in_graph,
"timeout": self.query.timeout
}


Expand Down
8 changes: 4 additions & 4 deletions indra_network_search/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def startup_event():
# - https://www.starlette.io/events/
if DEBUG:
from indra_network_search.tests.util import (
_setup_graph,
_setup_signed_node_graph,
unsigned_graph,
signed_node_graph,
)

dir_graph = _setup_graph()
sign_node_graph = _setup_signed_node_graph(False)
dir_graph = unsigned_graph
sign_node_graph = signed_node_graph
else:
# ToDo The file IO has to be done awaited to make this function async
dir_graph, _, _, sign_node_graph = load_indra_graph(
Expand Down
6 changes: 4 additions & 2 deletions indra_network_search/result_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Union,
)

from depmap_analysis.network_functions.famplex_functions import get_identifiers_url
from indra.databases.identifiers import get_identifiers_url
from indra.explanation.pathfinding import (
bfs_search,
open_dijkstra_search,
Expand Down Expand Up @@ -733,7 +733,7 @@ def _get_results(self) -> SharedInteractorsResults:
target_edges: List[EdgeData] = []
for (s1, s2), (t1, t2) in self.path_gen:
if self.timeout and datetime.utcnow() - self.start_time > timedelta(seconds=self.timeout):
logger.info(f"Timeout reached ({self.timeout} seconds), " f"breaking results loop")
logger.info(f"Timeout reached ({self.timeout} seconds), breaking results loop")
self.timed_out = True
break
source_edge = self._get_edge_data(a=s1, b=s2)
Expand Down Expand Up @@ -858,12 +858,14 @@ def __init__(
nodes_in_graph: List[Node],
not_in_graph: List[Node],
ev_limit: int = 10,
timeout: float = MAX_TIMEOUT,
):
super().__init__(
path_generator=path_generator,
graph=graph,
filter_options=filter_options,
input_nodes=original_nodes,
timeout=timeout
)
self.edge_dict: Dict[Tuple[str, str], EdgeDataByHash] = {}
self._available_nodes: Dict[str, Node] = {n.name: n for n in nodes_in_graph}
Expand Down
12 changes: 11 additions & 1 deletion indra_network_search/tests/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from inspect import signature
from typing import Any, Callable, Dict, List, Optional, Set, Tuple
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union

from indra.assemblers.indranet.net import default_sign_dict
from indra.explanation.model_checker.model_checker import signed_edges_to_signed_nodes
Expand Down Expand Up @@ -96,6 +96,13 @@ def _setup_signed_node_graph(large: bool) -> DiGraph:
return signed_edges_to_signed_nodes(graph=seg, copy_edge_data=True, prune_nodes=True)


def _add_graph_meta(g: Union[DiGraph, MultiDiGraph]):
ns_id_to_nodename = {}
for name, data in g.nodes(data=True):
ns_id_to_nodename[(data["ns"], data["id"])] = name
g.graph["node_by_ns_id"] = ns_id_to_nodename


def _setup_api(large: bool) -> IndraNetworkSearchAPI:
g = expanded_unsigned_graph if large else unsigned_graph
sg = exp_signed_node_graph if large else signed_node_graph
Expand Down Expand Up @@ -346,3 +353,6 @@ def _get_edge_hash(edge: StrEdge, graph: DiGraph, large: bool, signed: bool):
exp_signed_node_graph = _setup_signed_node_graph(True)
search_api = _setup_api(False)
exp_search_api = _setup_api(True)

for graph in [unsigned_graph, expanded_unsigned_graph, signed_node_graph, exp_signed_node_graph]:
_add_graph_meta(graph)
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ install_requires =
fnvhash
autodoc_pydantic

zip_safe = false
include_package_data = True
python_requires = >=3.7

# Where is my code
packages = find:

[options.extras_require]
tests =
nose

0 comments on commit 248239c

Please sign in to comment.