Skip to content

Commit 9246c58

Browse files
alexfiklinducer
authored andcommitted
port deprecated uses of freeze and thaw
1 parent 2450074 commit 9246c58

23 files changed

+59
-74
lines changed

examples/cost.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import numpy as np
2929
import pyopencl as cl
3030

31-
from arraycontext import thaw
3231
from meshmode.array_context import PyOpenCLArrayContext
3332

3433
from pytential import sym, bind
@@ -109,7 +108,7 @@ def get_bound_op(places):
109108

110109

111110
def get_test_density(actx, density_discr):
112-
nodes = thaw(density_discr.nodes(), actx)
111+
nodes = actx.thaw(density_discr.nodes())
113112
sigma = actx.np.sin(10 * nodes[0])
114113
return sigma
115114

examples/fmm-error.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
from arraycontext import thaw
43
from meshmode.array_context import PyOpenCLArrayContext
54
from meshmode.mesh.generation import ( # noqa
65
make_curve_mesh, starfish, ellipse, drop)
@@ -61,7 +60,7 @@ def main():
6160
}, auto_where=("qbx", "targets"))
6261
density_discr = places.get_discretization("unaccel_qbx")
6362

64-
nodes = thaw(density_discr.nodes(), actx)
63+
nodes = actx.thaw(density_discr.nodes())
6564
angle = actx.np.arctan2(nodes[1], nodes[0])
6665

6766
from pytential import bind, sym

examples/helmholtz-dirichlet.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22
import numpy.linalg as la
33

4-
from arraycontext import thaw
54
from meshmode.array_context import PyOpenCLArrayContext
65
from meshmode.discretization import Discretization
76
from meshmode.discretization.poly_element import \
@@ -122,7 +121,7 @@ def main(mesh_name="ellipse", visualize=False):
122121

123122
# {{{ fix rhs and solve
124123

125-
nodes = thaw(density_discr.nodes(), actx)
124+
nodes = actx.thaw(density_discr.nodes())
126125
k_vec = np.array([2, 1])
127126
k_vec = k * k_vec / la.norm(k_vec, 2)
128127

examples/laplace-dirichlet-3d.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
from arraycontext import thaw
43
from meshmode.array_context import PyOpenCLArrayContext
54
from meshmode.discretization import Discretization
65
from meshmode.discretization.poly_element import \
@@ -110,7 +109,7 @@ def main(mesh_name="torus", visualize=False):
110109

111110
# {{{ fix rhs and solve
112111

113-
nodes = thaw(density_discr.nodes(), actx)
112+
nodes = actx.thaw(density_discr.nodes())
114113
source = np.array([rout, 0, 0], dtype=object)
115114

116115
def u_incoming_func(x):

examples/layerpot-3d.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
from arraycontext import thaw
43
from meshmode.array_context import PyOpenCLArrayContext
54

65
from sumpy.visualization import FieldPlotter
@@ -72,7 +71,7 @@ def main(mesh_name="ellipsoid"):
7271
}, auto_where="qbx")
7372
density_discr = places.get_discretization("qbx")
7473

75-
nodes = thaw(density_discr.nodes(), actx)
74+
nodes = actx.thaw(density_discr.nodes())
7675
angle = actx.np.arctan2(nodes[1], nodes[0])
7776

7877
if k:

examples/layerpot.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import numpy as np
66

7-
from arraycontext import thaw
87
from meshmode.array_context import PyOpenCLArrayContext
98
from sumpy.visualization import FieldPlotter
109
from sumpy.kernel import one_kernel_2d, LaplaceKernel, HelmholtzKernel # noqa
@@ -63,7 +62,7 @@ def main(curve_fn=starfish, visualize=True):
6362

6463
density_discr = places.get_discretization("qbx")
6564

66-
nodes = thaw(density_discr.nodes(), actx)
65+
nodes = actx.thaw(density_discr.nodes())
6766
angle = actx.np.arctan2(nodes[1], nodes[0])
6867

6968
if k:

examples/scaling-study.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
from arraycontext import thaw
43
from meshmode.array_context import PyOpenCLArrayContext
54
from meshmode.discretization import Discretization
65
from meshmode.discretization.poly_element import \
@@ -122,7 +121,7 @@ def timing_run(nx, ny, visualize=False):
122121

123122
mode_nr = 3
124123

125-
nodes = thaw(density_discr.nodes(), actx)
124+
nodes = actx.thaw(density_discr.nodes())
126125
angle = actx.np.arctan2(nodes[1], nodes[0])
127126

128127
sigma = actx.np.cos(mode_nr*angle)

pytential/linalg/proxy.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ def partition_by_nodes(
8989
from pytential.qbx.utils import tree_code_container
9090
tcc = tree_code_container(lpot_source._setup_actx)
9191

92-
from arraycontext import thaw
9392
tree, _ = tcc.build_tree()(actx.queue,
9493
particles=flatten(
95-
thaw(discr.nodes(), actx), actx, leaf_class=DOFArray
94+
actx.thaw(discr.nodes()), actx, leaf_class=DOFArray
9695
),
9796
max_particles_in_box=max_particles_in_box,
9897
kind=tree_kind)
@@ -389,16 +388,16 @@ def __call__(self,
389388
pxyindices = np.arange(0, nproxy, dtype=dof_index.indices.dtype)
390389
pxystarts = np.arange(0, nproxy + 1, self.nproxy)
391390

392-
from arraycontext import freeze, from_numpy
391+
from arraycontext import from_numpy
393392
from pytential.linalg import make_index_list
394393
return ProxyClusterGeometryData(
395394
places=self.places,
396395
dofdesc=source_dd,
397396
srcindex=dof_index,
398397
pxyindex=make_index_list(pxyindices, pxystarts),
399-
points=freeze(from_numpy(proxies, actx), actx),
400-
centers=freeze(centers_dev, actx),
401-
radii=freeze(radii_dev, actx),
398+
points=actx.freeze(from_numpy(proxies, actx)),
399+
centers=actx.freeze(centers_dev),
400+
radii=actx.freeze(radii_dev),
402401
)
403402

404403

pytential/qbx/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import numpy as np
2424

25-
from arraycontext import PyOpenCLArrayContext, thaw, freeze, flatten, unflatten
25+
from arraycontext import PyOpenCLArrayContext, flatten, unflatten
2626
from meshmode.dof_array import DOFArray
2727

2828
from pytools import memoize_method, memoize_in, single_valued
@@ -661,7 +661,7 @@ def exec_compute_potential_insn_fmm(self, actx: PyOpenCLArrayContext,
661661

662662
from meshmode.discretization import Discretization
663663
if isinstance(target_discr, Discretization):
664-
template_ary = thaw(target_discr.nodes()[0], actx)
664+
template_ary = actx.thaw(target_discr.nodes()[0])
665665
result = unflatten(template_ary, result, actx, strict=False)
666666

667667
results.append((o.name, result))
@@ -758,7 +758,7 @@ def exec_compute_potential_insn_direct(self, actx, insn, bound_expr, evaluate,
758758
def _flat_nodes(dofdesc):
759759
discr = bound_expr.places.get_discretization(
760760
dofdesc.geometry, dofdesc.discr_stage)
761-
return freeze(flatten(discr.nodes(), actx, leaf_class=DOFArray), actx)
761+
return actx.freeze(flatten(discr.nodes(), actx, leaf_class=DOFArray))
762762

763763
@memoize_in(bound_expr.places,
764764
(QBXLayerPotentialSource, "flat_expansion_radii"))
@@ -767,7 +767,7 @@ def _flat_expansion_radii(dofdesc):
767767
bound_expr.places,
768768
sym.expansion_radii(self.ambient_dim, dofdesc=dofdesc),
769769
)(actx)
770-
return freeze(flatten(radii, actx), actx)
770+
return actx.freeze(flatten(radii, actx))
771771

772772
@memoize_in(bound_expr.places,
773773
(QBXLayerPotentialSource, "flat_centers"))
@@ -776,7 +776,7 @@ def _flat_centers(dofdesc, qbx_forced_limit):
776776
sym.expansion_centers(
777777
self.ambient_dim, qbx_forced_limit, dofdesc=dofdesc),
778778
)(actx)
779-
return freeze(flatten(centers, actx, leaf_class=DOFArray), actx)
779+
return actx.freeze(flatten(centers, actx, leaf_class=DOFArray))
780780

781781
from pytential.source import evaluate_kernel_arguments
782782
flat_kernel_args = evaluate_kernel_arguments(
@@ -846,7 +846,7 @@ def _flat_centers(dofdesc, qbx_forced_limit):
846846
for i, o in outputs:
847847
result = output_for_each_kernel[o.target_kernel_index]
848848
if isinstance(target_discr, Discretization):
849-
template_ary = thaw(target_discr.nodes()[0], actx)
849+
template_ary = actx.thaw(target_discr.nodes()[0])
850850
result = unflatten(template_ary, result, actx, strict=False)
851851

852852
results[i] = (o.name, result)
@@ -922,7 +922,7 @@ def _flat_centers(dofdesc, qbx_forced_limit):
922922
for i, o in outputs:
923923
result = output_for_each_kernel[o.target_kernel_index]
924924
if isinstance(target_discr, Discretization):
925-
template_ary = thaw(target_discr.nodes()[0], actx)
925+
template_ary = actx.thaw(target_discr.nodes()[0])
926926
result = unflatten(template_ary, result, actx, strict=False)
927927

928928
results[i] = (o.name, result)

pytential/qbx/geometry.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import numpy as np
2525

2626
from pytools import memoize_method, memoize_in, log_process
27-
from arraycontext import PyOpenCLArrayContext, flatten, freeze
27+
from arraycontext import PyOpenCLArrayContext, flatten
2828
from meshmode.dof_array import DOFArray
2929

3030
from boxtree.tools import DeviceDataRecord
@@ -442,7 +442,7 @@ def flat_centers(self):
442442
self.ambient_dim,
443443
dofdesc=self.source_dd.to_stage1()))(actx)
444444

445-
return freeze(flatten(centers, actx, leaf_class=DOFArray), actx)
445+
return actx.freeze(flatten(centers, actx, leaf_class=DOFArray))
446446

447447
@memoize_method
448448
def flat_expansion_radii(self):
@@ -460,7 +460,7 @@ def flat_expansion_radii(self):
460460
granularity=sym.GRANULARITY_CENTER,
461461
dofdesc=self.source_dd.to_stage1()))(actx)
462462

463-
return freeze(flatten(radii, actx), actx)
463+
return actx.freeze(flatten(radii, actx))
464464

465465
# }}}
466466

pytential/source.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import numpy as np
2424

2525
from pytools import memoize_in
26-
from arraycontext import thaw, flatten, unflatten
26+
from arraycontext import flatten, unflatten
2727
from meshmode.dof_array import DOFArray
2828

2929
from sumpy.fmm import UnableToCollectTimingData
@@ -194,7 +194,7 @@ def exec_compute_potential_insn(self, actx, insn, bound_expr, evaluate,
194194
from meshmode.discretization import Discretization
195195
result = output_for_each_kernel[o.target_kernel_index]
196196
if isinstance(target_discr, Discretization):
197-
template_ary = thaw(target_discr.nodes()[0], actx)
197+
template_ary = actx.thaw(target_discr.nodes()[0])
198198
result = unflatten(template_ary, result, actx, strict=False)
199199

200200
results.append((o.name, result))

pytential/symbolic/execution.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
EvaluationMapper as PymbolicEvaluationMapper)
3030
import numpy as np
3131

32-
from arraycontext import PyOpenCLArrayContext, thaw, freeze
32+
from arraycontext import PyOpenCLArrayContext
3333
from meshmode.dof_array import DOFArray
3434

3535
from pytools import memoize_in, memoize_method
@@ -210,9 +210,8 @@ def map_node_coordinate_component(self, expr):
210210
discr = self.places.get_discretization(
211211
expr.dofdesc.geometry, expr.dofdesc.discr_stage)
212212

213-
from arraycontext import thaw
214213
x = discr.nodes()[expr.ambient_axis]
215-
return thaw(x, self.array_context)
214+
return self.array_context.thaw(x)
216215

217216
def map_num_reference_derivative(self, expr):
218217
from pytools import flatten
@@ -225,10 +224,9 @@ def map_num_reference_derivative(self, expr):
225224
return num_reference_derivative(discr, ref_axes, self.rec(expr.operand))
226225

227226
def map_q_weight(self, expr):
228-
from arraycontext import thaw
229227
discr = self.places.get_discretization(
230228
expr.dofdesc.geometry, expr.dofdesc.discr_stage)
231-
return thaw(discr.quad_weights(), self.array_context)
229+
return self.array_context.thaw(discr.quad_weights())
232230

233231
def map_inverse(self, expr):
234232
bound_op_cache = self.bound_expr.places._get_cache(
@@ -282,12 +280,12 @@ def map_common_subexpression(self, expr):
282280
rec = cache[key]
283281
if (expr.scope == sym.cse_scope.DISCRETIZATION
284282
and not isinstance(rec, Number)):
285-
rec = thaw(rec, self.array_context)
283+
rec = self.array_context.thaw(rec)
286284
except KeyError:
287285
cached_rec = rec = self.rec(expr.child)
288286
if (expr.scope == sym.cse_scope.DISCRETIZATION
289287
and not isinstance(rec, Number)):
290-
cached_rec = freeze(cached_rec, self.array_context)
288+
cached_rec = self.array_context.freeze(cached_rec)
291289

292290
cache[key] = cached_rec
293291

@@ -492,7 +490,7 @@ def unflatten(self, ary):
492490
from meshmode.discretization import Discretization
493491
if isinstance(discr, Discretization):
494492
from arraycontext import unflatten
495-
template_ary = thaw(discr.nodes()[0], self.array_context)
493+
template_ary = self.array_context.thaw(discr.nodes()[0])
496494
component = unflatten(
497495
template_ary, component, self.array_context,
498496
strict=False)
@@ -811,7 +809,7 @@ def eval(self, context=None, timing_data=None,
811809
value = cache[expr.child]
812810
if (expr.scope == sym.cse_scope.DISCRETIZATION
813811
and not isinstance(value, Number)):
814-
value = thaw(value, array_context)
812+
value = array_context.thaw(value)
815813

816814
return value
817815

pytential/symbolic/matrix.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from sys import intern
2929

3030
from pytools import memoize_method
31-
from arraycontext import thaw, flatten, unflatten
31+
from arraycontext import flatten, unflatten
3232
from meshmode.dof_array import DOFArray
3333

3434
from pytential.symbolic.mappers import EvaluationMapperBase
@@ -209,7 +209,7 @@ def map_num_reference_derivative(self, expr):
209209

210210
discr = self.places.get_discretization(dofdesc.geometry, dofdesc.discr_stage)
211211

212-
template_ary = thaw(discr.nodes()[0], actx)
212+
template_ary = actx.thaw(discr.nodes()[0])
213213
rec_operand = unflatten(template_ary, actx.from_numpy(rec_operand), actx)
214214

215215
return actx.to_numpy(flatten(
@@ -341,7 +341,7 @@ def map_interpolation(self, expr):
341341
conn = self.places.get_connection(expr.from_dd, expr.to_dd)
342342
discr = self.places.get_discretization(
343343
expr.from_dd.geometry, expr.from_dd.discr_stage)
344-
template_ary = thaw(discr.nodes()[0], actx)
344+
template_ary = actx.thaw(discr.nodes()[0])
345345

346346
from pytools.obj_array import make_obj_array
347347
return make_obj_array([

pytential/unregularized.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from loopy.version import MOST_RECENT_LANGUAGE_VERSION
2929

3030
from pytools import memoize_method
31-
from arraycontext import PyOpenCLArrayContext, thaw, flatten, unflatten
31+
from arraycontext import PyOpenCLArrayContext, flatten, unflatten
3232
from meshmode.dof_array import DOFArray
3333

3434
from boxtree.tools import DeviceDataRecord
@@ -171,7 +171,7 @@ def exec_compute_potential_insn_direct(self, actx: PyOpenCLArrayContext,
171171
from meshmode.discretization import Discretization
172172
result = output_for_each_kernel[o.target_kernel_index]
173173
if isinstance(target_discr, Discretization):
174-
template_ary = thaw(target_discr.nodes()[0], actx)
174+
template_ary = actx.thaw(target_discr.nodes()[0])
175175
result = unflatten(template_ary, result, actx, strict=False)
176176

177177
results.append((o.name, result))
@@ -285,7 +285,7 @@ def exec_compute_potential_insn_fmm(self, actx: PyOpenCLArrayContext,
285285

286286
from meshmode.discretization import Discretization
287287
if isinstance(target_discr, Discretization):
288-
template_ary = thaw(target_discr.nodes()[0], actx)
288+
template_ary = actx.thaw(target_discr.nodes()[0])
289289
result = unflatten(template_ary, result, actx, strict=False)
290290

291291
results.append((o.name, result))

test/test_beltrami.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def evaluate_circle_eigf(actx, discr, k: int) -> np.ndarray:
5050

5151
# {{{ get polar coordinates
5252

53-
from arraycontext import thaw
54-
x, y = thaw(discr.nodes(), actx)
53+
x, y = actx.thaw(discr.nodes())
5554
theta = actx.np.arctan2(y, x)
5655

5756
# }}}
@@ -64,8 +63,7 @@ def evaluate_sphere_eigf(actx, discr, m: int, n: int) -> DOFArray:
6463

6564
# {{{ get spherical coordinates
6665

67-
from arraycontext import thaw
68-
x, y, z = thaw(discr.nodes(), actx)
66+
x, y, z = actx.thaw(discr.nodes())
6967

7068
theta = actx.np.arctan2(actx.np.sqrt(x**2 + y**2), z)
7169
phi = actx.np.arctan2(y, x)

0 commit comments

Comments
 (0)