Skip to content

Commit 499508c

Browse files
Add simple profiling test
1 parent 24721f6 commit 499508c

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

demo/Profiling.ipynb

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"Missing HsMG for fract norm computing\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"from fenics import *\n",
18+
"import matplotlib.pyplot as plt\n",
19+
"import networkx as nx\n",
20+
"import numpy as np\n",
21+
"import imp\n",
22+
"from graphnics import *\n"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": null,
28+
"metadata": {},
29+
"outputs": [
30+
{
31+
"name": "stdout",
32+
"output_type": "stream",
33+
"text": [
34+
"\n",
35+
"0 bifurcations:\n",
36+
"Make graphmesh 0.0039s\n",
37+
"Make model 0.0018s\n",
38+
"*Assemble and convert diag terms in a 0.1045s\n",
39+
"*Assemble and convert off diag terms in a 0.1022s\n",
40+
"*Assemble and convert bifurcation terms in a 0.1000s\n",
41+
"Assemble all 0.0237s\n",
42+
"Convert 0.0030s\n",
43+
"Solve 0.0021s\n",
44+
"\n",
45+
"1 bifurcations:\n",
46+
"Make graphmesh 0.0054s\n",
47+
"Make model 0.0046s\n",
48+
"*Assemble and convert diag terms in a 0.0264s\n",
49+
"*Assemble and convert off diag terms in a 0.0363s\n",
50+
"*Assemble and convert bifurcation terms in a 0.0261s\n",
51+
"Assemble all 0.0489s\n",
52+
"Convert 0.0082s\n",
53+
"Solve 0.0020s\n",
54+
"\n",
55+
"3 bifurcations:\n",
56+
"Make graphmesh 0.0064s\n",
57+
"Make model 0.0078s\n",
58+
"*Assemble and convert diag terms in a 0.0779s\n",
59+
"*Assemble and convert off diag terms in a 0.0947s\n",
60+
"*Assemble and convert bifurcation terms in a 0.0745s\n",
61+
"Assemble all 0.1102s\n",
62+
"Convert 0.0377s\n",
63+
"Solve 0.0032s\n",
64+
"\n",
65+
"9 bifurcations:\n",
66+
"Make graphmesh 0.0138s\n",
67+
"Make model 0.0214s\n",
68+
"*Assemble and convert diag terms in a 0.3460s\n",
69+
"*Assemble and convert off diag terms in a 0.4997s\n",
70+
"*Assemble and convert bifurcation terms in a 0.4385s\n",
71+
"Assemble all 0.3122s\n",
72+
"Convert 0.4137s\n",
73+
"Solve 0.0086s\n",
74+
"\n",
75+
"19 bifurcations:\n",
76+
"Make graphmesh 0.0231s\n",
77+
"Make model 0.0502s\n",
78+
"*Assemble and convert diag terms in a 1.4383s\n"
79+
]
80+
}
81+
],
82+
"source": [
83+
"import time\n",
84+
"\n",
85+
"\n",
86+
"for n_nodes in [2, 3, 5, 11, 21]:\n",
87+
" G = make_line_graph(n_nodes)\n",
88+
" print(f'\\n{G.num_bifurcations} bifurcations:')\n",
89+
"\n",
90+
" start = time.time()\n",
91+
" G = make_line_graph(n_nodes)\n",
92+
" G.make_mesh(n=2)\n",
93+
" elapsed = time.time()-start\n",
94+
" for e in G.edges():\n",
95+
" G.edges()[e]['Res'] = Constant(1)\n",
96+
" G.edges()[e]['Ainv'] = Constant(1)\n",
97+
" \n",
98+
" print(f'Make graphmesh {elapsed:1.4f}s')\n",
99+
" \n",
100+
" \n",
101+
" start = time.time()\n",
102+
" model = NetworkStokes(G)\n",
103+
" elapsed = time.time()-start\n",
104+
" print(f'Make model {elapsed:1.4f}s')\n",
105+
" \n",
106+
" \n",
107+
" start = time.time()\n",
108+
" a = model.diag_a_form_on_edges()\n",
109+
" A, b = map(ii_assemble, (a,L))\n",
110+
" A, b = map(ii_convert, (A,b))\n",
111+
" elapsed = time.time()-start\n",
112+
" print(f'*Assemble and convert diag terms in a {elapsed:1.4f}s')\n",
113+
" \n",
114+
" \n",
115+
" start = time.time()\n",
116+
" a = model.offdiag_a_form_on_edges()\n",
117+
" A, b = map(ii_assemble, (a,L))\n",
118+
" A, b = map(ii_convert, (A,b))\n",
119+
" elapsed = time.time()-start\n",
120+
" print(f'*Assemble and convert off diag terms in a {elapsed:1.4f}s')\n",
121+
" \n",
122+
" \n",
123+
" start = time.time()\n",
124+
" a = model.a_form_on_bifs()\n",
125+
" A, b = map(ii_assemble, (a,L))\n",
126+
" A, b = map(ii_convert, (A,b))\n",
127+
" elapsed = time.time()-start\n",
128+
" print(f'*Assemble and convert bifurcation terms in a {elapsed:1.4f}s')\n",
129+
" \n",
130+
" \n",
131+
" start = time.time()\n",
132+
" a = model.a_form()\n",
133+
" L = model.L_form()\n",
134+
" A, b = map(ii_assemble, (a,L))\n",
135+
" elapsed = time.time()-start\n",
136+
" print(f'Assemble all {elapsed:1.4f}s')\n",
137+
" \n",
138+
" start = time.time()\n",
139+
" A, b = map(ii_convert, (A,b))\n",
140+
" elapsed = time.time()-start\n",
141+
" print(f'Convert {elapsed:1.4f}s')\n",
142+
" \n",
143+
"\n",
144+
" start = time.time()\n",
145+
" qp = ii_Function(model.W)\n",
146+
" solver = LUSolver(A, 'mumps')\n",
147+
" solver.solve(qp.vector(), b)\n",
148+
" elapsed = time.time()-start\n",
149+
" print(f'Solve {elapsed:1.4f}s')"
150+
]
151+
}
152+
],
153+
"metadata": {
154+
"kernelspec": {
155+
"display_name": "Python 3",
156+
"language": "python",
157+
"name": "python3"
158+
},
159+
"language_info": {
160+
"codemirror_mode": {
161+
"name": "ipython",
162+
"version": 3
163+
},
164+
"file_extension": ".py",
165+
"mimetype": "text/x-python",
166+
"name": "python",
167+
"nbconvert_exporter": "python",
168+
"pygments_lexer": "ipython3",
169+
"version": "3.6.9"
170+
},
171+
"vscode": {
172+
"interpreter": {
173+
"hash": "767d51c1340bd893661ea55ea3124f6de3c7a262a8b4abca0554b478b1e2ff90"
174+
}
175+
}
176+
},
177+
"nbformat": 4,
178+
"nbformat_minor": 4
179+
}

0 commit comments

Comments
 (0)