TensorFlow graph construction

The TensorGraph class manages all the data and build processes associated with the TensorFlow graph. The TensorFlow graph is the symbolic description of the computations in the network, which will be executed by the simulator.

class nengo_dl.tensor_graph.TensorGraph(model, dt, step_blocks, unroll_simulation, dtype, minibatch_size, device)[source]

Manages the construction of the Tensorflow symbolic computation graph.

Parameters:
model : Model

pre-built Nengo model describing the network to be simulated

dt : float

length of a simulator timestep, in seconds

step_blocks : int

controls how many simulation steps run each time the graph is executed (affects memory usage and graph construction time)

unroll_simulation : bool

if True, unroll simulation loop by explicitly building each iteration (up to step_blocks) into the computation graph. if False, use a symbolic loop, which is more general and produces a simpler graph, but is likely to be slower to simulate

dtype : tf.DType

floating point precision to use for simulation

minibatch_size : int

the number of simultaneous inputs that will be passed through the network

device : None or "/cpu:0" or "/gpu:[0-n]"

device on which to execute computations (if None then uses the default device as determined by Tensorflow)

build(rng)[source]

Constructs a new graph to simulate the model.

Parameters:
rng : RandomState

the Simulator’s random number generator

build_step()[source]

Build the operators that execute a single simulation timestep into the graph.

Returns:
probe_tensors : list of tf.Tensor

the Tensor objects representing the data required for each model Probe

side_effects : list of tf.Tensor

the output Tensors of computations that may have side-effects (e.g., Node functions), meaning that they must be executed each time step even if their output doesn’t appear to be used in the simulation

build_loop()[source]

Build simulation loop.

Loop can be constructed using the tf.while_loop architecture, or explicitly unrolled. Unrolling increases graph construction time and memory usage, but increases simulation speed.

build_inputs(rng)[source]

Sets up the inputs in the model (which will be computed outside of Tensorflow and fed in each simulation block).

Parameters:
rng : RandomState

the Simulator’s random number generator

build_optimizer(optimizer, targets, objective)[source]

Adds elements into the graph to execute the given optimizer.

Parameters:
optimizer : tf.train.Optimizer

instance of a Tensorflow optimizer class

targets : list of Probe

the Probes corresponding to the output signals being optimized

objective : "mse" or callable

the objective to be minimized. passing "mse" will train with mean squared error. a custom function f(output, target) -> loss can be passed that consumes the actual output and target output for a probe in targets and returns a tf.Tensor representing the scalar loss value for that Probe (loss will be averaged across Probes).

build_loss(objective, targets)[source]

Adds elements into the graph to compute the given objective.

Parameters:
objective : "mse" or callable

the objective used to compute loss. passing "mse" will use mean squared error. a custom function f(output, target) -> loss can be passed that consumes the actual output and target output for a probe in targets and returns a tf.Tensor representing the scalar loss value for that Probe (loss will be averaged across Probes).

targets : list of Probe

the Probes corresponding to target values in objective