<html aria-label="message body"><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">I would say this is a bug in petsc4py, the following diff should fix this.<div>I’m not sure why this if is there, as it’s perfectly valid to call PetscOptionsClear(NULL).<div><br></div><div>Thanks,</div><div>Pierre</div><div><br></div><div><div>diff --git a/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx b/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx</div><div>index 4db3c52f022..8a923a6dd8e 100644</div><div>--- a/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx</div><div>+++ b/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx</div><div>@@ -90,7 +90,6 @@ cdef class Options:</div><div> </div><div>     def clear(self) -> Self:</div><div>         """Clear an options database."""</div><div>-        if self.opt == NULL: return</div><div>         CHKERR(PetscOptionsClear(self.opt))</div><div>         return self</div><div><br><blockquote type="cite"><div>On 27 Oct 2025, at 10:23 AM, SCOTTO Alexandre via petsc-users <petsc-users@mcs.anl.gov> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Dear PETSc Community,<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">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:<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><b>Code</b>:<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">options = PETSc.Options("ksp_")<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">options.setValue("atol", 7e-8)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">options.view()<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;"><o:p> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">options.clear()<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">options.view()</span><span style="font-family: "Courier New";"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><b>Output</b>:<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">#PETSc Option Table entries:<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="FR" style="font-family: "Courier New"; background: silver;">-ksp_atol 7e-08 # (source: code)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">#End of PETSc Option Table entries<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;"><o:p> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">#PETSc Option Table entries:<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">-ksp_atol 7e-08 # (source: code)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New"; background: silver;">#End of PETSc Option Table entries</span><span style="font-family: "Courier New";"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-family: "Courier New";"><o:p> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">It seems that the<span class="Apple-converted-space"> </span><span style="font-family: "Courier New"; background: silver;">clear()</span><span class="Apple-converted-space"> </span>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<span class="Apple-converted-space"> </span><span style="font-family: "Courier New"; background: silver;">delValue()</span><span class="Apple-converted-space"> </span>method for all the option keys passed:<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: -18pt;"><span>1.<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-width: normal; font-size: 7pt; line-height: normal; font-family: "Times New Roman"; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-variant-emoji: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;">      <span class="Apple-converted-space"> </span></span></span>Iterate over a dictionary of options and use<span class="Apple-converted-space"> </span><span style="font-family: "Courier New"; background: silver;">setValue(name, value)</span><o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: -18pt;"><span>2.<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-width: normal; font-size: 7pt; line-height: normal; font-family: "Times New Roman"; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-variant-emoji: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;">      <span class="Apple-converted-space"> </span></span></span>Set the KSP with option database:<span class="Apple-converted-space"> </span><span style="font-family: "Courier New"; background: silver;">KSP.setFromOptions()</span><o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: -18pt;"><span>3.<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-width: normal; font-size: 7pt; line-height: normal; font-family: "Times New Roman"; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-variant-emoji: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;">      <span class="Apple-converted-space"> </span></span></span>Iterate over a the keys of the dictionary and<span class="Apple-converted-space"> </span><span style="font-family: "Courier New";">use<span class="Apple-converted-space"> </span><span style="background: silver;">delValue(name)</span></span><span class="Apple-converted-space"> </span>to effectively clear the option database.<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Does it seem normal to you, is there something I am missing out?<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Regards,<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Alexandre Scotto.</div></div></div></blockquote></div><br></div></div></body></html>