Comments (8)
How do we know the LRU cache is big enough?
from ufl.
How do we know the LRU cache is big enough?
Good question. We should probably use lru_cache(maxsize=None)
(which is what cache
is from Python 3.9 onwards, #272)
from ufl.
Isn't that a memory leak?
from ufl.
I need to read up on lru_cache more. I was trying to avoid writing our own cache decorator but maybe that's unavoidable
from ufl.
I think there is a tough lifetimes issue going on here. UFL needs to hold onto references for the duration of a tree traversal, lest the DAG explode. On the other hand, some UFL objects will be subclassed and carry large amounts of data (Coefficient
and Matrix
) so it's important that stray references to those objects are not retained, otherwise quite bad memory leaks can occur (this is a current pyadjoint issue, BTW). I think that probably means that the caches have to have a life of exactly one tree traversal. I think that would mean still having something like multifunction, but delegating the implementation of the individual cases back to the objects, so that you keep extensibility.
from ufl.
I've added a hastily implemented caching function to #271.
Caching function is in https://github.com/FEniCS/ufl/blob/mscroggs/apply_restrictions/ufl/core/caching.py
Can then be called like this:
ufl/ufl/algorithms/apply_restrictions.py
Lines 37 to 42 in e9efc6c
from ufl.
That's not recursion safe. Imagine someone puts some UFL inside an ExternalOperator, and then takes a derivative. The derivative application method of the external operator might well itself call the derivative application visitor.
Another issue with this approach is that it assumes that we know in advance what the full set of DAG visitors is, because if someone wants to do something to a UFL expression that we didn't think of, they will have to go through and subclass every single UFL type to add the new method.
A further issue is that it's not at all clear how you specify traversal orders other than post-order.
I think that the right way to do this is till to have a dedicated tree visitor (i.e. a multifunction but without using the UFL type system). @wence- described how to do this well in #35. Note that this is completely compatible with having a lot of visitors built in to UFL expression as methods. That bit of this proposal isn't the issue.
from ufl.
#274 is an updated version of my PR that uses class methods with a copy of the old traversal methods
from ufl.
Related Issues (20)
- Update tests to not use legacy features
- Fix warnings when building documentation
- Add typing and enable mypy checks
- Set tsfc branch to master
- Remove elements in ufl.legacy
- I/O of `ufl` forms HOT 2
- ufl.constantvalue.as_ufl should use the numbers hierarchy HOT 1
- Move CI tests from pydocstyle to ruff
- Update docstrings including bullet points
- manpages provided but no utility scripts
- ConstantValue and Parameter HOT 3
- Form should have a quadrature rule
- Use `cache` instead of `lru_cache` once minimum python version is >=3.9 HOT 1
- Add Numpy-like functions HOT 1
- extract_domains does the wrong thing with interpolate.
- `ufl.extract_blocks` is broken for `MixedElement` HOT 9
- Tab completion is not working with the default python interpreter
- ufl.TrialFunction uses deprecated method
- Remove quadrature schemes from metadata
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ufl.