Skip to content

Commit

Permalink
Drop unused command() interface
Browse files Browse the repository at this point in the history
  • Loading branch information
saraedum committed Jun 27, 2024
1 parent 903f48b commit 6b41476
Show file tree
Hide file tree
Showing 20 changed files with 14 additions and 180 deletions.
18 changes: 0 additions & 18 deletions flatsurvey/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
3 changes: 0 additions & 3 deletions flatsurvey/cache/pickles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
20 changes: 1 addition & 19 deletions flatsurvey/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -92,4 +74,4 @@ def __repr__(self):
log
"""
return " ".join(self.command())
return self.name()
8 changes: 0 additions & 8 deletions flatsurvey/jobs/cylinder_periodic_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions flatsurvey/jobs/flow_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
13 changes: 0 additions & 13 deletions flatsurvey/jobs/orbit_closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions flatsurvey/jobs/saddle_connection_orientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,3 @@ async def _consume(self, connection, cost):
)
def click():
return {"bindings": SaddleConnectionOrientations}

def command(self):
return ["saddle-connection-orientations"]
8 changes: 0 additions & 8 deletions flatsurvey/jobs/saddle_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 1 addition & 10 deletions flatsurvey/jobs/undetermined_interval_exchange_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions flatsurvey/reporting/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
8 changes: 0 additions & 8 deletions flatsurvey/reporting/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions flatsurvey/reporting/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 0 additions & 3 deletions flatsurvey/reporting/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}

Expand Down
8 changes: 2 additions & 6 deletions flatsurvey/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -237,7 +233,7 @@ async def _consume(self, pool, pending):
return False

for job in completed:
print(await job)
await job

return True

Expand Down
17 changes: 0 additions & 17 deletions flatsurvey/surfaces/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions flatsurvey/worker/dask.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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):
Expand All @@ -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):
Expand Down
6 changes: 0 additions & 6 deletions unsupported/jobs/boshernitzan_conjecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
3 changes: 0 additions & 3 deletions unsupported/jobs/boshernitzan_conjecture_orientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,3 @@ def click():
)()
]
}

def command(self):
return ["boshernitzan-conjecture-orientations"]
6 changes: 0 additions & 6 deletions unsupported/jobs/cylinder_periodic_asymptotics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
8 changes: 0 additions & 8 deletions unsupported/reporting/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6b41476

Please sign in to comment.