Skip to content

Commit 1e9c6d0

Browse files
authored
Cache Basix element creation (#475)
* revert caching * Add C++ DOLFINx tests to CI * build dir * add a cached create_basix_element function
1 parent e5f26d9 commit 1e9c6d0

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.github/workflows/dolfin-tests.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,14 @@ jobs:
5353
cmake --install build
5454
pip3 -v install --global-option build --global-option --debug dolfinx/python/
5555
56-
- name: Run DOLFINx unit tests
56+
- name: Build DOLFINx C++ unit tests
57+
run: |
58+
cmake -G Ninja -DCMAKE_BUILD_TYPE=Developer -B build/test/ -S build/test/
59+
cmake --build build/test
60+
- name: Run DOLFINx C++ unit tests
61+
run: |
62+
cd build/test
63+
ctest -V --output-on-failure -R unittests
64+
65+
- name: Run DOLFINx Python unit tests
5766
run: python3 -m pytest -n auto dolfinx/python/test/unit

ffcx/element_interface.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
import numpy
2020
import ufl
2121
import basix.ufl_wrapper
22-
# from functools import lru_cache
22+
import functools
23+
24+
25+
@functools.lru_cache
26+
def create_basix_element(family_type, cell_type, degree, variant_info, discontinuous):
27+
"""Create a basix element."""
28+
return basix.create_element(family_type, cell_type, degree, *variant_info, discontinuous)
2329

2430

25-
# @lru_cache
2631
def create_element(element: ufl.finiteelement.FiniteElementBase) -> BaseElement:
2732
"""Create an FFCx element from a UFL element.
2833
@@ -90,8 +95,8 @@ def create_element(element: ufl.finiteelement.FiniteElementBase) -> BaseElement:
9095
else:
9196
variant_info.append(basix.variants.string_to_dpc_variant(element.variant()))
9297

93-
return BasixElement(basix.create_element(
94-
family_type, cell_type, element.degree(), *variant_info, discontinuous))
98+
return BasixElement(create_basix_element(
99+
family_type, cell_type, element.degree(), tuple(variant_info), discontinuous))
95100

96101

97102
def basix_index(*args):

0 commit comments

Comments
 (0)