TAO bindings in petsc4py

Issue #20 resolved
jefflarson created an issue

There are many PETSc bindings that are unavailable from within a running python program calling petsc4py. Some of them are fairly basic (likely desirable for many petsc4py users), some are not.

Question 1 If you want to limit the number of function evaluations performed by a PETSc optimization run, you can not use the TaoSetMaximumFunctionEvaluations function. But the tao.Reason() class DIVERGED_MAXFCN variable, so such a functionality can be achieved by defining:

def additional_convergence_test(tao):
    global pt_in_run, max_fevals_allowed
    if pt_in_run > max_fevals_allowed:
        tao.setConvergedReason(tao.Reason().DIVERGED_MAXFCN)

and later invoking:

tao.setConvergenceTest(additional_convergence_test)

and including:

...
global pt_in_run
pt_in_run += 1
...

in the declaration of the objective function. But one would think this unnecessary since TAO already has a TaoSetMaximumFunctionEvaluations function. Will all of the TAO functions eventually be exposed by petsc4py?

Question 2 Is it possible to append options to a TAO run after petsc4py is initialized? For example, I am running the TAO routine POUNDERs, which has a command line option of

-tao_pounders_delta 0.1

to set the starting delta to 0.1. In petsc4py, I can set it at initialization with

import petsc4py
petsc4py.init('-tao_pounders_delta 0.1')
from petsc4py import PETSc

Is there any way to adjust this value without restarting?

EDIT:

This last functionality exists, but not through a TAO command as I was assuming. The syntax is:

PETSc.Options().setValue('-tao_pounders_delta','0.1')

Comments (2)

  1. Log in to comment