[petsc-users] Options database in petsc4py

Pierre Jolivet pierre at joliv.et
Mon Oct 27 05:08:13 CDT 2025



> On 27 Oct 2025, at 10:49 AM, SCOTTO Alexandre via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> In if this is a bug, I think the fix you proposed should also be applied to the destroy() method, as it does not clear the database either.

Yes, it was under my radar, see https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/8812/diffs__;!!G_uCfscf7eWS!bpR5xoqEEZODT3ldlupKuT0SLPS13FfAmILqjeIji7MVoNK9BGluc0PWAB3HllK1KvjANwLcl90jUg0rveJhRw$ 
There is still one check of self.opt == NULL that I’m not sure whether it should be there, but it’s orthogonal to the issue at end.

Thanks,
Pierre

> Regards,
> Alexandre.
>  
> De : Pierre Jolivet <pierre at joliv.et>
> Envoyé : lundi 27 octobre 2025 10:36
> À : SCOTTO Alexandre <alexandre.scotto at irt-saintexupery.com>
> Cc : petsc-users at mcs.anl.gov
> Objet : Re: [petsc-users] Options database in petsc4py
>  
> I would say this is a bug in petsc4py, the following diff should fix this.
> I’m not sure why this if is there, as it’s perfectly valid to call PetscOptionsClear(NULL).
>  
> Thanks,
> Pierre
>  
> diff --git a/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx b/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx
> index 4db3c52f022..8a923a6dd8e 100644
> --- a/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx
> +++ b/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx
> @@ -90,7 +90,6 @@ cdef class Options:
>  
>      def clear(self) -> Self:
>          """Clear an options database."""
> -        if self.opt == NULL: return
>          CHKERR(PetscOptionsClear(self.opt))
>          return self
> 
> 
> On 27 Oct 2025, at 10:23 AM, SCOTTO Alexandre via petsc-users <petsc-users at mcs.anl.gov <mailto:petsc-users at mcs.anl.gov>> wrote:
>  
> Dear PETSc Community,
>  
> In my developments, I am managing possibly several KSP solvers with options handled by the Options database. During my tests, I encountered the following behavior:
>  
> Code:
> options = PETSc.Options("ksp_")
> options.setValue("atol", 7e-8)
> options.view()
>  
> options.clear()
> options.view()
>  
> Output:
> #PETSc Option Table entries:
> -ksp_atol 7e-08 # (source: code)
> #End of PETSc Option Table entries
>  
> #PETSc Option Table entries:
> -ksp_atol 7e-08 # (source: code)
> #End of PETSc Option Table entries
>  
> It seems that the clear() method does not really clear the Option database. To ensure that the several KSP I deal with are set with their own options (without getting options from a KSP previously set), the only way I found was to explicitly call the delValue() method for all the option keys passed:
>  
> 1.       Iterate over a dictionary of options and use setValue(name, value)
> 2.       Set the KSP with option database: KSP.setFromOptions()
> 3.       Iterate over a the keys of the dictionary and use delValue(name) to effectively clear the option database.
>  
> Does it seem normal to you, is there something I am missing out?
>  
> Regards,
> Alexandre Scotto.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20251027/cb0fdc6d/attachment-0001.html>


More information about the petsc-users mailing list