AttributeError: 'petsc4py.PETSc.KSP' object has no attribute 'matSolve'

I use petsc4py (installed by Ubuntu, petsc4py V3.15.1) solve the linear system with multiple right-hand sides. And I look up the petsc4py user manual and find the method ‘petsc4py.PETSc.KSP.matSolve()’. But when I run my code, it output:

solver.matSolve(B, X)
AttributeError: 'petsc4py.PETSc.KSP' object has no attribute 'matSolve'

Here is the code segment:

# Define a solver
        ksp_type = getattr(PETSc.KSP.Type, petsc_options["ksp_type"])
        pc_type = getattr(PETSc.PC.Type, petsc_options["pc_type"])
        solver = PETSc.KSP().create(self.comm)
        if "fs_type" in petsc_options.keys():
            fs_type = getattr(PETSc.Mat.SolverType, petsc_options["fs_type"])
            solver.getPC().setFactorSolverType(fs_type)  # Set the solver package used to perform the factorization.
        solver.getPC().setReusePreconditioner(True)  # Set up the reuse Preconditioner
        for i, B in enumerate(pload):
            X = B.copy()
            solver.matSolve(B, X)

where pload is a list of PETSc.Mat.

Your petsc4py is too old: petsc4py: add interface to KSPMatSolve() (5d1e342f) · Commits · PETSc / petsc · GitLab says that you need to have 3.19+ to have that function available.

You are probably using an old version of ubuntu. We don’t necessary release the latest dolfinx package (and its dependencies, including petsc4py) to old ubuntu versions. Considering that ubuntu 24.04 was released these days, and we will soon upload dolfinx 0.8.0 there, your best bet is to upgrade your ubuntu version.

My current installation of dolfinx is V0.7.3, and the official website says it’s already the latest version. Do you mean that I can use the higher version of petsc4py by upgrading Ubuntu (right now my version is 22.04) or do I have to wait until you release dolfinx 0.8.0 on Ubuntu 24.04 to use the higher version of petsc4py.

I have installded Ubutun 24.04, but can not install fenicsx on it.

We have a pre-release of 0.8.0, the official one will be out in the next few days, although I can’t state a precise ETA.

Thank you. I have uninstalled Ubutun 22.04, and installed 24.04.However, I can not install fenicsx using the following command:

add-apt-repository ppa:fenics-packages/fenics
apt update
apt install fenicsx

Is it caused by Ubutun 24.04, if so, do I still have to reinstall the old version of Ubutun if I want to install fenicsx?

Try with apt install python3-dolfinx, it should install the version 1:0.8.0~git20240411.cd10d4e-5~ppa1~noble3 (i.e., the pre-release that I was mentioning before).

We will investigate with @dparsons why the metapackage fenicsx is missing.

Ubuntu 24.04 is too new (it has literally only just been released). The PPA has not been updated for it yet. Unfortunately issues with adios2 prevented ubuntu from completing its own native build of the packages. That said, python3-dolfinx (not fenicsx) should install from the PPA.