Skip to content

Commit

Permalink
Just notes
Browse files Browse the repository at this point in the history
  • Loading branch information
JDBetteridge committed Aug 13, 2024
1 parent 597563b commit 50ebec1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
74 changes: 74 additions & 0 deletions pyop2/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pyop2/global_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 50ebec1

Please sign in to comment.