Filter out definitions with unavailable constructors in local mode as well
Docker mode does this by checking that the appropriate images are
available; local mode now uses the new algorithm_status method to see
whether a definition can actually be instantiated
@@ -9,7 +9,7 @@ import traceback
from ann_benchmarks.datasets import get_dataset, DATASETS
from ann_benchmarks.constants import INDEX_DIR
-from ann_benchmarks.algorithms.definitions import get_definitions, list_algorithms, get_result_filename
+from ann_benchmarks.algorithms.definitions import get_definitions, list_algorithms, get_result_filename, algorithm_status, InstantiationStatus
from ann_benchmarks.runner import run, run_docker
@@ -118,6 +118,7 @@ def main():
print('running only', args.algorithm)
definitions = [d for d in definitions if d.algorithm == args.algorithm]
+ if not args.local:
if args.docker_tag:
print('running only', args.docker_tag)
definitions = [d for d in definitions if d.docker_tag == args.docker_tag]
@@ -126,6 +127,23 @@ def main():
print('not all docker images available, only:', set(docker_tags))
print('missing docker images:', set(d.docker_tag for d in definitions).difference(docker_tags))
definitions = [d for d in definitions if d.docker_tag in docker_tags]
+ else:
+ def _test(df):
+ status = algorithm_status(df)
+ # If the module was loaded but doesn't actually have a constructor of
+ # the right name, then the definition is broken
+ assert status != InstantiationStatus.NO_CONSTRUCTOR, """\
+%s.%s(%s): error: the module '%s' does not expose the named constructor""" % (df.module, df.constructor, df.arguments, df.module)
+ if status == InstantiationStatus.NO_MODULE:
+ # If the module couldn't be loaded (presumably because of a missing
+ # dependency), print a warning and remove this definition from the
+ # list of things to be run
+ print """\
+%s.%s(%s): warning: the module '%s' could not be loaded; skipping""" % (df.module, df.constructor, df.arguments, df.module)
+ return False
+ else:
+ return True
+ definitions = [d for d in definitions if _test(d)]
if args.max_n_algorithms >= 0:
definitions = definitions[:args.max_n_algorithms]
