Skip to content

DOCS: solver callback function signatures insufficiently documented #3556

Open
@connorjward

Description

@connorjward

Variational solvers accept pre_ and post_ callback functions. The docstring for NonlinearVariationalSolver describes what the pre_ callbacks should look like:

        To use the ``pre_jacobian_callback`` or ``pre_function_callback``
        functionality, the user-defined function must accept the current
        solution as a petsc4py Vec. Example usage is given below:

        .. code-block:: python3

            def update_diffusivity(current_solution):
                with cursol.dat.vec_wo as v:
                    current_solution.copy(v)
                solve(trial*test*dx == dot(grad(cursol), grad(test))*dx, diffusivity)

            solver = NonlinearVariationalSolver(problem,
                                                pre_jacobian_callback=update_diffusivity)

But the post_ callbacks are not mentioned. This is confusing because the function signature for post_ callbacks is different to the pre_ ones. The post_jacobian_callback signature for instance looks like:

def callback(current_solution, J):
    ...

Using the wrong function signature causes the solver to terminate without a helpful error message.

It might be helpful to look at the test_custom_callbacks regression test to see intended usage.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions