Skip to content

Commit f5564bf

Browse files
connorjwarddham
andauthored
Updates for latest release of PETSc (#4181)
* Fixes for PETSc 3.23.0 * Fix that options prefixes may now be None Introduced in https://gitlab.com/petsc/petsc/-/merge_requests/8185. --------- Co-authored-by: David Ham <[email protected]>
1 parent 6789e9d commit f5564bf

File tree

21 files changed

+54
-56
lines changed

21 files changed

+54
-56
lines changed

firedrake/cython/dmcommon.pyx

+6-2
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,8 @@ def mark_entity_classes_using_cell_dm(PETSc.DM swarm):
21202120
PetscInt nswarmCells, swarmCell, blocksize
21212121
PetscInt *swarmParentCells = NULL
21222122
PetscDataType ctype = PETSC_DATATYPE_UNKNOWN
2123+
const char *cellid = NULL
2124+
PETSc.PetscDMSwarmCellDM celldm
21232125

21242126
plex = swarm.getCellDM()
21252127
get_height_stratum(plex.dm, 0, &cStart, &cEnd)
@@ -2145,14 +2147,16 @@ def mark_entity_classes_using_cell_dm(PETSc.DM swarm):
21452147
for ilabel, op2class in enumerate([b"pyop2_core", b"pyop2_owned", b"pyop2_ghost"]):
21462148
CHKERR(DMCreateLabel(swarm.dm, op2class))
21472149
CHKERR(DMGetLabel(swarm.dm, op2class, &swarm_labels[ilabel]))
2148-
CHKERR(DMSwarmGetField(swarm.dm, b"DMSwarm_cellid", &blocksize, &ctype, <void**>&swarmParentCells))
2150+
CHKERR(DMSwarmGetCellDMActive(swarm.dm, &celldm))
2151+
CHKERR(DMSwarmCellDMGetCellID(celldm, &cellid))
2152+
CHKERR(DMSwarmGetField(swarm.dm, cellid, &blocksize, &ctype, <void**> &swarmParentCells))
21492153
assert ctype == PETSC_INT
21502154
assert blocksize == 1
21512155
CHKERR(DMSwarmGetLocalSize(swarm.dm, &nswarmCells))
21522156
for swarmCell in range(nswarmCells):
21532157
plex_cell_class = plex_cell_classes[swarmParentCells[swarmCell] - cStart]
21542158
CHKERR(DMLabelSetValue(swarm_labels[plex_cell_class], swarmCell, label_value))
2155-
CHKERR(DMSwarmRestoreField(swarm.dm, b"DMSwarm_cellid", &blocksize, &ctype, <void**>&swarmParentCells))
2159+
CHKERR(DMSwarmRestoreField(swarm.dm, cellid, &blocksize, &ctype, <void**> &swarmParentCells))
21562160
CHKERR(PetscFree(plex_cell_classes))
21572161

21582162

firedrake/cython/petschdr.pxi

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ cdef extern from "petscdm.h" nogil:
7979
cdef extern from "petscdmswarm.h" nogil:
8080
int DMSwarmGetLocalSize(PETSc.PetscDM,PetscInt*)
8181
int DMSwarmGetCellDM(PETSc.PetscDM, PETSc.PetscDM*)
82+
int DMSwarmGetCellDMActive(PETSc.PetscDM, PETSc.PetscDMSwarmCellDM*)
83+
int DMSwarmCellDMGetCellID(PETSc.PetscDMSwarmCellDM, const char *[])
8284
int DMSwarmGetField(PETSc.PetscDM,const char[],PetscInt*,PetscDataType*,void**)
8385
int DMSwarmRestoreField(PETSc.PetscDM,const char[],PetscInt*,PetscDataType*,void**)
8486

firedrake/mesh.py

+11-18
Original file line numberDiff line numberDiff line change
@@ -1966,14 +1966,15 @@ def _renumber_entities(self, reorder):
19661966
if reorder:
19671967
swarm = self.topology_dm
19681968
parent = self._parent_mesh.topology_dm
1969-
swarm_parent_cell_nums = swarm.getField("DMSwarm_cellid").ravel()
1969+
cell_id_name = swarm.getCellDMActive().getCellID()
1970+
swarm_parent_cell_nums = swarm.getField(cell_id_name).ravel()
19701971
parent_renum = self._parent_mesh._dm_renumbering.getIndices()
19711972
pStart, _ = parent.getChart()
19721973
parent_renum_inv = np.empty_like(parent_renum)
19731974
parent_renum_inv[parent_renum - pStart] = np.arange(len(parent_renum))
19741975
# Use kind = 'stable' to make the ordering deterministic.
19751976
perm = np.argsort(parent_renum_inv[swarm_parent_cell_nums - pStart], kind='stable').astype(IntType)
1976-
swarm.restoreField("DMSwarm_cellid")
1977+
swarm.restoreField(cell_id_name)
19771978
perm_is = PETSc.IS().create(comm=swarm.comm)
19781979
perm_is.setType("general")
19791980
perm_is.setIndices(perm)
@@ -3557,11 +3558,9 @@ def _pic_swarm_in_mesh(
35573558
#. ``parentcellextrusionheight`` which contains the extrusion height of
35583559
the immersed vertex in the parent mesh cell.
35593560
3560-
Another three are required for proper functioning of the DMSwarm:
3561+
Another two are required for proper functioning of the DMSwarm:
35613562
35623563
#. ``DMSwarmPIC_coor`` which contains the coordinates of the point.
3563-
#. ``DMSwarm_cellid`` the DMPlex cell within which the DMSwarm point is
3564-
located.
35653564
#. ``DMSwarm_rank``: the MPI rank which owns the DMSwarm point.
35663565
35673566
.. note::
@@ -3794,7 +3793,6 @@ def _dmswarm_create(
37943793
# These are created by default for a PIC DMSwarm
37953794
default_fields = [
37963795
("DMSwarmPIC_coor", gdim, RealType),
3797-
("DMSwarm_cellid", 1, IntType),
37983796
("DMSwarm_rank", 1, IntType),
37993797
]
38003798

@@ -3853,12 +3851,6 @@ def _dmswarm_create(
38533851
# Set to Particle In Cell (PIC) type
38543852
if not isinstance(plex, PETSc.DMSwarm):
38553853
swarm.setType(PETSc.DMSwarm.Type.PIC)
3856-
else:
3857-
# This doesn't work where we embed a DMSwarm in a DMSwarm, instead
3858-
# we register some default fields manually
3859-
for name, size, dtype in default_fields:
3860-
if name == "DMSwarmPIC_coor" or name == "DMSwarm_cellid":
3861-
swarm.registerField(name, size, dtype=dtype)
38623854

38633855
# Register any fields
38643856
for name, size, dtype in swarm.default_extra_fields + swarm.other_fields:
@@ -3872,14 +3864,15 @@ def _dmswarm_create(
38723864
# Add point coordinates. This amounts to our own implementation of
38733865
# DMSwarmSetPointCoordinates because Firedrake's mesh coordinate model
38743866
# doesn't always exactly coincide with that of DMPlex: in most cases the
3875-
# plex_parent_cell_nums (DMSwarm_cellid field) and parent_cell_nums
3876-
# (parentcellnum field), the latter being the numbering used by firedrake,
3877-
# refer fundamentally to the same cells. For extruded meshes the DMPlex
3878-
# dimension is based on the topological dimension of the base mesh.
3867+
# plex_parent_cell_nums and parent_cell_nums (parentcellnum field), the
3868+
# latter being the numbering used by firedrake, refer fundamentally to the
3869+
# same cells. For extruded meshes the DMPlex dimension is based on the
3870+
# topological dimension of the base mesh.
38793871

38803872
# NOTE ensure that swarm.restoreField is called for each field too!
38813873
swarm_coords = swarm.getField("DMSwarmPIC_coor").reshape((num_vertices, gdim))
3882-
swarm_parent_cell_nums = swarm.getField("DMSwarm_cellid").ravel()
3874+
cell_id_name = swarm.getCellDMActive().getCellID()
3875+
swarm_parent_cell_nums = swarm.getField(cell_id_name).ravel()
38833876
field_parent_cell_nums = swarm.getField("parentcellnum").ravel()
38843877
field_reference_coords = swarm.getField("refcoord").reshape((num_vertices, tdim))
38853878
field_global_index = swarm.getField("globalindex").ravel()
@@ -3903,7 +3896,7 @@ def _dmswarm_create(
39033896
swarm.restoreField("refcoord")
39043897
swarm.restoreField("parentcellnum")
39053898
swarm.restoreField("DMSwarmPIC_coor")
3906-
swarm.restoreField("DMSwarm_cellid")
3899+
swarm.restoreField(cell_id_name)
39073900

39083901
if extruded:
39093902
field_base_parent_cell_nums = swarm.getField("parentcellbasenum").ravel()

firedrake/preconditioners/asm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize(self, pc):
2929
# Get context from pc
3030
_, P = pc.getOperators()
3131
dm = pc.getDM()
32-
self.prefix = pc.getOptionsPrefix() + self._prefix
32+
self.prefix = (pc.getOptionsPrefix() or "") + self._prefix
3333

3434
# Extract function space and mesh to obtain plex and indexing functions
3535
V = get_function_space(dm)

firedrake/preconditioners/assembled.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def initialize(self, pc):
3737
if not context.on_diag:
3838
raise ValueError("Only makes sense to invert diagonal block")
3939

40-
prefix = pc.getOptionsPrefix()
40+
prefix = pc.getOptionsPrefix() or ""
4141
options_prefix = prefix + self._prefix
4242

4343
mat_type = PETSc.Options().getString(options_prefix + "mat_type", "aij")

firedrake/preconditioners/bddc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def initialize(self, pc):
4242
# Get context from pc
4343
_, P = pc.getOperators()
4444
dm = pc.getDM()
45-
self.prefix = pc.getOptionsPrefix() + self._prefix
45+
self.prefix = (pc.getOptionsPrefix() or "") + self._prefix
4646

4747
V = get_function_space(dm)
4848

firedrake/preconditioners/facet_split.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_indices(self, V, W):
4141
def initialize(self, pc):
4242
from firedrake import FunctionSpace, TestFunction, TrialFunction, split
4343

44-
prefix = pc.getOptionsPrefix()
44+
prefix = pc.getOptionsPrefix() or ""
4545
options_prefix = prefix + self._prefix
4646
options = PETSc.Options(options_prefix)
4747
mat_type = options.getString("mat_type", "submatrix")

firedrake/preconditioners/fdm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def initialize(self, pc):
121121
Citations().register(self._citation)
122122
self.comm = pc.comm
123123
Amat, Pmat = pc.getOperators()
124-
prefix = pc.getOptionsPrefix()
124+
prefix = pc.getOptionsPrefix() or ""
125125
options_prefix = prefix + self._prefix
126126
options = PETSc.Options(options_prefix)
127127

firedrake/preconditioners/gtmg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize(self, pc):
3131
if not isinstance(ctx, _SNESContext):
3232
raise ValueError("Don't know how to get form from %r" % ctx)
3333

34-
prefix = pc.getOptionsPrefix()
34+
prefix = pc.getOptionsPrefix() or ""
3535
options_prefix = prefix + self._prefix
3636
opts = PETSc.Options()
3737

firedrake/preconditioners/hiptmair.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def initialize(self, pc):
4141
appctx = self.get_appctx(pc)
4242
fcp = appctx.get("form_compiler_parameters")
4343

44-
prefix = pc.getOptionsPrefix()
44+
prefix = pc.getOptionsPrefix() or ""
4545
options_prefix = prefix + self._prefix
4646
opts = PETSc.Options()
4747

@@ -156,7 +156,7 @@ def coarsen(self, pc):
156156
else:
157157
raise ValueError("Hiptmair decomposition not available for", element)
158158

159-
prefix = pc.getOptionsPrefix()
159+
prefix = pc.getOptionsPrefix() or ""
160160
options_prefix = prefix + self._prefix
161161
opts = PETSc.Options(options_prefix)
162162
domain = opts.getString("mg_coarse_restriction_domain", "")

firedrake/preconditioners/hypre_ads.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HypreADS(PCBase):
1616
def initialize(self, obj):
1717
A, P = obj.getOperators()
1818
appctx = self.get_appctx(obj)
19-
prefix = obj.getOptionsPrefix()
19+
prefix = obj.getOptionsPrefix() or ""
2020
V = get_function_space(obj.getDM())
2121
mesh = V.mesh()
2222

firedrake/preconditioners/hypre_ams.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def initialize(self, obj):
3737
Citations().register("Kolev2009")
3838
A, P = obj.getOperators()
3939
appctx = self.get_appctx(obj)
40-
prefix = obj.getOptionsPrefix()
40+
prefix = obj.getOptionsPrefix() or ""
4141
V = get_function_space(obj.getDM())
4242
mesh = V.mesh()
4343

firedrake/preconditioners/patch.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ def __call__(self, pc):
715715
raise NotImplementedError("Sorry, plane smoothers not yet implemented in complex mode")
716716
dm = pc.getDM()
717717
context = dm.getAttr("__firedrake_ctx__")
718-
prefix = pc.getOptionsPrefix()
718+
prefix = pc.getOptionsPrefix() or ""
719719
sentinel = object()
720720
sweeps = PETSc.Options(prefix).getString("pc_patch_construct_ps_sweeps", default=sentinel)
721721
if sweeps == sentinel:
@@ -789,7 +789,7 @@ def initialize(self, obj):
789789
PETSc.Sys.Print("Warning: you almost surely want to set an overlap_type in your mesh's distribution_parameters.")
790790

791791
patch = obj.__class__().create(comm=mesh.comm)
792-
patch.setOptionsPrefix(obj.getOptionsPrefix() + "patch_")
792+
patch.setOptionsPrefix((obj.getOptionsPrefix() or "") + "patch_")
793793
self.configure_patch(patch, obj)
794794
patch.setType("patch")
795795

@@ -924,7 +924,7 @@ def destroy(self, obj):
924924
self.patch.destroy()
925925

926926
def user_construction_op(self, obj, *args, **kwargs):
927-
prefix = obj.getOptionsPrefix()
927+
prefix = obj.getOptionsPrefix() or ""
928928
sentinel = object()
929929
usercode = PETSc.Options(prefix).getString("%s_patch_construct_python_type" % self._objectname, default=sentinel)
930930
if usercode == sentinel:

firedrake/preconditioners/pcd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def initialize(self, pc):
4545
from firedrake.assemble import assemble, get_assembler
4646
if pc.getType() != "python":
4747
raise ValueError("Expecting PC type python")
48-
prefix = pc.getOptionsPrefix() + "pcd_"
48+
prefix = (pc.getOptionsPrefix() or "") + "pcd_"
4949

5050
# we assume P has things stuffed inside of it
5151
_, P = pc.getOperators()

firedrake/preconditioners/pmg.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def initialize(self, obj):
106106
if test.function_space() != trial.function_space():
107107
raise NotImplementedError("test and trial spaces must be the same")
108108

109-
prefix = obj.getOptionsPrefix()
109+
prefix = obj.getOptionsPrefix() or ""
110110
options_prefix = prefix + self._prefix
111111
pdm = PETSc.DMShell().create(comm=obj.comm)
112112
pdm.setOptionsPrefix(options_prefix)
@@ -119,7 +119,7 @@ def initialize(self, obj):
119119
default_mat_type = "matfree"
120120

121121
# Get the coarse degree from PETSc options
122-
copts = PETSc.Options(ppc.getOptionsPrefix() + ppc.getType() + "_coarse_")
122+
copts = PETSc.Options((ppc.getOptionsPrefix() or "") + ppc.getType() + "_coarse_")
123123
self.coarse_degree = copts.getInt("degree", default=1)
124124
self.coarse_mat_type = copts.getString("mat_type", default=default_mat_type)
125125
self.coarse_pmat_type = copts.getString("pmat_type", default=self.coarse_mat_type)
@@ -443,7 +443,7 @@ class PMGPC(PCBase, PMGBase):
443443
def configure_pmg(self, pc, pdm):
444444
odm = pc.getDM()
445445
ppc = PETSc.PC().create(comm=pc.comm)
446-
ppc.setOptionsPrefix(pc.getOptionsPrefix() + self._prefix)
446+
ppc.setOptionsPrefix((pc.getOptionsPrefix() or "") + self._prefix)
447447
ppc.setType("mg")
448448
ppc.setOperators(*pc.getOperators())
449449
ppc.setDM(pdm)
@@ -458,7 +458,7 @@ def configure_pmg(self, pc, pdm):
458458
# other way to get PETSc to know this at the right time.
459459
max_levels = odm.getRefineLevel() + 1
460460
if max_levels > 1:
461-
opts = PETSc.Options(pc.getOptionsPrefix() + "pmg_")
461+
opts = PETSc.Options((pc.getOptionsPrefix() or "") + "pmg_")
462462
if opts.getString("mg_coarse_pc_type") == "mg":
463463
opts["mg_coarse_pc_mg_levels"] = min(opts.getInt("mg_coarse_pc_mg_levels", max_levels), max_levels)
464464
return ppc
@@ -479,7 +479,7 @@ class PMGSNES(SNESBase, PMGBase):
479479
def configure_pmg(self, snes, pdm):
480480
odm = snes.getDM()
481481
psnes = PETSc.SNES().create(comm=snes.comm)
482-
psnes.setOptionsPrefix(snes.getOptionsPrefix() + self._prefix)
482+
psnes.setOptionsPrefix((snes.getOptionsPrefix() or "") + self._prefix)
483483
psnes.setType("fas")
484484
psnes.setDM(pdm)
485485
psnes.setTolerances(max_it=1)
@@ -503,7 +503,7 @@ def configure_pmg(self, snes, pdm):
503503
# other way to get PETSc to know this at the right time.
504504
max_levels = odm.getRefineLevel() + 1
505505
if max_levels > 1:
506-
opts = PETSc.Options(snes.getOptionsPrefix() + "pfas_")
506+
opts = PETSc.Options((snes.getOptionsPrefix() or "") + "pfas_")
507507
if opts.getString("fas_coarse_pc_type") == "mg":
508508
opts["fas_coarse_pc_mg_levels"] = min(opts.getInt("fas_coarse_pc_mg_levels", max_levels), max_levels)
509509
if opts.getString("fas_coarse_snes_type") == "fas":

firedrake/slate/static_condensation/hybridization.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def initialize(self, pc):
4343
from ufl.algorithms.replace import replace
4444

4545
# Extract the problem context
46-
prefix = pc.getOptionsPrefix() + "hybridization_"
46+
prefix = (pc.getOptionsPrefix() or "") + "hybridization_"
4747
_, P = pc.getOperators()
4848
self.ctx = P.getPythonContext()
4949

firedrake/slate/static_condensation/scpc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def initialize(self, pc):
3636
from firedrake.parloops import par_loop, INC
3737
from ufl import dx
3838

39-
prefix = pc.getOptionsPrefix() + "condensed_field_"
39+
prefix = (pc.getOptionsPrefix() or "") + "condensed_field_"
4040
A, P = pc.getOperators()
4141
self.cxt = A.getPythonContext()
4242
if not isinstance(self.cxt, ImplicitMatrixContext):
@@ -49,7 +49,7 @@ def initialize(self, pc):
4949
if len(W) > 3:
5050
raise NotImplementedError("Only supports up to three function spaces.")
5151

52-
elim_fields = PETSc.Options().getString(pc.getOptionsPrefix()
52+
elim_fields = PETSc.Options().getString((pc.getOptionsPrefix() or "")
5353
+ "pc_sc_eliminate_fields",
5454
None)
5555
if elim_fields:

pyproject.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies = [
2222
"libsupermesh",
2323
# NOTE: If changing the PETSc/SLEPc version then firedrake-configure also needs
2424
# changing (as well as other references to petsc4py and slepc4py here)
25-
"petsc4py==3.22.2",
25+
"petsc4py==3.23.0",
2626
"numpy",
2727
"packaging",
2828
"pkgconfig",
@@ -119,7 +119,7 @@ ci = [
119119
"pytest-split", # needed for firedrake-run-split-tests
120120
"pytest-timeout",
121121
"pytest-xdist",
122-
"slepc4py==3.22.2",
122+
"slepc4py==3.23.0",
123123
"torch", # requires passing '--extra-index-url' to work
124124
"vtk",
125125
]
@@ -133,7 +133,7 @@ docker = [ # Used in firedrake-vanilla container
133133
"pytest-split", # needed for firedrake-run-split-tests
134134
"pytest-timeout",
135135
"pytest-xdist",
136-
"slepc4py==3.22.2",
136+
"slepc4py==3.23.0",
137137
]
138138

139139
[build-system]
@@ -146,7 +146,7 @@ requires = [
146146
"pkgconfig",
147147
"pybind11",
148148
"setuptools>61.2",
149-
"petsc4py==3.22.2",
149+
"petsc4py==3.23.0",
150150
"rtree>=1.2",
151151
]
152152
build-backend = "setuptools.build_meta"

scripts/firedrake-configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ARCH_COMPLEX = FiredrakeArch.COMPLEX
4141

4242
# NOTE: When updating this variable corresponding changes must be made inside
4343
# pyproject.toml
44-
SUPPORTED_PETSC_VERSION = "v3.22.2"
44+
SUPPORTED_PETSC_VERSION = "v3.23.0"
4545

4646

4747
def main():

tests/firedrake/regression/test_matrix_prefix.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def test_matrix_prefix_solver(options_prefix):
3232
assert factor.getType() == DEFAULT_DIRECT_SOLVER
3333

3434
for A in pc.getOperators():
35-
pfx = A.getOptionsPrefix()
36-
if pfx is None:
37-
pfx = ""
35+
pfx = A.getOptionsPrefix() or ""
3836
assert pfx == solver.options_prefix
3937

4038

0 commit comments

Comments
 (0)