From 107fb0c17f33f2c9460cc13d4bf6e3edc74be7e5 Mon Sep 17 00:00:00 2001 From: Krzysztof Maziarz Date: Thu, 7 Sep 2023 13:11:37 +0000 Subject: [PATCH] fix(node_evaluators): Handle the empty input list case --- CHANGELOG.md | 2 +- syntheseus/search/node_evaluation/base.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce98e78b..feda442f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0. - Add a top-level CLI for running end-to-end search ([#26](https://github.com/microsoft/syntheseus/pull/26)) ([@kmaziarz]) - Release single-step evaluation framework and wrappers for several model types ([#14](https://github.com/microsoft/syntheseus/pull/14), [#15](https://github.com/microsoft/syntheseus/pull/15), [#20](https://github.com/microsoft/syntheseus/pull/20)) ([@kmaziarz]) - Release checkpoints for all supported single-step model types ([#21](https://github.com/microsoft/syntheseus/pull/21)) ([@kmaziarz]) -- Implement node evaluators commonly used in MCTS and Retro* ([#23](https://github.com/microsoft/syntheseus/pull/23)) ([@kmaziarz]) +- Implement node evaluators commonly used in MCTS and Retro* ([#23](https://github.com/microsoft/syntheseus/pull/23), [#27](https://github.com/microsoft/syntheseus/pull/27)) ([@kmaziarz]) - Add option to terminate search when the first solution is found ([#13](https://github.com/microsoft/syntheseus/pull/13)) ([@austint]) - Add code to extract routes in order found instead of by minimum cost ([#9](https://github.com/microsoft/syntheseus/pull/9)) ([@austint]) - Declare support for type checking ([#4](https://github.com/microsoft/syntheseus/pull/4)) ([@kmaziarz]) diff --git a/syntheseus/search/node_evaluation/base.py b/syntheseus/search/node_evaluation/base.py index d6e4e786..c2218c98 100644 --- a/syntheseus/search/node_evaluation/base.py +++ b/syntheseus/search/node_evaluation/base.py @@ -138,6 +138,9 @@ def _get_probability(self, node, graph) -> float: return metadata["probability"] # type: ignore def _evaluate_nodes(self, nodes, graph=None) -> Sequence[float]: + if not nodes: # handle the case when there are no nodes to score + return [] + probs = np.asarray([self._get_probability(n, graph) for n in nodes]) probs = np.clip(probs, a_min=self._clip_probability_min, a_max=self._clip_probability_max)