Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS: solver callback function signatures insufficiently documented #3556

Open
connorjward opened this issue May 8, 2024 · 0 comments
Open

Comments

@connorjward
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant