EpsilonGreedy
EpsilonGreedy

Reputation: 83

Print values of constraint at each iteration during optimization

How can we do this from Pydrake? Print values of constraint at each iteration during optimization

EDIT 1:

I tried:

def update(n):
    print(n)

prog.AddVisualizationCallback(update, n)

in accordance with the example here at the bottom: https://github.com/RobotLocomotion/drake/blob/master/tutorials/debug_mathematical_program.ipynb

But it spat out this error:

    prog.AddVisualizationCallback(update, n)
TypeError: AddVisualizationCallback(): incompatible function arguments. The following argument types are supported:
    1. (self: pydrake.solvers.mathematicalprogram.MathematicalProgram, arg0: Callable[[numpy.ndarray[numpy.float64[m, 1]]], None], arg1: numpy.ndarray[object[m, 1]]) -> pydrake.solvers.mathematicalprogram.Binding[VisualizationCallback]

Upvotes: 0

Views: 143

Answers (1)

Russ Tedrake
Russ Tedrake

Reputation: 5533

Here are a few possibilities:

  • You can use AddVisualizationCallback to make effectively an empty generic constraint that gets called on each iteration.
  • You might also want to increase the solver verbosity level (see the “debugging mathematical programs” tutorial) so that the solver itself prints some progress info.
  • Depending on what sort of constraint you’re thinking about, you could potentially just implement the constraint itself as a python method (with a print statement inside) instead of whatever you’re doing to add it right now.

Upvotes: 2

Related Questions