PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

Use `@cache` and `@cache_property` from `functools` for memoization

Open valentinsulzer opened this issue 3 years ago • 2 comments

See https://docs.python.org/3/library/functools.html

We are currently doing this manually using try-except blocks with AttributeError (example). Using the decorators from functools would be cleaner

This is different functionality from using @property with a setter and getter - those should not be changed.

valentinsulzer avatar Sep 08 '22 14:09 valentinsulzer

See #2289 for an example of @cached_property

valentinsulzer avatar Sep 08 '22 15:09 valentinsulzer

This isn't available in python 3.7, so we need to wait until we drop support (which should be at latest when it stops being supported on 2023-06-27, see https://www.python.org/downloads/)

valentinsulzer avatar Sep 08 '22 15:09 valentinsulzer

Hi @tinosulzer, I'd be happy to work on this!

agriyakhetarpal avatar Oct 26 '22 09:10 agriyakhetarpal

Great!

valentinsulzer avatar Oct 26 '22 13:10 valentinsulzer

Apologies for the delay(s), I'll be working on this in this week!

agriyakhetarpal avatar Nov 04 '22 06:11 agriyakhetarpal