From 50ebec1c234f6aede7906383d7800dda02bf5ed5 Mon Sep 17 00:00:00 2001 From: Jack Betteridge Date: Tue, 13 Aug 2024 17:31:18 +0100 Subject: [PATCH] Just notes --- pyop2/caching.py | 74 ++++++++++++++++++++++++++++++++++++++++++ pyop2/global_kernel.py | 1 + 2 files changed, 75 insertions(+) diff --git a/pyop2/caching.py b/pyop2/caching.py index 7522c6978..2ee71fe9f 100644 --- a/pyop2/caching.py +++ b/pyop2/caching.py @@ -481,6 +481,80 @@ def default_parallel_hashkey(*args, **kwargs): comm = kwargs.get('comm') return comm, cachetools.keys.hashkey(*args, **kwargs) +#### connor bits + +# ~ def pcache(comm_seeker, key=None, cache_factory=dict): + + # ~ comm = comm_seeker() + # ~ cache = cache_factory() + +# ~ @pcache(cachetools.LRUCache) + +@pcache(DiskCache) + +@pcache(MemDiskCache) + +@pcache(MemCache) + +mem_cache = pcache(cache_factory=cachetools.LRUCache) +disk_cache = mem_cache(cache_factory=DiskCache) + +# ~ @pcache(comm_seeker=lambda obj, *_, **_: obj.comm, cache_factory=lambda: cachetools.LRUCache(maxsize=1000)) + + +# ~ @pmemcache + +# ~ @pmemdiskcache + +# ~ class ParallelObject(ABC): + # ~ @abc.abstractproperty + # ~ def _comm(self): + # ~ pass + +# ~ class MyObj(ParallelObject): + + # ~ @pcached_property # assumes that obj has a "comm" attr + # ~ @pcached_property(lambda self: self.comm) + # ~ def myproperty(self): + # ~ ... + + +# ~ def pcached_property(): + # ~ def wrapper(self): + # ~ assert isinstance(self, ParallelObject) + # ~ ... + + +# ~ from futils.mpi import ParallelObject + +# ~ from futils.cache import pcached_property + +# ~ from footils.cache import * + +# footils == firedrake utils + +# * parallel cached property +# * memcache / cache / cached +# * diskonlycache / disk_only_cached +# * memdiskcache / diskcache / disk_cached +# * memcache_no_bcast / broadcast=False + +# ~ parallel_cached_property = parallel_cache(lambda self: self._comm, key=lambda self: ()) + +# ~ @time +# ~ @timed +# ~ def myslowfunc(): + # ~ .. + +# ~ my_fast_fun = cache(my_slow_fn) + +#### + + +# TODO: +# Implement an @parallel_cached_property decorator function + + def parallel_memory_only_cache(key=default_parallel_hashkey): """Memory only cache decorator. diff --git a/pyop2/global_kernel.py b/pyop2/global_kernel.py index 4ffee512d..454ca414f 100644 --- a/pyop2/global_kernel.py +++ b/pyop2/global_kernel.py @@ -354,6 +354,7 @@ def builder(self): builder.add_argument(arg) return builder + # TODO: Wrap with parallel_cached_property @cached_property def code_to_compile(self): """Return the C/C++ source code as a string."""