Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array context #16

Closed
wants to merge 87 commits into from
Closed
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
5915199
Initial, incomplete adaptation to meshmode's ArrayContext
inducer Jun 15, 2020
66fc944
Improve ArrayContext processing in BoundOperator.{__call__,eval}
inducer Jun 17, 2020
3dbc2c8
Track introduction of ArrayContext.np
inducer Jun 17, 2020
f0e5c54
symbolic.primitives: Fix the dimension check for a few 3D-surface-only
mattwala Jun 30, 2020
5cc8cf5
Merge branch 'master' of https://github.com/inducer/pytential into fi…
mattwala Jun 30, 2020
86934b7
Merge branch 'fix-surface-check' into 'master'
inducer Jul 1, 2020
273ba51
CI: Disable tests, only keep examples for now
mattwala Jul 2, 2020
cf635e0
Update requirements.txt
mattwala Jul 2, 2020
459ec80
Port over examples
mattwala Jul 2, 2020
1306729
Relax sumpy version
mattwala Jul 2, 2020
c738c07
Add utils.py
mattwala Jul 2, 2020
c1678d1
pylint fixes
mattwala Jul 2, 2020
657c35f
flake8 fixes
mattwala Jul 2, 2020
51fa634
requirements.txt: Point to revert-cffi-go-to-pybind branch of islpy
mattwala Jul 2, 2020
8a70c0d
Port over some tests
mattwala Jul 2, 2020
54a125a
flake8 fix
mattwala Jul 2, 2020
36919c9
Improve test specificity
mattwala Jul 2, 2020
c1df687
Merge branch 'master' into array-context
mattwala Jul 2, 2020
16864ec
Port test_symbolic.py
mattwala Jul 2, 2020
fddc8c4
Mark test_muller.py as OK
mattwala Jul 2, 2020
473de87
formatting
mattwala Jul 2, 2020
bb6d56e
Port test_global_qbx.py
mattwala Jul 2, 2020
a7d8282
Misc fixes for test_global_qbx
mattwala Jul 2, 2020
55a2b36
Port test_layer_pot_eigenvalues.py
mattwala Jul 2, 2020
ce86dc6
Point requirements.txt to sumpy master
mattwala Jul 2, 2020
b32792e
Fixes for test_layer_pot_eigenvalues
mattwala Jul 2, 2020
72a09b0
Port test_layer_pot_identity
mattwala Jul 2, 2020
7ce0165
Actually run the tests in test_layer_pot_identity.py
mattwala Jul 2, 2020
25582e5
Port test_layer_pot.py
mattwala Jul 2, 2020
01872e9
port test_matrix to array-context
alexfikl Jul 3, 2020
c3077e9
Port test_scalar_int_eq.py
mattwala Jul 3, 2020
80ab289
port test_linalg_proxy to array-context
alexfikl Jul 3, 2020
87df581
flake8 fixes
mattwala Jul 3, 2020
9b4ce76
Thaw failed_target_flags after QBXTargetAssociationFailedException
mattwala Jul 3, 2020
fee617b
Port test_maxwell.py
mattwala Jul 3, 2020
21d641d
Add test_maxwell.py to setup.cfg tests
mattwala Jul 3, 2020
d4a8585
port test_stokes to array-context
alexfikl Jul 3, 2020
16b103d
enable tests in setup.cfg
alexfikl Jul 3, 2020
d790dfe
Merge branch 'array-context' into array-context-tests
alexfikl Jul 3, 2020
213ee64
Allow tests marked as slowtest to run
mattwala Jul 3, 2020
b57224c
Fix yaml syntax
mattwala Jul 3, 2020
58d21fc
Merge branch 'array-context' into array-context-tests
alexfikl Jul 3, 2020
030c7c0
Document default_vdot()
mattwala Jul 3, 2020
af7ff8c
Improve the documentation in MatVecOp
mattwala Jul 3, 2020
0760994
Remove unneeded FIXME
mattwala Jul 3, 2020
37e9404
remove stray debugging remnants
alexfikl Jul 3, 2020
b5f1e9d
Remove another FIXME
mattwala Jul 3, 2020
740cd15
Apply 1 suggestion(s) to 1 file(s)
Jul 3, 2020
67b1228
Apply 1 suggestion(s) to 1 file(s)
Jul 3, 2020
c09cfb9
Apply 1 suggestion(s) to 1 file(s)
Jul 3, 2020
94a220d
switch argument order in unflatten_to_numpy
alexfikl Jul 3, 2020
6b50ccf
Address more FIXMEs
mattwala Jul 4, 2020
9303cc2
Remove FIXME
mattwala Jul 4, 2020
b51f070
Address another FIXME
mattwala Jul 4, 2020
087411c
Merge branch 'array-context' into 'array-context-tests'
mattwala Jul 4, 2020
d476b09
flake8 fix
mattwala Jul 4, 2020
c28247b
Merge branch 'array-context' into HEAD
mattwala Jul 4, 2020
56373b8
Apply 1 suggestion(s) to 1 file(s)
Jul 4, 2020
27c7922
Apply 1 suggestion(s) to 1 file(s)
Jul 4, 2020
fb062bb
remove partition_by_coarse
alexfikl Jul 4, 2020
58d0dfa
[ci skip] Rename default_vdot to structured_vdot
mattwala Jul 4, 2020
61b6220
Merge branch 'array-context-tests' into 'array-context'
mattwala Jul 4, 2020
ef9c1c4
Undo setup.cfg changes
mattwala Jul 4, 2020
c296c6d
Tweak setup.cfg
mattwala Jul 4, 2020
459f2f1
Undo changes to .gitlab-ci.yml
mattwala Jul 4, 2020
e08ec0e
Re-dangle Conda requirements files
mattwala Jul 4, 2020
15b7c8d
Fix CI failures on master due to recent Sumpy P2P API changes
mattwala Jul 5, 2020
10d1ed7
Merge branch 'track-sumpy-changes' into 'master'
mattwala Jul 5, 2020
3440900
Merge branch 'master' into array-context
mattwala Jul 5, 2020
a2a7273
Tweak comments in examples
mattwala Jul 6, 2020
0a298d9
Fix getting host array
mattwala Jul 6, 2020
db0a8c2
Fix naming to QBXFMMGeometryDataCodeContainer
mattwala Jul 6, 2020
f1d7193
Rename _FMMGeometryCodeContainer to _FMMGeometryDataCodeContainer
mattwala Jul 6, 2020
f1281a0
Update pytential/symbolic/execution.py
mattwala Jul 6, 2020
bdb3cf2
Remove too_slow_test_helmholtz.py
mattwala Jul 6, 2020
10c3787
Make an interleave_dof_arrays underscored method
mattwala Jul 6, 2020
ec9bdb1
Merge branch 'array-context' of https://github.com/inducer/pytential …
mattwala Jul 6, 2020
499ffc3
Delete DielectricSRep2DBoundaryOperator and DielectricSDRep2DBoundary…
mattwala Jul 8, 2020
90056c1
Move flatten() import to top of file, and don't use a separate
mattwala Jul 10, 2020
0c63898
pytential.source: Introduce _SumpyP2PMixin
mattwala Jul 10, 2020
a86f7a9
Fix incorrect parentheses placement
mattwala Jul 10, 2020
0f6471b
Re-dangle islpy back to master
inducer Jul 11, 2020
2fc4fb1
Move Apple CI to Github
inducer Jul 11, 2020
5fe6d92
Merge remote-tracking branch 'gitlab/array-context' into array-context
inducer Jul 11, 2020
ba588a6
Try mac CI with normal conda env without mac workarounds
inducer Jul 11, 2020
753a54a
mac CI: Try and install compiler from conda
inducer Jul 11, 2020
4e7f2db
Apply suggestions from @isuruf to fix Github Mac CI
inducer Jul 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
-
uses: actions/setup-python@v1
with:
python-version: '3.x'
python-version: '3.x'
- name: "Main Script"
run: |
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-flake8.sh
Expand All @@ -32,7 +32,7 @@ jobs:
-
uses: actions/setup-python@v1
with:
python-version: '3.x'
python-version: '3.x'
- name: "Main Script"
run: |
set -e
Expand All @@ -51,18 +51,35 @@ jobs:
. ./prepare-and-run-pylint.sh pytential test/test_*.py

pytest3:
name: Pytest on Py3
name: Pytest Linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Main Script"
run: |
set -e
grep -v symengine .test-conda-env-py3.yml > .test-conda-env.yml
CONDA_ENVIRONMENT=.test-conda-env.yml
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh
. ./build-and-test-py-project-within-miniconda.sh

pytest3mac:
name: Pytest Mac
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: "Main Script"
run: |
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
grep -v symengine .test-conda-env-py3.yml > .test-conda-env.yml
echo "- compiler" >> .test-conda-env.yml
inducer marked this conversation as resolved.
Show resolved Hide resolved
echo "- openmp" >> .test-conda-env.yml
inducer marked this conversation as resolved.
Show resolved Hide resolved
CONDA_ENVIRONMENT=.test-conda-env.yml
export PYTEST_ADDOPTS=${PYTEST_ADDOPTS:--k-slowtest}
set -o xtrace
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh
. ./build-and-test-py-project-within-miniconda.sh

pytest3symengine:
name: Pytest on Py3 with SymEngine
runs-on: ubuntu-latest
Expand Down
23 changes: 0 additions & 23 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,6 @@ Python 3 Conda:
reports:
junit: test/pytest.xml

Python 3 Conda Apple:
script:
- export LC_ALL=en_US.UTF-8
- export LANG=en_US.UTF-8
- export CONDA_ENVIRONMENT=.test-conda-env-py3-macos.yml
- export PYTEST_ADDOPTS=${PYTEST_ADDOPTS:--k-slowtest}
- export CC=clang
# https://stackoverflow.com/q/60934005; https://reviews.llvm.org/D71579
- export LDFLAGS="-mlinker-version=519"
- set -o xtrace
- curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh
- ". ./build-and-test-py-project-within-miniconda.sh"

tags:
- apple
except:
- tags
retry: 2

artifacts:
reports:
junit: test/pytest.xml

Documentation:
script:
- EXTRA_INSTALL="Cython pybind11 numpy mako"
Expand Down
30 changes: 0 additions & 30 deletions .test-conda-env-py3-macos.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .test-conda-env-py3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ dependencies:
- git+https://github.com/inducer/pymbolic
- git+https://github.com/inducer/loopy
- git+https://gitlab.tiker.net/inducer/sumpy
- git+https://github.com/inducer/meshmode
- git+https://gitlab.tiker.net/inducer/meshmode@array-context
45 changes: 25 additions & 20 deletions examples/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pyopencl as cl
import numpy as np
from meshmode.array_context import PyOpenCLArrayContext
from meshmode.dof_array import thaw

from pytential import sym, bind
from pytools import one
Expand All @@ -26,7 +28,7 @@
TESTING_ARMS = (20,)


def starfish_lpot_source(queue, n_arms):
def starfish_lpot_source(actx, n_arms):
from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
InterpolatoryQuadratureSimplexGroupFactory)
Expand All @@ -39,7 +41,7 @@ def starfish_lpot_source(queue, n_arms):
TARGET_ORDER)

pre_density_discr = Discretization(
queue.context, mesh,
actx, mesh,
InterpolatoryQuadratureSimplexGroupFactory(TARGET_ORDER))

lpot_kwargs = DEFAULT_LPOT_KWARGS.copy()
Expand All @@ -60,14 +62,14 @@ def starfish_lpot_source(queue, n_arms):
# }}}


def training_geometries(queue):
def training_geometries(actx):
for n_arms in TRAINING_ARMS:
yield starfish_lpot_source(queue, n_arms)
yield starfish_lpot_source(actx, n_arms)


def test_geometries(queue):
def test_geometries(actx):
for n_arms in TESTING_ARMS:
yield starfish_lpot_source(queue, n_arms)
yield starfish_lpot_source(actx, n_arms)


def get_bound_op(places):
Expand All @@ -79,40 +81,41 @@ def get_bound_op(places):
return bind(places, op)


def get_test_density(queue, density_discr):
nodes = density_discr.nodes().with_queue(queue)
sigma = cl.clmath.sin(10 * nodes[0])

def get_test_density(actx, density_discr):
nodes = thaw(actx, density_discr.nodes())
sigma = actx.np.sin(10 * nodes[0])
return sigma


def calibrate_cost_model(ctx):
queue = cl.CommandQueue(ctx)
actx = PyOpenCLArrayContext(queue)

from pytential.qbx.cost import CostModel, estimate_calibration_params
cost_model = CostModel()

model_results = []
timing_results = []

for lpot_source in training_geometries(queue):
for lpot_source in training_geometries(actx):
lpot_source = lpot_source.copy(cost_model=cost_model)

from pytential import GeometryCollection
places = GeometryCollection(lpot_source)
density_discr = places.get_discretization(places.auto_source.geometry)

bound_op = get_bound_op(places)
sigma = get_test_density(queue, density_discr)
sigma = get_test_density(actx, density_discr)

cost_S = bound_op.get_modeled_cost(queue, sigma=sigma)
cost_S = bound_op.get_modeled_cost(actx, sigma=sigma)

# Warm-up run.
bound_op.eval(queue, {"sigma": sigma})
bound_op.eval({"sigma": sigma}, array_context=actx)

for _ in range(RUNS):
timing_data = {}
bound_op.eval(queue, {"sigma": sigma}, timing_data=timing_data)
bound_op.eval({"sigma": sigma}, array_context=actx,
timing_data=timing_data)

model_results.append(one(cost_S.values()))
timing_results.append(one(timing_data.values()))
Expand All @@ -125,29 +128,31 @@ def calibrate_cost_model(ctx):

def test_cost_model(ctx, cost_model):
queue = cl.CommandQueue(ctx)
actx = PyOpenCLArrayContext(queue)

for lpot_source in test_geometries(queue):
for lpot_source in test_geometries(actx):
lpot_source = lpot_source.copy(cost_model=cost_model)

from pytential import GeometryCollection
places = GeometryCollection(lpot_source)
density_discr = places.get_discretization(places.auto_source.geometry)

bound_op = get_bound_op(places)
sigma = get_test_density(queue, density_discr)
sigma = get_test_density(actx, density_discr)

cost_S = bound_op.get_modeled_cost(queue, sigma=sigma)
cost_S = bound_op.get_modeled_cost(actx, sigma=sigma)
model_result = (
one(cost_S.values())
.get_predicted_times(merge_close_lists=True))

# Warm-up run.
bound_op.eval(queue, {"sigma": sigma})
bound_op.eval({"sigma": sigma}, array_context=actx)

temp_timing_results = []
for _ in range(RUNS):
timing_data = {}
bound_op.eval(queue, {"sigma": sigma}, timing_data=timing_data)
bound_op.eval({"sigma": sigma},
array_context=actx, timing_data=timing_data)
temp_timing_results.append(one(timing_data.values()))

timing_result = {}
Expand Down
36 changes: 25 additions & 11 deletions examples/fmm-error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import division
import numpy as np
import pyopencl as cl
from meshmode.array_context import PyOpenCLArrayContext
from meshmode.dof_array import thaw
from meshmode.mesh.generation import ( # noqa
make_curve_mesh, starfish, ellipse, drop)
from sumpy.visualization import FieldPlotter
Expand All @@ -13,6 +15,7 @@ def main():

cl_ctx = cl.create_some_context()
queue = cl.CommandQueue(cl_ctx)
actx = PyOpenCLArrayContext(queue)

target_order = 16
qbx_order = 3
Expand All @@ -37,13 +40,13 @@ def main():
InterpolatoryQuadratureSimplexGroupFactory

pre_density_discr = Discretization(
cl_ctx, mesh,
actx, mesh,
InterpolatoryQuadratureSimplexGroupFactory(target_order))

unaccel_qbx = QBXLayerPotentialSource(
pre_density_discr, fine_order=2*target_order,
qbx_order=qbx_order, fmm_order=False,
target_association_tolerance=.05
target_association_tolerance=.05,
)

from pytential.target import PointsTarget
Expand All @@ -57,24 +60,35 @@ def main():
})
density_discr = places.get_discretization("unaccel_qbx")

nodes = density_discr.nodes().with_queue(queue)
angle = cl.clmath.atan2(nodes[1], nodes[0])
nodes = thaw(actx, density_discr.nodes())
angle = actx.np.atan2(nodes[1], nodes[0])

from pytential import bind, sym
#op = sym.d_dx(sym.S(kernel, sym.var("sigma")), qbx_forced_limit=None)
#op = sym.D(kernel, sym.var("sigma"), qbx_forced_limit=None)
op = sym.S(kernel, sym.var("sigma"), qbx_forced_limit=None)
if k:
kernel_kwargs = {"k": sym.var("k")}
else:
kernel_kwargs = {}

def get_op():
kwargs = dict(qbx_forced_limit=None)
kwargs.update(kernel_kwargs)
# return sym.d_dx(2, sym.S(kernel, sym.var("sigma"), **kwargs))
# return sym.D(kernel, sym.var("sigma"), **kwargs)
return sym.S(kernel, sym.var("sigma"), **kwargs)

op = get_op()

sigma = cl.clmath.cos(mode_nr*angle)
sigma = actx.np.cos(mode_nr*angle)

if isinstance(kernel, HelmholtzKernel):
sigma = sigma.astype(np.complex128)
for i, elem in np.ndenumerate(sigma):
sigma[i] = elem.astype(np.complex128)

fld_in_vol = bind(places, op, auto_where=("unaccel_qbx", "targets"))(
queue, sigma=sigma, k=k).get()
actx, sigma=sigma, k=k).get()

fmm_fld_in_vol = bind(places, op, auto_where=("qbx", "targets"))(
queue, sigma=sigma, k=k).get()
actx, sigma=sigma, k=k).get()

err = fmm_fld_in_vol-fld_in_vol

Expand Down
Loading