[petsc-dev] -snes_check_jacobian

Peter Brune prbrune at gmail.com
Thu Dec 13 17:22:27 CST 2012


On Thu, Dec 13, 2012 at 5:10 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
> On Dec 13, 2012, at 5:04 PM, Peter Brune <prbrune at gmail.com> wrote:
>
> > Dangit Barry!  I already started a patch moving all Jed's
> -snes_compare_* garbage in SNESComputeJacobian() over to a
> SNESJacobianMonitor registration type deal where it has functions you can
> register to run after computing the Jacobian.  This will allow you to do
> all sorts of nice comparisons.
>
>   Dang it we don't need yet another registration thingy, I used the
> SNESSetUpdate() hook.
>
>
  Actually I don't mind if you do something better and remove mine (it is
> the story of my life) but don't remove mine until yours produces as pretty
> an output and has good names for the options and yes
> snes_compare_explicit is a terrible name. At least put jacobian in the
> option so I have some clue that it has something to do with the jacobian!
>
>
I agree, and this seems like a fine place for it to happen.  I'll have to
look at exactly what you did, but you could save a Jacobian computation if
you put it after the user Jacobian has been computed, which is why I was
putting it as hooks to be run at the end of SNESComputeJacobian().

I want similar facilities for the objectives as well.   There's already an
FD test objective in place (used by SNESTEST to verify if you have written
a proper objective -> function -> jacobian set).  If we had it so you could
register multiple tests (even in the update slot) we could provide a whole
suite of potential useful output without much work.

- Peter

  Barry
>
> >
> > Dangit Jed!  -snes_compare_* is a seeerious mess and shouldn't be in
> SNESComputeJacobian().  Barry's recent holy war against string comparisons
> will find this some day and there will be a lot of explaining to do.
> >
> > - Peter
> >
> >
> > On Thu, Dec 13, 2012 at 4:59 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
> > Surely you were aware of the -snes_compare_* options that can be
> activated in SNESComputeJacobian().
> >
> > Can we settle on one common way to do this testing and perhaps remove
> -snes_type test.
> >
> >
> > On Thu, Dec 13, 2012 at 2:55 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> >
> >    I got sick of -snes_type test only checking the Jacobian at the
> initial solution and not being able to test later Jacobians so I added
> -snes_check_jacobian that allows the regular running of SNESSolve() (also
> inside TS) and compares every Jacobian computed with a finite difference
> version.
> >
> >   For example, (already found one bug in one example :-(). This may be
> the best thing I've added to PETSc in a decade.
> >
> >    Barry
> >
> >
> > Barrys-MacBook-Pro:advection-diffusion-reaction barrysmith$ ./ex1
> -snes_check_jacobian -snes_monitor  -ts_type arkimex | more
> >     0 SNES Function norm 2.182384017537e+00
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >         Run with -snes_check_jacobian_display to show difference of
> hand-coded and finite difference Jacobian.
> >       1.68322e-09 = ||J - Jfd||//J|| 6.69028e-06  = ||J - Jfd||
> >     1 SNES Function norm 4.695397453383e-07
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >         Run with -snes_check_jacobian_display to show difference of
> hand-coded and finite difference Jacobian.
> >       2.45109e-09 = ||J - Jfd||//J|| 9.74235e-06  = ||J - Jfd||
> >     2 SNES Function norm 4.020379099215e-13
> >     0 SNES Function norm 6.799718390407e-01
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >         Run with -snes_check_jacobian_display to show difference of
> hand-coded and finite difference Jacobian.
> >       1.65487e-09 = ||J - Jfd||//J|| 6.5776e-06  = ||J - Jfd||
> >     1 SNES Function norm 4.558192078678e-08
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >         Run with -snes_check_jacobian_display to show difference of
> hand-coded and finite difference Jacobian.
> >       2.93714e-09 = ||J - Jfd||//J|| 1.16742e-05  = ||J - Jfd||
> >     2 SNES Function norm 9.907308296870e-14
> >     0 SNES Function norm 1.000842117652e+00
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >         Run with -snes_check_jacobian_display to show difference of
> hand-coded and finite difference Jacobian.
> >       1.24476e-09 = ||J - Jfd||//J|| 4.94755e-06  = ||J - Jfd||
> >     1 SNES Function norm 9.875108391772e-08
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >         Run with -snes_check_jacobian_display to show difference of
> hand-coded and finite difference Jacobian.
> >       1.10818e-10 = ||J - Jfd||//J|| 4.40468e-07  = ||J - Jfd||
> >     2 SNES Function norm 7.677760150017e-14
> >     0 SNES Function norm 2.179048757949e+00
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >         Run with -snes_check_jacobian_display to show difference of
> hand-coded and finite difference Jacobian.
> >       1.32338e-09 = ||J - Jfd||//J|| 5.27058e-07  = ||J - Jfd||
> >     1 SNES Function norm 4.625448863612e-05
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >         Run with -snes_check_jacobian_display to show difference of
> hand-coded and finite difference Jacobian.
> >       1.57582e-09 = ||J - Jfd||//J|| 6.27588e-07  = ||J - Jfd||
> >     2 SNES Function norm 4.391784647745e-14
> >     0 SNES Function norm 6.761591873515e-01
> >         Testing hand-coded Jacobian, if the ratio is O(1.e-8), the
> hand-coded Jacobian is probably correct.
> >
> >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20121213/d649e8fb/attachment.html>


More information about the petsc-dev mailing list