tests – Tests

class theano.tests.breakpoint.PdbBreakpoint(name)[source]

This is an identity-like op with the side effect of enforcing a conditional breakpoint, inside a theano function, based on a symbolic scalar condition.

Parameters:

name (String) – name of the conditional breakpoint. To be printed when the breakpoint is activated.

Note:

WARNING. At least one of the outputs of the op must be used otherwise the op will be removed from the Theano graph due to its outputs being unused

Note:
WARNING. Employing the function inside a theano graph can prevent

Theano from applying certain optimizations to improve performance, reduce memory consumption and/or reduce numerical instability.

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

Example:

import theano
import theano.tensor as T
from theano.tests.breakpoint import PdbBreakpoint

input = T.fvector()
target = T.fvector()

# Mean squared error between input and target
mse = (input - target) ** 2

# Conditional breakpoint to be activated if the total MSE is higher
# than 100. The breakpoint will monitor the inputs, targets as well
# as the individual error values
breakpointOp = PdbBreakpoint("MSE too high")
condition = T.gt(mse.sum(), 100)
mse, monitored_input, monitored_target = breakpointOp(condition, mse,
                                                      input, target)

# Compile the theano function
fct = theano.function([input, target], mse)

# Use the function
print fct([10, 0], [10, 5]) # Will NOT activate the breakpoint
print fct([0, 0], [10, 5]) # Will activate the breakpoint