Skip to content

Commit

Permalink
Merge pull request schism-dev#2 from platipodium/lru_cache
Browse files Browse the repository at this point in the history
Fix maxsisze argument to @lru_cache
  • Loading branch information
jreniel authored Mar 4, 2020
2 parents 24777c5 + fed189d commit a54638e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
18 changes: 9 additions & 9 deletions pyschism/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def main(self):
return self.driver.run()

@property
@lru_cache
@lru_cache(maxsize=None)
def driver(self):
return SchismRun(self.mesh, self.param)

@property
@lru_cache
@lru_cache(maxsize=None)
def mesh(self):
return Mesh.open(
self.hgrid,
Expand All @@ -35,13 +35,13 @@ def mesh(self):
)

@property
@lru_cache
@lru_cache(maxsize=None)
def hgrid(self):
return pathlib.Path(
os.path.expandvars(self.mesh_opts["hgrid"])).resolve()

@property
@lru_cache
@lru_cache(maxsize=None)
def vgrid(self):
vgrid = self.mesh_opts.get("vgrid", None)
if vgrid is not None:
Expand All @@ -56,7 +56,7 @@ def fgrid(self):
return fgrid

@property
@lru_cache
@lru_cache(maxsize=None)
def mesh_crs(self):
crs = self.mesh_opts.get('crs', None)
if crs is None:
Expand All @@ -65,15 +65,15 @@ def mesh_crs(self):
return crs

@property
@lru_cache
@lru_cache(maxsize=None)
def config(self):
src = pathlib.Path(self.args.config_file).resolve()
with open(src, 'r') as json_file:
config = json.load(json_file)
return config

@property
@lru_cache
@lru_cache(maxsize=None)
def mesh_opts(self):
return self.config["mesh"]

Expand All @@ -90,7 +90,7 @@ def project_name(self):
return self.meta.get("project_name", False)

@property
@lru_cache
@lru_cache(maxsize=None)
def output_directory(self):
outdir = self.meta.get("output_directory", "'.'")
outdir = pathlib.Path(os.path.expandvars(outdir)).resolve()
Expand All @@ -102,7 +102,7 @@ def server(self):
return self.config.get("server", False)

@property
@lru_cache
@lru_cache(maxsize=None)
def param(self):
param = Param()

Expand Down
10 changes: 5 additions & 5 deletions pyschism/cmd/basecmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _init_output_stations(self, driver):
pass

@property
@lru_cache
@lru_cache(maxsize=None)
def driver(self):
driver = SchismRun(
self.mesh,
Expand Down Expand Up @@ -88,7 +88,7 @@ def mesh(self):
return self._mesh

@property
@lru_cache
@lru_cache(maxsize=None)
def tidal_forcing(self):
tidal_forcing = Tides()
for constituent in self.constituents:
Expand All @@ -109,7 +109,7 @@ def output_directory(self):
return pathlib.Path(self.args.output_directory).absolute()

@property
@lru_cache
@lru_cache(maxsize=None)
def constituents(self):
# might be better to get these from Tides()
_major = ('Q1', 'O1', 'P1', 'K1', 'N2', 'M2', 'S2', 'K2')
Expand All @@ -132,7 +132,7 @@ def constituents(self):
return constituents

@property
@lru_cache
@lru_cache(maxsize=None)
def server_config(self):
if self.args.hostname:
if (not self.args.use_slurm or
Expand Down Expand Up @@ -164,7 +164,7 @@ def _args(self):
return self.__args

@property
@lru_cache
@lru_cache(maxsize=None)
def _mesh(self):
return Mesh.open(
hgrid=self.args.hgrid,
Expand Down
2 changes: 1 addition & 1 deletion pyschism/driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def spinup_time(self):
return self.param.spinup_time

@property
@lru_cache
@lru_cache(maxsize=None)
def bctides(self):
return Bctides(self.mesh)

Expand Down
10 changes: 5 additions & 5 deletions pyschism/driver/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ def write(self, path, overwrite=False):
f90nml.patch(self.src, self._nml, path)

@property
@lru_cache
@lru_cache(maxsize=None)
def core(self):
return CORE(self._nml)

@property
@lru_cache
@lru_cache(maxsize=None)
def opt(self):
return OPT(self._nml)

@property
@lru_cache
@lru_cache(maxsize=None)
def schout(self):
return SCHOUT(self._nml)

@property
@lru_cache
@lru_cache(maxsize=None)
def src(self):
return pathlib.Path(__file__).parent / 'param.nml'

Expand Down Expand Up @@ -149,7 +149,7 @@ def timestep(self, timestep):
self.core.dt = timestep

@property
@lru_cache
@lru_cache(maxsize=None)
def _nml(self):
return f90nml.read(self.src.resolve())

Expand Down
4 changes: 2 additions & 2 deletions pyschism/forcing/tides.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def bctype(self):
return 3

@property
@lru_cache
@lru_cache(maxsize=None)
def tpxo(self):
return TPXO()

Expand Down Expand Up @@ -659,6 +659,6 @@ def spinup_time(self):
pass

@property
@lru_cache
@lru_cache(maxsize=None)
def _active_constituents(self):
return OrderedDict()
42 changes: 21 additions & 21 deletions pyschism/mesh/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def plot_wireframe(self, axes=None, show=False, **kwargs):
return axes

@property
@lru_cache
@lru_cache(maxsize=None)
def coords(self):
return np.array(
[coord for coord in self._coords.values()]
Expand All @@ -215,7 +215,7 @@ def y(self):
return self.coords[:, 1]

@property
@lru_cache
@lru_cache(maxsize=None)
def values(self):
return self._values

Expand All @@ -233,47 +233,47 @@ def quads(self):
return self.quad4

@property
@lru_cache
@lru_cache(maxsize=None)
def nodes(self):
return list(self._nodes.items())

@property
@lru_cache
@lru_cache(maxsize=None)
def elements(self):
return list(self._elements.values())

@property
@lru_cache
@lru_cache(maxsize=None)
def coords_id(self):
return self._coords.keys()

@property
@lru_cache
@lru_cache(maxsize=None)
def triangles_id(self):
return self._triangles.keys()

@property
@lru_cache
@lru_cache(maxsize=None)
def quads_id(self):
return self._quads.keys()

@property
@lru_cache
@lru_cache(maxsize=None)
def node_id(self):
return {index: id for index, id in enumerate(self._coords)}

@property
@lru_cache
@lru_cache(maxsize=None)
def element_id(self):
return {index: id for index, id in enumerate(self._elements)}

@property
@lru_cache
@lru_cache(maxsize=None)
def node_index(self):
return {id: index for index, id in enumerate(self._coords)}

@property
@lru_cache
@lru_cache(maxsize=None)
def element_index(self):
return {id: index for index, id in enumerate(self._elements)}

Expand Down Expand Up @@ -310,21 +310,21 @@ def sms2dm(self):
return sms2dm.string(self._sms2dm)

@property
@lru_cache
@lru_cache(maxsize=None)
def tria3(self):
return np.array(
[list(map(self.get_node_index, index))
for index in self._triangles.values()])

@property
@lru_cache
@lru_cache(maxsize=None)
def quad4(self):
return np.array(
[list(map(self.get_node_index, index))
for index in self._quads.values()])

@property
@lru_cache
@lru_cache(maxsize=None)
def index_ring_collection(self):
# find boundary edges using triangulation neighbors table,
# see: https://stackoverflow.com/a/23073229/7432462
Expand Down Expand Up @@ -398,23 +398,23 @@ def index_ring_collection(self):
return _index_ring_collection

@property
@lru_cache
@lru_cache(maxsize=None)
def outer_ring_collection(self):
outer_ring_collection = defaultdict()
for key, ring in self.index_ring_collection.items():
outer_ring_collection[key] = ring['exterior']
return outer_ring_collection

@property
@lru_cache
@lru_cache(maxsize=None)
def inner_ring_collection(self):
inner_ring_collection = defaultdict()
for key, rings in self.index_ring_collection.items():
inner_ring_collection[key] = rings['interiors']
return inner_ring_collection

@property
@lru_cache
@lru_cache(maxsize=None)
def logger(self):
return logging.getLogger(__name__ + '.' + self.__class__.__name__)

Expand Down Expand Up @@ -461,13 +461,13 @@ def _description(self):
return self.__description

@property
@lru_cache
@lru_cache(maxsize=None)
def _nodes(self):
return {id: ((x, y), -self.values[i]) for i, (id, (x, y))
in enumerate(self._coords.items())}

@property
@lru_cache
@lru_cache(maxsize=None)
def _elements(self):
elements_id = list()
elements_id.extend(list(self._triangles.keys()))
Expand All @@ -482,7 +482,7 @@ def _elements(self):
return elements

@property
@lru_cache
@lru_cache(maxsize=None)
def _grd(self):
description = self.description
if self.crs is not None:
Expand All @@ -494,7 +494,7 @@ def _grd(self):
}

@property
@lru_cache
@lru_cache(maxsize=None)
def _sms2dm(self):
description = self.description
if self.crs is not None:
Expand Down
2 changes: 1 addition & 1 deletion pyschism/mesh/hgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def boundaries(self):
return self._boundaries

@property
@lru_cache
@lru_cache(maxsize=None)
def logger(self):
return logging.getLogger(__name__ + '.' + self.__class__.__name__)

Expand Down
2 changes: 1 addition & 1 deletion pyschism/mesh/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def open_boundaries(self):
return open_boundaries

@property
@lru_cache
@lru_cache(maxsize=None)
def _open_boundaries(self):
_open_boundaries = self.hgrid.boundaries[None].copy()
for id in _open_boundaries:
Expand Down
2 changes: 1 addition & 1 deletion pyschism/mesh/vgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def is3D(self):
return False

@property
@lru_cache
@lru_cache(maxsize=None)
def boilerplate_2D(self): # TODO: *QUICK HACK*, please fix ASAP.
return """2 !ivcor
2 1 1.e6 !nvrt, kz (# of Z-levels); h_s (transition depth between S and Z)
Expand Down

0 comments on commit a54638e

Please sign in to comment.