[petsc-users] How to read/write a HDF5 file using petsc4py ?

Lawrence Mitchell wence at gmx.li
Tue Dec 7 09:18:26 CST 2021


Comments inline below:

> On 7 Dec 2021, at 14:43, Quentin Chevalier <quentin.chevalier at polytechnique.edu> wrote:
> 
> @Matthew, as stated before, error output is unchanged, i.e.the python
> command below produces the same traceback :
> 
> # python3 -c "from petsc4py import PETSc; PETSc.Viewer().createHDF5('d.h5')"
> Traceback (most recent call last):
>  File "<string>", line 1, in <module>
>  File "PETSc/Viewer.pyx", line 182, in petsc4py.PETSc.Viewer.createHDF5
> petsc4py.PETSc.Error: error code 86
> [0] PetscViewerSetType() at
> /usr/local/petsc/src/sys/classes/viewer/interface/viewreg.c:442
> [0] Unknown type. Check for miss-spelling or missing package:
> https://petsc.org/release/install/install/#external-packages
> [0] Unknown PetscViewer type given: hdf5
> 
> @Wence that makes sense. I'd assumed that the original PETSc had been
> overwritten, and if the linking has gone wrong I'm surprised anything
> happens with petsc4py at all.
> 
> Your tentative command gave :
> 
> ERROR: Invalid requirement: '/usr/local/petsc/src/binding/petsc4py'
> Hint: It looks like a path. File
> '/usr/local/petsc/src/binding/petsc4py' does not exist.
> 
> So I tested that global variables PETSC_ARCH & PETSC_DIR were correct
> then ran "pip install petsc4py" to restart petsc4py from scratch.

This downloads petsc4py from pypi. It is not guaranteed to give you a version that matches the PETSc version you have installed (which is the source of your error below)


> This
> gives rise to a different error :
> 
[...]
> ImportError: /usr/local/lib/python3.9/dist-packages/petsc4py/lib/linux-gnu-real-32/PETSc.cpython-39-x86_64-linux-gnu.so:
> undefined symbol: petscstack
> 
> Not sure that it a step forward ; looks like petsc4py is broken now.

The steps to build PETSc with HDF5 support and then get a compatible petsc4py are:

1. Download the PETSc source somehow (https://petsc.org/release/download/)

I now assume that this source tree lives in .../petsc

2. cd .../petsc

3. ./configure --with-hdf5 --any-other --configure-flags --you-want

4. Run the appropriate "make" command as suggested by configure

5. Run the appropriate "make check" command as suggested by configure

6. Set PETSC_DIR and PETSC_ARCH appropriately

7. pip install src/binding/petsc4py

If you are working the docker container from dolfinx/dolfinx, you can see the commands that are run to install PETSc, and then petsc4py, here https://github.com/FEniCS/dolfinx/blob/main/docker/Dockerfile#L243

If you want to reproduce these versions of PETSc but with the addition of HDF5 support, just add --with-hdf5 to all of the relevant configure lines.

Lawrence




More information about the petsc-users mailing list