tests – Tests

  • class theano.tests.breakpoint.PdbBreakpoint(name)[source]
  • This is an identity-like op with the side effect of enforcing aconditional breakpoint, inside a theano function, based on a symbolicscalar condition.

Parameters: name (String) – name of the conditional breakpoint. To be printed when thebreakpoint is activated. Note: WARNING. At least one of the outputs of the op must be usedotherwise the op will be removed from the Theano graphdue to its outputs being unused Note:

  • WARNING. Employing the function inside a theano graph can prevent
  • Theano from applying certain optimizations to improveperformance, reduce memory consumption and/or reducenumerical instability.

Detailed explanation:As of 2014-12-01 the PdbBreakpoint op is not known by anyoptimization. Setting a PdbBreakpoint op in the middle of apattern that is usually optimized out will block the optimization.

Example:

  1. import theano
  2. import theano.tensor as T
  3. from theano.tests.breakpoint import PdbBreakpoint
  4.  
  5. input = T.fvector()
  6. target = T.fvector()
  7.  
  8. # Mean squared error between input and target
  9. mse = (input - target) ** 2
  10.  
  11. # Conditional breakpoint to be activated if the total MSE is higher
  12. # than 100. The breakpoint will monitor the inputs, targets as well
  13. # as the individual error values
  14. breakpointOp = PdbBreakpoint("MSE too high")
  15. condition = T.gt(mse.sum(), 100)
  16. mse, monitored_input, monitored_target = breakpointOp(condition, mse,
  17. input, target)
  18.  
  19. # Compile the theano function
  20. fct = theano.function([input, target], mse)
  21.  
  22. # Use the function
  23. print fct([10, 0], [10, 5]) # Will NOT activate the breakpoint
  24. print fct([0, 0], [10, 5]) # Will activate the breakpoint