Skip to content

Commit 55395df

Browse files
authored
Merge pull request #39 from finsberg/codspeed
Run problem 1,2 and 3 as benchmark to monitor performance
2 parents f951168 + 29461b1 commit 55395df

File tree

5 files changed

+132
-2
lines changed

5 files changed

+132
-2
lines changed

.cspell_dict.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ deviatoric
1111
dirichletbc
1212
dofs
1313
dolfinx
14+
endo
1415
fenics
1516
fenicsx
1617
fenicsx_pulse
1718
ffun
1819
finsberg
1920
functionspace
21+
geodir
2022
gradu
2123
Guccione
2224
Holzapfel

.github/workflows/codspeed.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: codspeed-benchmarks
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
9+
jobs:
10+
benchmarks:
11+
runs-on: ubuntu-22.04
12+
container:
13+
image: ghcr.io/fenics/dolfinx/dolfinx:v0.8.0
14+
options: --privileged
15+
env:
16+
DEB_PYTHON_INSTALL_LAYOUT: deb_system
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Install package needed by codspeed
22+
run: apt-get update && apt-get install -y curl lsb-release
23+
24+
- name: Install package
25+
run: python3 -m pip install -e .[benchmark]
26+
27+
- name : Install codspeed
28+
run: curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v2.4.2/codspeed-runner-installer.sh | bash -s
29+
30+
- name: Fix git owner
31+
run: git config --global --add safe.directory "*"
32+
33+
- name: Run benchmarks
34+
run: |
35+
$HOME/.cargo/bin/codspeed-runner --token ${{ secrets.CODSPEED_TOKEN }} "python3 -m pytest tests/ --codspeed"

.github/workflows/test_package_coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: python3 -m pip install .[test]
2121

2222
- name: Run tests
23-
run: python3 -m pytest -v
23+
run: python3 -m pytest -m "not benchmark"
2424

2525
- name: Extract Coverage
2626
run: |

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ docs = [
3333
"trame-vuetify",
3434
"ipywidgets",
3535
]
36+
benchmark = [
37+
"pytest-codspeed",
38+
"fenicsx_pulse[test]",
39+
]
3640

3741
all = [
3842
"fenicsx_pulse[test]",
@@ -46,7 +50,7 @@ addopts = [
4650
"--cov-report=html",
4751
"--cov-report=xml",
4852
"--cov-report=term-missing",
49-
"-v"
53+
"-v",
5054
]
5155
testpaths = [
5256
"tests"

tests/test_benchmarks.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
from mpi4py import MPI
2+
3+
import dolfinx
4+
import fenicsx_pulse
5+
import numpy as np
6+
import pytest
7+
from dolfinx import log
8+
9+
10+
@pytest.mark.benchmark
11+
def test_problem1():
12+
L = 10.0
13+
W = 1.0
14+
mesh = dolfinx.mesh.create_box(
15+
MPI.COMM_WORLD,
16+
[[0.0, 0.0, 0.0], [L, W, W]],
17+
[30, 3, 3],
18+
dolfinx.mesh.CellType.hexahedron,
19+
)
20+
21+
left = 1
22+
bottom = 2
23+
boundaries = [
24+
fenicsx_pulse.Marker(
25+
name="left",
26+
marker=left,
27+
dim=2,
28+
locator=lambda x: np.isclose(x[0], 0),
29+
),
30+
fenicsx_pulse.Marker(
31+
name="bottom",
32+
marker=bottom,
33+
dim=2,
34+
locator=lambda x: np.isclose(x[2], 0),
35+
),
36+
]
37+
38+
geo = fenicsx_pulse.Geometry(
39+
mesh=mesh,
40+
boundaries=boundaries,
41+
metadata={"quadrature_degree": 4},
42+
)
43+
44+
material_params = {
45+
"C": dolfinx.fem.Constant(mesh, dolfinx.default_scalar_type(2.0)),
46+
"bf": dolfinx.fem.Constant(mesh, dolfinx.default_scalar_type(8.0)),
47+
"bt": dolfinx.fem.Constant(mesh, dolfinx.default_scalar_type(2.0)),
48+
"bfs": dolfinx.fem.Constant(mesh, dolfinx.default_scalar_type(4.0)),
49+
}
50+
f0 = dolfinx.fem.Constant(mesh, dolfinx.default_scalar_type((1.0, 0.0, 0.0)))
51+
s0 = dolfinx.fem.Constant(mesh, dolfinx.default_scalar_type((0.0, 1.0, 0.0)))
52+
n0 = dolfinx.fem.Constant(mesh, dolfinx.default_scalar_type((0.0, 0.0, 1.0)))
53+
material = fenicsx_pulse.Guccione(f0=f0, s0=s0, n0=n0, **material_params)
54+
55+
active_model = fenicsx_pulse.active_model.Passive()
56+
comp_model = fenicsx_pulse.Incompressible()
57+
58+
model = fenicsx_pulse.CardiacModel(
59+
material=material,
60+
active=active_model,
61+
compressibility=comp_model,
62+
)
63+
64+
def dirichlet_bc(
65+
state_space: dolfinx.fem.FunctionSpace,
66+
) -> list[dolfinx.fem.bcs.DirichletBC]:
67+
V, _ = state_space.sub(0).collapse()
68+
facets = geo.facet_tags.find(left) # Specify the marker used on the boundary
69+
mesh.topology.create_connectivity(mesh.topology.dim - 1, mesh.topology.dim)
70+
dofs = dolfinx.fem.locate_dofs_topological((state_space.sub(0), V), 2, facets)
71+
u_fixed = dolfinx.fem.Function(V)
72+
u_fixed.x.array[:] = 0.0
73+
return [dolfinx.fem.dirichletbc(u_fixed, dofs, state_space.sub(0))]
74+
75+
traction = dolfinx.fem.Constant(mesh, dolfinx.default_scalar_type(0.0))
76+
neumann = fenicsx_pulse.NeumannBC(traction=traction, marker=bottom)
77+
bcs = fenicsx_pulse.BoundaryConditions(dirichlet=(dirichlet_bc,), neumann=(neumann,))
78+
problem = fenicsx_pulse.MechanicsProblemMixed(model=model, geometry=geo, bcs=bcs)
79+
80+
log.set_log_level(log.LogLevel.INFO)
81+
82+
for t in [0.0, 0.001, 0.002, 0.003, 0.004]:
83+
print(f"Solving problem for traction={t}")
84+
traction.value = t
85+
problem.solve()
86+
87+
# Now let us turn off the logging again
88+
89+
log.set_log_level(log.LogLevel.WARNING)

0 commit comments

Comments
 (0)