Commit ebfd56e1 authored by Markus Holzer's avatar Markus Holzer
Browse files

fixed docstring bugs and expm1 optimisation

parent 35c029a0
......@@ -66,6 +66,7 @@ try:
if int(sympy_version[0]) <= 1 and int(sympy_version[1]) <= 4:
def hash_fun(self):
return hash((self.lhs, self.rhs))
Assignment.__hash__ = hash_fun
except Exception:
pass
......@@ -94,16 +95,19 @@ def assignment_from_stencil(stencil_array, input_field, output_field,
... [0, 6, 0]]
By default 'visual ordering is used - i.e. the stencil is applied as the nested lists are written down
>>> assignment_from_stencil(stencil, f, g, order='visual')
Assignment(g_C, 3*f_W + 6*f_S + 4*f_C + 2*f_N + 5*f_E)
>>> expected_output = Assignment(g[0, 0], 3*f[-1, 0] + 6*f[0, -1] + 4*f[0, 0] + 2*f[0, 1] + 5*f[1, 0])
>>> assignment_from_stencil(stencil, f, g, order='visual') == expected_output
True
'numpy' ordering uses the first coordinate of the stencil array for x offset, second for y offset etc.
>>> assignment_from_stencil(stencil, f, g, order='numpy')
Assignment(g_C, 2*f_W + 3*f_S + 4*f_C + 5*f_N + 6*f_E)
>>> expected_output = Assignment(g[0, 0], 2*f[-1, 0] + 3*f[0, -1] + 4*f[0, 0] + 5*f[0, 1] + 6*f[1, 0])
>>> assignment_from_stencil(stencil, f, g, order='numpy') == expected_output
True
You can also pass field accesses to apply the stencil at an already shifted position:
>>> assignment_from_stencil(stencil, f[1, 0], g[2, 0])
Assignment(g_2E, 3*f_C + 6*f_SE + 4*f_E + 2*f_NE + 5*f_2E)
>>> expected_output = Assignment(g[2, 0], 3*f[0, 0] + 6*f[1, -1] + 4*f[1, 0] + 2*f[1, 1] + 5*f[2, 0])
>>> assignment_from_stencil(stencil, f[1, 0], g[2, 0]) == expected_output
True
"""
from pystencils.field import Field
......
import itertools
import warnings
from collections import defaultdict
import numpy as np
......
......@@ -21,10 +21,13 @@ def diffusion(scalar, diffusion_coeff, idx=None):
Examples:
>>> f = Field.create_generic('f', spatial_dimensions=2)
>>> d = sp.Symbol("d")
>>> dx = sp.Symbol("dx")
>>> diffusion_term = diffusion(scalar=f, diffusion_coeff=sp.Symbol("d"))
>>> discretization = Discretization2ndOrder()
>>> discretization(diffusion_term)
(f_W*d + f_S*d - 4*f_C*d + f_N*d + f_E*d)/dx**2
>>> expected_output = ((f[-1, 0] + f[0, -1] - 4*f[0, 0] + f[0, 1] + f[1, 0]) * d) / dx**2
>>> sp.simplify(discretization(diffusion_term) - expected_output)
0
"""
if isinstance(scalar, Field):
first_arg = scalar.center
......@@ -313,8 +316,9 @@ def discretize_center(term, symbols_to_field_dict, dx, dim=3):
>>> term
x*x^Delta^0
>>> f = Field.create_generic('f', spatial_dimensions=3)
>>> discretize_center(term, { x: f }, dx=1, dim=3)
f_C*(-f_W/2 + f_E/2)
>>> expected_output = f[0, 0, 0] * (-f[-1, 0, 0]/2 + f[1, 0, 0]/2)
>>> sp.simplify(discretize_center(term, { x: f }, dx=1, dim=3) - expected_output)
0
"""
substitutions = {}
for symbols, field in symbols_to_field_dict.items():
......@@ -396,8 +400,10 @@ def discretize_divergence(vector_term, symbols_to_field_dict, dx):
>>> x, dx = sp.symbols("x dx")
>>> grad_x = grad(x, dim=3)
>>> f = Field.create_generic('f', spatial_dimensions=3)
>>> sp.simplify(discretize_divergence(grad_x, {x : f}, dx))
(f_W + f_S + f_B - 6*f_C + f_T + f_N + f_E)/dx**2
>>> expected_output = (f[-1, 0, 0] + f[0, -1, 0] + f[0, 0, -1] -
... 6*f[0, 0, 0] + f[0, 0, 1] + f[0, 1, 0] + f[1, 0, 0])/dx**2
>>> sp.simplify(discretize_divergence(grad_x, {x : f}, dx) - expected_output)
0
"""
dim = len(vector_term)
result = 0
......
......@@ -61,7 +61,7 @@
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAABLCAYAAABz5qkHAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFRElEQVR4Ae1dUW7UMBDdRXyj0kqI7+0NlvYElBuUI5TegIoj0BtQToDaI7QngO4Nyj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4t/OOKeuXEZEt1RIfg2p6j6fP2Bo2j/bq/u3qe1ifItCQpf1K4ptry0b63Kotz4U36KQIA9XYxn8mTnLzf62gQvraaUH4VsKJC+w71E+H8bbYSZDumjfUiC19RZ/JtubIxfPTDHdopAw7vthzgMJ3fFnsPoDHWGjPj0U36KQnCDFv53RgxeORXRLhVT82xmF4XhzIrolQcKwYm+O9LJ3iKV06zLByufX7M2RHSC5qivrlgzJXaR7+Xue0n1LGu66nzz2CUkFDJKkmkq2DJKSsJJmDZKkmkq2DJKSsJJmw7u7O9wlVW3bPwOuKqKQh+6N/wyYzRES592abq0nrGRBXQE+4OPnQRca+weeGBF+hDwvIgAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}0 & 0 & 0\\\\1 & -2 & 1\\\\0 & 0 & 0\\end{matrix}\\right]$"
],
......@@ -123,7 +123,7 @@
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAIIAAABNCAYAAABqvbycAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAH5ElEQVR4Ae2dT47kNBTGq0esUYsFQiyrN6x7NCeguUHPcAJmbtAtViwQGvXcoAchViygkThA96xYDswNZtiwQEjQrVkhsSh+X8oOSSpV5YrtxEnZ0qvYjmO/973n/3FltlgsZr40m82OoWvffFJ8PlXZQvP1Dhl2dgcHBzKAJyaDeeeMEnwwVdli8iVlLtbQlUst5dkT6LVL2rGlSVW2XfmSfqBWPUsn1RbhuUnMpXRvSl/2jB2BCwQ4bAjxgPCp4qqGcIFlZMU3kJpKEN2qotcc3YyMoDCEe7U7ObC3CGRD2FvV1wXPhlDHY29D2RD2VvV1wUMZQnM0Wi9l3KFUZQvKl5chMOqcQ5foWVMT+a+gs3Hrfcl9qrLF4usAsbWg9Ct0lKePSyPYl1+MSlNHLRoeeLUI+wLYPsiZDWEftOwgY3VlcWNymhGtU3s5NUFeGWx5GB41gHqxJVnz9mfw9aoa6SJrbFnEjwsfVb7b/K58O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Mw8SHipGNNQRGwZ8UYlIQzF0NAbCgHxU+VGAkSMGzFhvOdKQWflZ4o/CRAkZwEyNRHJOCYO5kCAKFYeqO4oVi3qVrz71jAubUt2R5qgaeWrIlcWxP/ATBfLSz6IRyqZwcAsUQklNJHIaKIcTBPbleiyEkp5I4DBVDiIN7cr0WQ0hOJXEY8mUIrMTtKqUqm1e+XNcR5tI+K12sI5R/cJngVtA6QhDMXQ2BlcSdWUSy9SjAk5QtFF++Hg02hiWdIQLFEDJUWgiWez8aNCRtPdCyjUG1EfTAi9rHgdqZAy5TYj7EEIIqcZsR9flewF3oup054BL6xrEx7W0IdiUxWO3RK175rSSVsXfPnYl3i8OV3Y9yi+cl1fKQ56BLtMM7oTEfZAg1M2aWgKIbVIPGdjQGMFPMyxwM1c53Ke1NTeKfswwYcvkHFxt8ATLJv4nYfcZKS9YkDu9MhfmgEaGnUswjgct5ZkN22VVJ+p9BDpIEEtvGdxTmXg1B1msfEUNmfAkoxx/Xws+Z1SMDySQP7/jC3KshgFaLcByzcxYFrvF/cjy8Mwrz/ZbivGUFJgyVf3Dxhuj2hlwwD2IIYqj8g8t2vXm9whVz74YghhaSkONh1TSTvILxFbwKH7gx3haed/RRTY07yqMV+cDc9hH4UYi2MKcq63qNu3Kk2hfXCueRwIFRczQMg+hqo109tXx1kERM8QOXs1qemId3nDAX//yCfpdhI94MQ6hW/6rc6gd3xZLUGA1tev+AxSMYbvyyiOpdLBvJJCGe8W8OFDi9Bf/INfnhHfXvC3NuUGTopP8B4bgV5RaoCpcAAAAASUVORK5CYII=\n",
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\frac{1}{12} & - \\frac{1}{6} & \\frac{1}{12}\\\\\\frac{5}{6} & - \\frac{5}{3} & \\frac{5}{6}\\\\\\frac{1}{12} & - \\frac{1}{6} & \\frac{1}{12}\\end{matrix}\\right]$"
],
......@@ -173,48 +173,8 @@
"metadata": {},
"outputs": [],
"source": [
"expected_result = sp.Matrix([[1, -2, 1], [10, -20, 10], [1, -2, 1]]) / 12\n",
"assert expected_result[:] == isotropic_2d_00_res.as_array()[:]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"sympy.tensor.array.dense_ndim_array.MutableDenseNDimArray"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(isotropic_2d_00_res.as_array())"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"sympy.matrices.dense.MutableDenseMatrix"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(expected_result)"
"expected_result = sp.Array([[1, -2, 1], [10, -20, 10], [1, -2, 1]]) / 12\n",
"assert expected_result == isotropic_2d_00_res.as_array()"
]
},
{
......@@ -226,12 +186,12 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAHoAAABNCAYAAABpJnDxAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAINklEQVR4Ae2dvY4cRRSFdy3HaDESIiCaJSBey0/g5Q0WExBjvwEWEaG15gkWiYAUWyIh8/IExg7IcYyQzFqIgGz5Tk9Vq7qnd6aqu3r61kxf6U7/d997Tv3X7Z7D6+vrg1Q5PDw84Zpzrv0s9dopz8fuc55/hC7QN+hjfHjH0rwMxfx2iofuYY/cNQKrGHEkX0CsCD5g+xmLX9G72rYqOTFX7lS27tJnyvFt5dxT9I/2fsvbshddeBtZ937X+/wxi0vsXYu586+LQ9y5Pghz9PfuZBa1VKm/3ip/xRfZ8sQX2eG+kj301VLowz02zrQjJFp17q4RWzuNb8f1xnJFOVry23JR9i/+KaM2hGJfJFdE32oc2a8N5YBiGmNDqdlLol3D7JJc8HQogKVcv3dEQ/JDyDmCZN97KIWrQXbuFdGQrJbrsSdZ26ivqwcBaf3ivkRr0KEocYSqXn7J+pmU9cdoKQ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M9UYZHIpRhjnsneGvB82pbV702JbokJ3gT1wLUpW1d9dqI6Ag5hlqHUoLVnbGJV9s20iu5jxaZ9MmlOsGvLIRebcupl4XoxgleCoQ1Unydma36aSWSTi5Kb2oDBXaqwApW5e+m841tOhfkUIlBbYv16op5MtG19V8r/lnhP4WPFADiFgopdi3SEZJXfYE/OPhXOzN0L4XBg21ZMDcRLbAey/jHiintgDbUYryyNwvvEczsBTlRotl8IFtY+GgWP8JNQ8e5MO/6MjY0Dtb8qaVBQisUnwvXRhebanTJ1qtmxNOImMJ7BjKIw98s6/5+t61Gx8jSZ49180FsZ5XeSqJVuyF5zJsPdkSL5DFvPrhEcDixVTVaJDNaGO3mg0BqW7zpy9h+2595PieSwyRPqZsPOmFuIlpgMRRZ6vjumWjplsURvm8bc2FuJXqt43vfQKTmJ8CK3HwgvbNgvlV9dGqhGON9O6LHyGqLTclNt5qQwR34W/RPOlWq7jn1thDdy+6EJOaMNwmwInXPqXcy0TG2UoCZJYQlPdZyL32Qrbrq7KfWu8jNB10xN/fRyhBf7t0X+HssxDkwNxGtDPH+3H2Bv1+Ss2Bubbr5rOLuC/w9Eq2ssmBuJbqahqtrNuayxlvcUp/0x45SNh9kwTyZaIEzhVnJ7gv8Mxyu/Dcn5pY++k1tWfPVeinCvqvdF/ivjvJsmCcTLVLPVtgTavuKW9xdYojoevNBTsyTm+6aJrwk20hl4t2tCDD6uVI3H2TBPCaaDe6LZPERtdillyVKQjVBomu40L5U7HrrrPRz6aC/CPaS4yTMZeOpnm+rhNXfQnS1Y2FJJpSmRiBUYV8B/2iacmpKKdtmvTroN/i2JQyY0xXBR6v8D0vOpx54AZn/AAAAAElFTkSuQmCC\n",
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\frac{1}{6} & \\frac{2}{3} & \\frac{1}{6}\\\\\\frac{2}{3} & - \\frac{10}{3} & \\frac{2}{3}\\\\\\frac{1}{6} & \\frac{2}{3} & \\frac{1}{6}\\end{matrix}\\right]$"
],
......@@ -243,7 +203,7 @@
"⎣1/6 2/3 1/6⎦"
]
},
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
......@@ -257,12 +217,12 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"expected_result = sp.Matrix([[1, 4, 1], [4, -20, 4], [1, 4, 1]]) / 6\n",
"assert iso_laplacian[:] == expected_result[:]"
"expected_result = sp.Array([[1, 4, 1], [4, -20, 4], [1, 4, 1]]) / 6\n",
"assert iso_laplacian == expected_result"
]
},
{
......@@ -274,7 +234,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
......@@ -315,7 +275,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
......@@ -345,7 +305,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 13,
"metadata": {},
"outputs": [
{
......@@ -369,7 +329,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 14,
"metadata": {
"pycharm": {
"name": "#%%\n"
......@@ -405,4 +365,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
\ No newline at end of file
}
......@@ -11,8 +11,11 @@ def test_sympy_optimizations():
x, y, z = pystencils.fields('x, y, z: float32[2d]')
# Triggers Sympy's expm1 optimization
# Sympy's expm1 optimization is tedious to use and the behaviour is highly depended on the sympy version. In
# some cases the exp expression has to be encapsulated in brackets or multiplied with 1 or 1.0
# for sympy to work properly ...
assignments = pystencils.AssignmentCollection({
x[0, 0]: sp.exp(y[0, 0]) - 1
x[0, 0]: 1.0 * (sp.exp(y[0, 0]) - 1)
})
assignments = optimize_assignments(assignments, optims_pystencils_cpu)
......@@ -28,7 +31,7 @@ def test_evaluate_constant_terms():
for target in ('cpu', 'gpu'):
x, y, z = pystencils.fields('x, y, z: float32[2d]')
# Triggers Sympy's expm1 optimization
# Triggers Sympy's cos optimization
assignments = pystencils.AssignmentCollection({
x[0, 0]: -sp.cos(1) + y[0, 0]
})
......@@ -53,8 +56,6 @@ def test_do_not_evaluate_constant_terms():
x[0, 0]: -sp.cos(1) + y[0, 0]
})
optimize_assignments(assignments, optimizations)
ast = pystencils.create_kernel(assignments, target=target)
code = pystencils.get_code_str(ast)
assert 'cos(' in code
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment