Opened 4 years ago

Closed 4 years ago

#20376 closed enhancement (fixed)

LoggingBackend - delegating MIP backend class that logs input/output to backend methods

Reported by: mkoeppe Owned by:
Priority: major Milestone: sage-7.2
Component: numerical Keywords: lp
Cc: dimpase, vdelecroix, vbraun, nthiery Merged in:
Authors: Matthias Koeppe Reviewers: Dima Pasechnik
Report Upstream: N/A Work issues:
Branch: f17cd9b (Commits) Commit: f17cd9b799125912f098e541e950f1374674e6ca
Dependencies: #20406, #20323 Stopgaps:

Description (last modified by mkoeppe)

This is a debugging tool. It logs calls to the methods of MIP backends.

There are three output formats:

  • on-screen comments
  • doctests, suitable for cut and paste
  • _test_* methods for the backends (#20323).

I have already used this code to translate the testcase using the MixedIntegerLinearProgram reported in #18572 to a testcase in the style of the _test_* methods for the backends. The result has been committed on #20424 .

Change History (26)

comment:1 Changed 4 years ago by mkoeppe

  • Branch set to u/mkoeppe/loggingbackend___delegating_mip_backend_class_that_logs_input_output_to_backend_methods

comment:2 Changed 4 years ago by git

  • Commit set to e7ef1eab2afffb239b253b354cdebff8965af13c

Branch pushed to git repo; I updated commit sha1. New commits:

756015fLoggingBackend: add test method writer
a9535a7Use assertAlmostEqual for float; don't log zero and base_ring
e7ef1eaAdd doctest

comment:3 Changed 4 years ago by mkoeppe

  • Cc dimpase vdelecroix vbraun nthiery added
  • Dependencies set to #20406, #20323
  • Description modified (diff)

The branch is on top of #20406. The _test methods that this class generates mimic the ones written in #20323, which is why I mark it as a dependency.

comment:4 Changed 4 years ago by git

  • Commit changed from e7ef1eab2afffb239b253b354cdebff8965af13c to 4983cc757f72093976d2dfc83beb37be71add00e

Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:

d1d84c6get_solver: Add doctest
cc2d999Mention solver=callable in docstrings and error messages
37e87a5Replace delsarte test by one that does not expose a bug in GLPK exact
2b0626fFirst attempt at LoggingBackend
4e5c439This is as far as we get with __getattr__
5282a79LoggingBackend: Inherit from GenericBackend, override methods
deedc16LoggingBackend: add test method writer
cc845f7Use assertAlmostEqual for float; don't log zero and base_ring
2f4b58cAdd doctest
4983cc7Fix docstring

comment:5 Changed 4 years ago by mkoeppe

  • Description modified (diff)
  • Status changed from new to needs_review

rebased on top of current #20406.

comment:6 Changed 4 years ago by mkoeppe

  • Authors set to Matthias Koeppe

comment:7 Changed 4 years ago by dimpase

it would be great to have a concrete explained example in the docs like "suppose we want to test that foo does baz. Then we..."

comment:8 Changed 4 years ago by git

  • Commit changed from 4983cc757f72093976d2dfc83beb37be71add00e to 12261790b750b1757e6d958c6fa3b6d3e0f5b548

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

632e81dFirst attempt at LoggingBackend
3c96d9fThis is as far as we get with __getattr__
123c066LoggingBackend: Inherit from GenericBackend, override methods
8c2612dLoggingBackend: add test method writer
9c69834Use assertAlmostEqual for float; don't log zero and base_ring
422226cAdd doctest
b66cd6dFix docstring
1226179Add more documentation and examples

comment:9 Changed 4 years ago by mkoeppe

I've added a better example.

comment:10 Changed 4 years ago by dimpase

there is no trace of this backend in the docs. You probably want to add it to some index in an rst file...

comment:11 Changed 4 years ago by git

  • Commit changed from 12261790b750b1757e6d958c6fa3b6d3e0f5b548 to a2217679f53c50dc44bab546de982b7b8d841ad9

Branch pushed to git repo; I updated commit sha1. New commits:

cea8e06Add logging_backend to documentation index
a221767Use print_function and output get_solver calls too

comment:12 Changed 4 years ago by mkoeppe

Thanks for the reminder; I've added it to the documentation index.

comment:13 Changed 4 years ago by dimpase

in

call `compute_something` in the doctest

compute_something is being typeset in the doc as a maths expression. I guess it needs :func: prefix.

As well, after EXAMPLES there is a long list

add_col(*args, **kwdargs)
add_linear_constraint(*args, **kwdargs)
...
write_mps(*args, **kwdargs)

Is it how it is meant to look?

comment:14 Changed 4 years ago by git

  • Commit changed from a2217679f53c50dc44bab546de982b7b8d841ad9 to b1db4dced251560e239b2ad2d21d4423b4e819fe

Branch pushed to git repo; I updated commit sha1. New commits:

b1db4dcImprovement for generated documentation

comment:15 follow-up: Changed 4 years ago by mkoeppe

I've fixed the markup of that function, actually using double-backquotes.

The long list is a list of all instrumented methods that comes from the backend. I don't know if it should be suppressed, and if yes, how. I also don't know how to remove the strange stuff at the very bottom of that page.

comment:16 Changed 4 years ago by dimpase

patchbots complain

Missing doctests in numerical/backends/logging_backend.py: 1 / 5 = 20%

comment:17 in reply to: ↑ 15 Changed 4 years ago by dimpase

Replying to mkoeppe:

The long list is a list of all instrumented methods that comes from the backend. I don't know if it should be suppressed, and if yes, how.

You can place .. auto*** directives in the docstrings of classes; although I don't exactly know how to achieve what we want. See the doc here: http://www.sphinx-doc.org/en/stable/ext/autodoc.html#confval-autoclass_content

and there are examples in src/sage/ doing something like this: grep -R "\.\. auto" * will show a lot...

I also don't know how to remove the strange stuff at the very bottom of that page.

no idea either...

comment:18 Changed 4 years ago by git

  • Commit changed from b1db4dced251560e239b2ad2d21d4423b4e819fe to 879c033b7bc5b245e19e7fc041ce487968fe6bac

Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:

d39dfdeLoggingBackend: Inherit from GenericBackend, override methods
028c64fLoggingBackend: add test method writer
9df27fdUse assertAlmostEqual for float; don't log zero and base_ring
9408e50Add doctest
dd95cb9Fix docstring
0d2e9d9Add more documentation and examples
07bd122Add logging_backend to documentation index
b69f62dUse print_function and output get_solver calls too
9fbba6dImprovement for generated documentation
879c033Add documentation to wrappers and clean up namespace. Fixes generated documentation

comment:19 Changed 4 years ago by mkoeppe

Found a solution for the documentation.

comment:20 Changed 4 years ago by git

  • Commit changed from 879c033b7bc5b245e19e7fc041ce487968fe6bac to a5498426bfadc8ac824861a40a0a50e9bb2f8c11

Branch pushed to git repo; I updated commit sha1. New commits:

a549842Add doctests

comment:21 Changed 4 years ago by git

  • Commit changed from a5498426bfadc8ac824861a40a0a50e9bb2f8c11 to 05c6c38bc47b186437b021581d63f8696c19156c

Branch pushed to git repo; I updated commit sha1. New commits:

05c6c38Faking the base_ring

comment:22 Changed 4 years ago by git

  • Commit changed from 05c6c38bc47b186437b021581d63f8696c19156c to f17cd9b799125912f098e541e950f1374674e6ca

Branch pushed to git repo; I updated commit sha1. New commits:

f17cd9bLoggingBackendFactory: Make the interface more user-friendly

comment:23 Changed 4 years ago by dimpase

  • Reviewers set to Dima Pasechnik
  • Status changed from needs_review to positive_review

looks good to me. By the way, you use deprecated db() stuff. Are you going to undo #2536 ?

comment:24 Changed 4 years ago by mkoeppe

I'm not using it. The LoggingBackend simply instruments every method that the backend has, including stuff that I never heard of or that was deprecated a decade ago.

comment:25 Changed 4 years ago by dimpase

Ah, OK, never mind then (I had a quick look at generated docs, and saw that db() there...)

comment:26 Changed 4 years ago by vbraun

  • Branch changed from u/mkoeppe/loggingbackend___delegating_mip_backend_class_that_logs_input_output_to_backend_methods to f17cd9b799125912f098e541e950f1374674e6ca
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.