From 6b41476933c299fe00f2653855160459cbe02b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20R=C3=BCth?= Date: Thu, 27 Jun 2024 13:16:27 +0300 Subject: [PATCH] Drop unused command() interface --- flatsurvey/cache/cache.py | 18 --------------- flatsurvey/cache/pickles.py | 3 --- flatsurvey/command.py | 20 +---------------- .../jobs/cylinder_periodic_direction.py | 8 ------- flatsurvey/jobs/flow_decomposition.py | 6 ----- flatsurvey/jobs/orbit_closure.py | 13 ----------- .../jobs/saddle_connection_orientations.py | 3 --- flatsurvey/jobs/saddle_connections.py | 8 ------- ...rmined_interval_exchange_transformation.py | 11 +--------- flatsurvey/reporting/json.py | 22 ------------------- flatsurvey/reporting/log.py | 8 ------- flatsurvey/reporting/progress.py | 3 --- flatsurvey/reporting/report.py | 3 --- flatsurvey/scheduler.py | 8 ++----- flatsurvey/surfaces/surface.py | 17 -------------- flatsurvey/worker/dask.py | 20 ++++++++--------- unsupported/jobs/boshernitzan_conjecture.py | 6 ----- .../boshernitzan_conjecture_orientations.py | 3 --- .../jobs/cylinder_periodic_asymptotics.py | 6 ----- unsupported/reporting/yaml.py | 8 ------- 20 files changed, 14 insertions(+), 180 deletions(-) diff --git a/flatsurvey/cache/cache.py b/flatsurvey/cache/cache.py index 0869060..86928c9 100644 --- a/flatsurvey/cache/cache.py +++ b/flatsurvey/cache/cache.py @@ -157,24 +157,6 @@ def click(json, pickles): return {"bindings": Cache.bindings(jsons, pickles)} - def command(self): - r""" - Return command that can be used to create this cache from the command - line. - - EXAMPLES:: - - >>> cache = Cache(pickles=None, jsons=(), report=None) - >>> cache.command() - ['local-cache'] - - """ - return ( - ["local-cache"] - + [f"--json={json.name}" for json in self._jsons] - + ([f"--pickles={self._pickles.name}"] if self._pickles is not None else []) - ) - @classmethod def bindings(cls, jsons, pickles): r""" diff --git a/flatsurvey/cache/pickles.py b/flatsurvey/cache/pickles.py index 6bee15d..dd58b0c 100644 --- a/flatsurvey/cache/pickles.py +++ b/flatsurvey/cache/pickles.py @@ -59,9 +59,6 @@ def click(dir): "bindings": Pickles.bindings(providers=providers), } - def command(self): - return ["pickles"] + [provider.command() for provider in self._providers] - @classmethod def bindings(cls, providers): return [PartialBindingSpec(Pickles, scope="SHARED")(providers=providers)] diff --git a/flatsurvey/command.py b/flatsurvey/command.py index 0a560c1..b9eb897 100644 --- a/flatsurvey/command.py +++ b/flatsurvey/command.py @@ -59,24 +59,6 @@ def name(cls): """ return cls.click.name - @abstractmethod - def command(self): - r""" - Return the command that can be invoked to get this object in its - current configuration. - - EXAMPLES:: - - >>> from flatsurvey.surfaces import Ngon - >>> surface = Ngon((1, 1, 1)) - - >>> from flatsurvey.reporting import Log - >>> log = Log(surface) - >>> log.command() - ['log'] - - """ - def __repr__(self): r""" Return a printable representation of this command. @@ -92,4 +74,4 @@ def __repr__(self): log """ - return " ".join(self.command()) + return self.name() diff --git a/flatsurvey/jobs/cylinder_periodic_direction.py b/flatsurvey/jobs/cylinder_periodic_direction.py index 8155955..409797c 100644 --- a/flatsurvey/jobs/cylinder_periodic_direction.py +++ b/flatsurvey/jobs/cylinder_periodic_direction.py @@ -197,14 +197,6 @@ def click(limit, cache_only): "goals": [CylinderPeriodicDirection], } - def command(self): - command = ["cylinder-periodic-direction"] - if self._limit != self.DEFAULT_LIMIT: - command.append(f"--limit={self._limit}") - if self._cache_only != self.DEFAULT_CACHE_ONLY: - command.append("--cache-only") - return command - async def _consume(self, decomposition, cost): r""" Determine wheter ``decomposition`` is cylinder periodic. diff --git a/flatsurvey/jobs/flow_decomposition.py b/flatsurvey/jobs/flow_decomposition.py index 076d9d6..8736f15 100644 --- a/flatsurvey/jobs/flow_decomposition.py +++ b/flatsurvey/jobs/flow_decomposition.py @@ -89,12 +89,6 @@ def click(limit): "bindings": [PartialBindingSpec(FlowDecompositions)(limit=limit)], } - def command(self): - command = ["flow-decompositions"] - if self._limit != self.DEFAULT_LIMIT: - command.append(f"--limit={self._limit}") - return command - async def _consume(self, orientation, cost): r""" Produce the flow decomposition corresponding to ``orientation``. diff --git a/flatsurvey/jobs/orbit_closure.py b/flatsurvey/jobs/orbit_closure.py index 7fc8d5f..d08236d 100644 --- a/flatsurvey/jobs/orbit_closure.py +++ b/flatsurvey/jobs/orbit_closure.py @@ -240,19 +240,6 @@ def deform(self, deformation): ), } - # TODO: Probably all command() implementations can be removed now. - def command(self): - command = [self.name()] - if self._limit != self.DEFAULT_LIMIT: - command.append(f"--limit={self._limit}") - if self._expansions != self.DEFAULT_EXPANSIONS: - command.append(f"--expansions={self._expansions}") - if self._deform != self.DEFAULT_DEFORM: - command.append("--deform") - if self._cache_only != self.DEFAULT_CACHE_ONLY: - command.append("--cache-only") - return command - @property def dimension(self): return self._surface.orbit_closure().dimension() diff --git a/flatsurvey/jobs/saddle_connection_orientations.py b/flatsurvey/jobs/saddle_connection_orientations.py index d6d3ea9..158d495 100644 --- a/flatsurvey/jobs/saddle_connection_orientations.py +++ b/flatsurvey/jobs/saddle_connection_orientations.py @@ -93,6 +93,3 @@ async def _consume(self, connection, cost): ) def click(): return {"bindings": SaddleConnectionOrientations} - - def command(self): - return ["saddle-connection-orientations"] diff --git a/flatsurvey/jobs/saddle_connections.py b/flatsurvey/jobs/saddle_connections.py index 5695ee3..d682570 100644 --- a/flatsurvey/jobs/saddle_connections.py +++ b/flatsurvey/jobs/saddle_connections.py @@ -131,11 +131,3 @@ def click(bound, limit): PartialBindingSpec(SaddleConnections)(bound=bound, limit=limit) ] } - - def command(self): - command = ["saddle-connections"] - if self._bound != self.DEFAULT_BOUND: - command.append(f"--bound={self._bound}") - if self._limit != self.DEFAULT_LIMIT: - command.append(f"--limit={self._limit}") - return command diff --git a/flatsurvey/jobs/undetermined_interval_exchange_transformation.py b/flatsurvey/jobs/undetermined_interval_exchange_transformation.py index 13ea592..16a8d5f 100644 --- a/flatsurvey/jobs/undetermined_interval_exchange_transformation.py +++ b/flatsurvey/jobs/undetermined_interval_exchange_transformation.py @@ -146,7 +146,7 @@ async def consume_cache(self): >>> import asyncio >>> asyncio.run(goal.consume_cache()) >>> report.flush() # doctest: +ELLIPSIS - {"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "undetermined-iet --cache-only": [{"timestamp": ..., "iets": ["IET(\u2026)", "IET(\u2026)"], "cached": true, "value": null}]} + {"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "undetermined-iet": [{"timestamp": ..., "iets": ["IET(\u2026)", "IET(\u2026)"], "cached": true, "value": null}]} """ if not self._cache_only: @@ -185,15 +185,6 @@ def click(limit): ) ], } - - def command(self): - command = ["undetermined-iet"] - if self._limit != UndeterminedIntervalExchangeTransformation.DEFAULT_LIMIT: - command += ["--limit", str(self._limit)] - if self._cache_only != self.DEFAULT_CACHE_ONLY: - command.append("--cache-only") - return command - _hacks_enabled = False @classmethod diff --git a/flatsurvey/reporting/json.py b/flatsurvey/reporting/json.py index 8d6ebe3..f71e9bc 100644 --- a/flatsurvey/reporting/json.py +++ b/flatsurvey/reporting/json.py @@ -92,28 +92,6 @@ def click(output): "reporters": [Json], } - def command(self): - r""" - Return the command line command used to create this reporter. - - EXAMPLES:: - - >>> from flatsurvey.reporting.json import Json - >>> from flatsurvey.surfaces import Ngon - >>> surface = Ngon((1, 1, 1)) - >>> json = Json(surface) - - >>> json.command() - ['json'] - - """ - import sys - - command = ["json"] - if self._stream is not sys.stdout: - command.append(f"--output={self._stream.name}") - return command - async def result(self, source, result, **kwargs): r""" Report a ``result`` for ``source``. diff --git a/flatsurvey/reporting/log.py b/flatsurvey/reporting/log.py index a2aa999..11dd18d 100644 --- a/flatsurvey/reporting/log.py +++ b/flatsurvey/reporting/log.py @@ -200,11 +200,3 @@ async def result(self, source, result, **kwargs): if kwargs.pop("cached", False): result = f"{result} (cached)" self.log(source, result, **kwargs) - - def command(self): - command = [self.name()] - import sys - - if self._stream is not sys.stdout: - command.append(f"--output={self._stream.name}") - return command diff --git a/flatsurvey/reporting/progress.py b/flatsurvey/reporting/progress.py index e998c40..1ee6289 100644 --- a/flatsurvey/reporting/progress.py +++ b/flatsurvey/reporting/progress.py @@ -148,9 +148,6 @@ def bindings(cls): else: return [PartialBindingSpec(Progress, scope="SHARED")()] - def command(self): - return ["progress"] - def deform(self, deformation): return { "bindings": Progress.bindings(), diff --git a/flatsurvey/reporting/report.py b/flatsurvey/reporting/report.py index 8e5f012..22640db 100644 --- a/flatsurvey/reporting/report.py +++ b/flatsurvey/reporting/report.py @@ -191,9 +191,6 @@ def ignore(self, source): return False - def command(self): - return ["report"] + [f"--ignore={i}" for i in self._ignore] - def deform(self, deformation): return {"bindings": Report.bindings(ignore=self._ignore)} diff --git a/flatsurvey/scheduler.py b/flatsurvey/scheduler.py index 5b3b24c..1ba0060 100644 --- a/flatsurvey/scheduler.py +++ b/flatsurvey/scheduler.py @@ -206,21 +206,17 @@ async def _schedule(self, pool, pending, surfaces, goals, scheduling_progress): if surface is None: return False - print(surface) - if await self._resolve_goals_from_cache(surface, self._goals): # Everything could be answered from cached data. Proceed to next surface. continue - from flatsurvey.worker.worker import Worker - from flatsurvey.pipeline.util import FactoryBindingSpec, ListBindingSpec bindings = list(self._bindings) bindings.append(SurfaceBindingSpec(surface)) from flatsurvey.worker.dask import DaskTask - task = DaskTask(Worker.work, bindings=bindings, goals=self._goals, reporters=self._reporters) + task = DaskTask(bindings=bindings, goals=self._goals, reporters=self._reporters) pending.append(pool.submit(task)) return True @@ -237,7 +233,7 @@ async def _consume(self, pool, pending): return False for job in completed: - print(await job) + await job return True diff --git a/flatsurvey/surfaces/surface.py b/flatsurvey/surfaces/surface.py index 600aa49..59772e8 100644 --- a/flatsurvey/surfaces/surface.py +++ b/flatsurvey/surfaces/surface.py @@ -141,23 +141,6 @@ def _surface(self): """ - def command(self): - r""" - Return command line arguments that can be used to recreate this surface. - - EXAMPLES:: - - >>> from flatsurvey.surfaces import Ngon - >>> Ngon((1, 1, 1)).command() - ['pickle', '--base64', '...'] - - """ - from base64 import b64encode - - from sage.all import dumps - - return ["pickle", "--base64", b64encode(dumps(self)).decode("ASCII").strip()] - def basename(self): r""" Return a prefix for files such as logfiles. diff --git a/flatsurvey/worker/dask.py b/flatsurvey/worker/dask.py index 835035c..ffd6992 100644 --- a/flatsurvey/worker/dask.py +++ b/flatsurvey/worker/dask.py @@ -1,24 +1,24 @@ import multiprocessing - forkserver = multiprocessing.get_context("forkserver") multiprocessing.set_forkserver_preload(["sage.all"]) class DaskTask: - def __init__(self, callable, *args, **kwargs): + def __init__(self, *args, **kwargs): from pickle import dumps - self._dump = dumps((callable, args, kwargs)) + self._dump = dumps((args, kwargs)) def __call__(self): DaskWorker.process(self) def run(self): from pickle import loads - callable, args, kwargs =loads(self._dump) + args, kwargs =loads(self._dump) + + from flatsurvey.worker.worker import Worker import asyncio - result = asyncio.run(callable(*args, **kwargs)) - print(result) + result = asyncio.run(Worker.work(*args, **kwargs)) return result @@ -35,12 +35,14 @@ def __init__(self): @staticmethod def _ensure_started(): + if DaskWorker._singleton is not None: + return + import sys if 'sage' in sys.modules: raise Exception("sage must not be loaded in dask worker") - if DaskWorker._singleton is None: - DaskWorker._singleton = DaskWorker() + DaskWorker._singleton = DaskWorker() @staticmethod def _process(self): @@ -49,10 +51,8 @@ def _process(self): task = self._work_queue.get() except ValueError: break - print(task) self._result_queue.put(task.run()) - print("done.") @staticmethod def process(task): diff --git a/unsupported/jobs/boshernitzan_conjecture.py b/unsupported/jobs/boshernitzan_conjecture.py index dcd481e..d391354 100644 --- a/unsupported/jobs/boshernitzan_conjecture.py +++ b/unsupported/jobs/boshernitzan_conjecture.py @@ -198,12 +198,6 @@ def click(cache_only): "goals": [BoshernitzanConjecture], } - def command(self): - command = ["boshernitzan-conjecture"] - if self._cache_only != self.DEFAULT_CACHE_ONLY: - command.append("--cache-only") - return command - @classmethod def reduce(self, results): r""" diff --git a/unsupported/jobs/boshernitzan_conjecture_orientations.py b/unsupported/jobs/boshernitzan_conjecture_orientations.py index ddc6cf6..0c41592 100644 --- a/unsupported/jobs/boshernitzan_conjecture_orientations.py +++ b/unsupported/jobs/boshernitzan_conjecture_orientations.py @@ -385,6 +385,3 @@ def click(): )() ] } - - def command(self): - return ["boshernitzan-conjecture-orientations"] diff --git a/unsupported/jobs/cylinder_periodic_asymptotics.py b/unsupported/jobs/cylinder_periodic_asymptotics.py index cf9c2e8..8b06214 100644 --- a/unsupported/jobs/cylinder_periodic_asymptotics.py +++ b/unsupported/jobs/cylinder_periodic_asymptotics.py @@ -171,12 +171,6 @@ def click(cache_only): "goals": [CylinderPeriodicAsymptotics], } - def command(self): - command = ["cylinder-periodic-asymptotics"] - if self._cache_only != self.DEFAULT_CACHE_ONLY: - command.append("--cache-only") - return command - @classmethod def reduce(self, results): r""" diff --git a/unsupported/reporting/yaml.py b/unsupported/reporting/yaml.py index 2bc5b56..e224bb2 100644 --- a/unsupported/reporting/yaml.py +++ b/unsupported/reporting/yaml.py @@ -253,14 +253,6 @@ def click(output): "reporters": [Yaml], } - def command(self): - import sys - - command = ["yaml"] - if self._stream is not sys.stdout: - command.append(f"--output={self._stream.name}") - return command - class Pickle: r""" Wrapper for objects that should be stored as their pickles in the YAML output.