Skip to content

Commit 3b8ec13

Browse files
committed
examples: Add safemath
1 parent b73d689 commit 3b8ec13

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

examples/userapi/07_functions_on_subdomains.ipynb

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,34 +2887,22 @@
28872887
"name": "stderr",
28882888
"output_type": "stream",
28892889
"text": [
2890-
"Operator `Kernel` ran in 0.68 s\n"
2890+
"Operator `Kernel` ran in 0.74 s\n"
28912891
]
2892-
},
2893-
{
2894-
"data": {
2895-
"text/plain": [
2896-
"PerformanceSummary([(PerfKey(name='section0', rank=None),\n",
2897-
" PerfEntry(time=0.198681000000007, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[])),\n",
2898-
" (PerfKey(name='section1', rank=None),\n",
2899-
" PerfEntry(time=0.19470700000000477, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[])),\n",
2900-
" (PerfKey(name='section2', rank=None),\n",
2901-
" PerfEntry(time=0.14005600000000007, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[])),\n",
2902-
" (PerfKey(name='section3', rank=None),\n",
2903-
" PerfEntry(time=0.1434430000000003, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[]))])"
2904-
]
2905-
},
2906-
"execution_count": 45,
2907-
"metadata": {},
2908-
"output_type": "execute_result"
29092892
}
29102893
],
29112894
"source": [
29122895
"#NBVAL_IGNORE_OUTPUT\n",
2913-
"op1 = Operator([eq_v,\n",
2896+
"from devito import switchconfig\n",
2897+
"\n",
2898+
"# Note: switchconfig(safe_math=True) is only required here to get consistent norms for testing purposes\n",
2899+
"# This is not required more widely and can be omitted in practical applications\n",
2900+
"with switchconfig(safe_math=True):\n",
2901+
" op1 = Operator([eq_v,\n",
29142902
" eq_p, eq_t,\n",
29152903
" eq_p_tr, eq_txx_tr, eq_tyy_tr]\n",
29162904
" + src_term + rec_term)\n",
2917-
"op1(dt=dt)"
2905+
" op1(dt=dt)"
29182906
]
29192907
},
29202908
{
@@ -3013,18 +3001,9 @@
30133001
"execution_count": 48,
30143002
"id": "692979ac-8bbf-4349-8b3f-ab98f11667bc",
30153003
"metadata": {},
3016-
"outputs": [
3017-
{
3018-
"name": "stdout",
3019-
"output_type": "stream",
3020-
"text": [
3021-
"4263.511\n"
3022-
]
3023-
}
3024-
],
3004+
"outputs": [],
30253005
"source": [
3026-
"print(np.linalg.norm(rec.data))\n",
3027-
"# assert np.isclose(np.linalg.norm(rec.data), 4263.511, atol=0, rtol=1e-4)"
3006+
"assert np.isclose(np.linalg.norm(rec.data), 4263.511, atol=0, rtol=1e-4)"
30283007
]
30293008
}
30303009
],

0 commit comments

Comments
 (0)