tests – Tests

class theano.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. It automatically detects available debuggers and uses the first available in the following order: pudb, ipdb, or pdb.

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 tt
from theano.breakpoint import PdbBreakpoint

input = tt.fvector()
target = tt.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 = tt.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
grad(inputs, output_gradients)[source]

Construct a graph for the gradient with respect to each input variable.

Each returned Variable represents the gradient with respect to that input computed based on the symbolic gradients with respect to each output. If the output is not differentiable with respect to an input, then this method should return an instance of type NullType for that input.

Parameters
  • inputs (list of Variable) – The input variables.

  • output_grads (list of Variable) – The gradients of the output variables.

Returns

grads – The gradients with respect to each Variable in inputs.

Return type

list of Variable

make_node(condition, *monitored_vars)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, output_storage)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters
  • node (Apply) – The symbolic Apply node that represents this computation.

  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.

  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.

  • params (tuple) – A tuple containing the values of each entry in __props__.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a NumPy ndarray with the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this PureOp.perform; they could’ve been allocated by another PureOp’s perform method. A PureOp is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

Raises

MethodNotDefined – The subclass does not override this method.