Module 'dolfinx.fem' has no attribute 'petsc'

Hi,
I use Google Colab and install FEniCSx using the following code:

!wget "https://fem-on-colab.github.io/releases/fenicsx-install-real.sh" -O "/tmp/fenicsx-install.sh" && bash "/tmp/fenicsx-install.sh"
!wget "https://fem-on-colab.github.io/releases/gmsh-install.sh" -O "/tmp/gmsh-install.sh" && bash "/tmp/gmsh-install.sh"
!apt-get install -qq xvfb
! pip install pyvista panel -q

I didn’t have any problems until yesterday when I started getting the following error:

AttributeError: module ‘dolfinx.fem’ has no attribute ‘petsc’

After running the line:

problem = fem.petsc.NonlinearProblem(F, uh, bcs=[bc])

I must note that I’m using Dokken’s tutorial A nonlinear Poisson equation - implementation, which had worked before. Therefore I suspect the problem is not with the code but the installation.

Does anyone know how I can make the code work again?

Just add import dolfinx.fem.petsc at the top of your file, and rewrite the command to call dolfinx.fem.petsc.NonlinearProblem.

This change is related to the changes in the main branch, see Isolate petsc4y in Python interface by garth-wells · Pull Request #2703 · FEniCS/dolfinx · GitHub
for details

1 Like

Unrelated note.

Neither of

!apt-get install -qq xvfb
! pip install pyvista panel -q

should be needed, as they should get installed alongside fenicsx.