petsc4py and python's logging module
Dear all, is it possible to use python's logging module (https://docs.python.org/2/howto/logging.html) to handle PETSc output in python, such as the residuals during a KSP/SNES solve? I log my solver's activity to a file using the logging module, it would be great to include the PETSc output aswell. Regards, David
On Mon, May 29, 2017 at 11:17 AM, David Nolte <[email protected]> wrote:
Dear all,
is it possible to use python's logging module (https://docs.python.org/2/howto/logging.html) to handle PETSc output in python, such as the residuals during a KSP/SNES solve? I log my solver's activity to a file using the logging module, it would be great to include the PETSc output aswell.
I think the best way to do this is the following: 1) Create a PetscViewer implementation, say PyASCII, that logs to the Python descriptor. This might be as easy as just augmenting the ASCII viewer to grab this descriptor on creation 2) Then you can hook this viewer to the monitor using options -ksp_monitor pyascii Thanks, Matt
Regards, David
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener http://www.caam.rice.edu/~mk51/
On 29 May 2017 at 19:17, David Nolte <[email protected]> wrote:
Dear all,
is it possible to use python's logging module (https://docs.python.org/2/howto/logging.html) to handle PETSc output in python, such as the residuals during a KSP/SNES solve? I log my solver's activity to a file using the logging module, it would be great to include the PETSc output aswell.
Not sure if this is what you really want, but you could... 1) Use {ksp|snes}.setConvergenceHistory() before solve, then {ksp|snes}.getConvergenceHistory() after solve, you will get arrays with the residual history, then you can do whatever you want with them. 2) Implement a KSP/SNES monitor in a Python function and call {ksp|snes}.setMonitor(), then you can use python's logging inside your monitor function. -- Lisandro Dalcin ============ Research Scientist Computer, Electrical and Mathematical Sciences & Engineering (CEMSE) Extreme Computing Research Center (ECRC) King Abdullah University of Science and Technology (KAUST) http://ecrc.kaust.edu.sa/ 4700 King Abdullah University of Science and Technology al-Khawarizmi Bldg (Bldg 1), Office # 0109 Thuwal 23955-6900, Kingdom of Saudi Arabia http://www.kaust.edu.sa Office Phone: +966 12 808-0459
If you want to log all PETSc ASCII output you can use http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscVFPrint... Just don't use the FILE *fd initial argument, instead pass the output into a Python function that calls the logger as desired. Barry
On May 29, 2017, at 11:17 AM, David Nolte <[email protected]> wrote:
Dear all,
is it possible to use python's logging module (https://docs.python.org/2/howto/logging.html) to handle PETSc output in python, such as the residuals during a KSP/SNES solve? I log my solver's activity to a file using the logging module, it would be great to include the PETSc output aswell.
Regards, David
participants (4)
-
Barry Smith -
David Nolte -
Lisandro Dalcin -
Matthew Knepley