<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;"><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On 27 Oct 2025, at 10:49 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: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">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.</span></div></div></div></blockquote><div><br></div><div>Yes, it was under my radar, see <a href="https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/8812/diffs__;!!G_uCfscf7eWS!bpR5xoqEEZODT3ldlupKuT0SLPS13FfAmILqjeIji7MVoNK9BGluc0PWAB3HllK1KvjANwLcl90jUg0rveJhRw$">https://gitlab.com/petsc/petsc/-/merge_requests/8812/diffs</a></div><div>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.</div><div><br></div><div>Thanks,</div><div>Pierre</div><br><blockquote type="cite"><div><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: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Regards,<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Alexandre.<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><o:p> </o:p></span></div><div><div style="border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(225, 225, 225) currentcolor currentcolor; border-image: none; padding: 3pt 0cm 0cm;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><b><span lang="FR" style="font-size: 11pt; font-family: Calibri, sans-serif;">De :</span></b><span lang="FR" style="font-size: 11pt; font-family: Calibri, sans-serif;"><span class="Apple-converted-space"> </span>Pierre Jolivet <pierre@joliv.et><br><b>Envoyé :</b><span class="Apple-converted-space"> </span>lundi 27 octobre 2025 10:36<br><b>À :</b><span class="Apple-converted-space"> </span>SCOTTO Alexandre <alexandre.scotto@irt-saintexupery.com><br><b>Cc :</b><span class="Apple-converted-space"> </span>petsc-users@mcs.anl.gov<br><b>Objet :</b><span class="Apple-converted-space"> </span>Re: [petsc-users] Options database in petsc4py<o:p></o:p></span></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">I would say this is a bug in petsc4py, the following diff should fix this.<o:p></o:p></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">I’m not sure why this if is there, as it’s perfectly valid to call PetscOptionsClear(NULL).<o:p></o:p></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><o:p> </o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">Thanks,<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">Pierre<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><o:p> </o:p></div></div><div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">diff --git a/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx b/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">index 4db3c52f022..8a923a6dd8e 100644<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">--- a/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">+++ b/src/binding/petsc4py/src/petsc4py/PETSc/Options.pyx<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">@@ -90,7 +90,6 @@ cdef class Options:<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"> <o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"> def clear(self) -> Self:<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"> """Clear an options database."""<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">- if self.opt == NULL: return<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"> CHKERR(PetscOptionsClear(self.opt))<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"> return self<o:p></o:p></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><br><br><o:p></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;"><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;">On 27 Oct 2025, at 10:23 AM, SCOTTO Alexandre via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" style="color: rgb(149, 79, 114); text-decoration: underline;">petsc-users@mcs.anl.gov</a>> wrote:<o:p></o:p></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><o:p> </o:p></div><div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;">Dear PETSc Community,<o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;"> <o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="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></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;"> <o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><b><span style="font-size: 11pt; font-family: Calibri, sans-serif;">Code</span></b><span style="font-size: 11pt; font-family: Calibri, sans-serif;">:<o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">options = PETSc.Options("ksp_")</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">options.setValue("atol", 7e-8)</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">options.view()</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;"> </span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">options.clear()</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">options.view()</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;"> <o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><b><span style="font-size: 11pt; font-family: Calibri, sans-serif;">Output</span></b><span style="font-size: 11pt; font-family: Calibri, sans-serif;">:<o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">#PETSc Option Table entries:</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span lang="FR" style="font-size: 11pt; font-family: "Courier New"; background: silver;">-ksp_atol 7e-08 # (source: code)</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">#End of PETSc Option Table entries</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;"> </span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">#PETSc Option Table entries:</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">-ksp_atol 7e-08 # (source: code)</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">#End of PETSc Option Table entries</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: "Courier New";"> </span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;">It seems that the<span class="apple-converted-space"> </span></span><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">clear()</span><span class="apple-converted-space"><span style="font-size: 11pt; font-family: Calibri, sans-serif;"> </span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif;">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><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">delValue()</span><span class="apple-converted-space"><span style="font-size: 11pt; font-family: Calibri, sans-serif;"> </span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif;">method for all the option keys passed:<o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;"> <o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif; text-indent: -18pt;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;">1.</span><span style="font-size: 7pt;"> <span class="apple-converted-space"> </span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif;">Iterate over a dictionary of options and use<span class="apple-converted-space"> </span></span><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">setValue(name, value)</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif; text-indent: -18pt;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;">2.</span><span style="font-size: 7pt;"> <span class="apple-converted-space"> </span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif;">Set the KSP with option database:<span class="apple-converted-space"> </span></span><span style="font-size: 11pt; font-family: "Courier New"; background: silver;">KSP.setFromOptions()</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;"><o:p></o:p></span></div></div><div style="margin-left: 36pt;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif; text-indent: -18pt;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;">3.</span><span style="font-size: 7pt;"> <span class="apple-converted-space"> </span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif;">Iterate over a the keys of the dictionary and<span class="apple-converted-space"> </span></span><span style="font-size: 11pt; 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 style="font-size: 11pt; font-family: Calibri, sans-serif;"> </span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif;">to effectively clear the option database.<o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;"> <o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="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></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;"> <o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;">Regards,<o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman", serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif;">Alexandre Scotto.</span></div></div></div></blockquote></div></div></div></div></div></blockquote></div><br></body></html>