bmtk.simulator.dpointnet package#

Subpackages#

Submodules#

bmtk.simulator.dpointnet.callbacks module#

class bmtk.simulator.dpointnet.callbacks.Callbacks(rnn, callbacks_dir='callbacks_outputs', starting_epoch=0, verbose='full', time_fmt='%d-%m-%Y %H:%M', epoch_store_weights='best', epoch_cache_weights=False, epoch_cach_dir='weights', sonata_output_dir='trained_weights', losses_table_csv='losses.csv', performance_table_csv='performance.csv')[source]#

Bases: object

static find_path(callbacks_dir, path)[source]#
property n_epochs#
on_epoch_end(validation_losses)[source]#
on_epoch_start()[source]#
on_step_end(loss_vals)[source]#
on_step_start()[source]#
on_train_begin()[source]#
on_train_end(metrics=None, normalizers=None)[source]#
property steps_per_epoch#
property time#
class bmtk.simulator.dpointnet.callbacks.GPUMem(name, tf_current, tf_peak, gpu_used, gpu_free, gpu_total)#

Bases: tuple

gpu_free#

Alias for field number 4

gpu_total#

Alias for field number 5

gpu_used#

Alias for field number 3

name#

Alias for field number 0

tf_current#

Alias for field number 1

tf_peak#

Alias for field number 2

class bmtk.simulator.dpointnet.callbacks.Verbosity(*values)[source]#

Bases: IntEnum

full = 4#
on_epoch = 2#
on_step = 3#
on_train = 1#
quiet = 0#
bmtk.simulator.dpointnet.callbacks.add_callbacks(cls, name=None, overwrite=True)[source]#
bmtk.simulator.dpointnet.callbacks.get_gpu_memory(gpu_id=0)[source]#

Returns GPU memory usage in GiB using only nvidia-smi.

bmtk.simulator.dpointnet.callbacks.register_callbacks(cls=None, *_, name=None, overwrite=True)[source]#

bmtk.simulator.dpointnet.config module#

class bmtk.simulator.dpointnet.config.Config(*args, **kwargs)[source]#

Bases: SimulationConfig

bmtk.simulator.dpointnet.data_iterator module#

class bmtk.simulator.dpointnet.data_iterator.DataIterator(input_mods, batch_size, seq_len, ordered_populations=None, fetch_in_graph=False)[source]#

Bases: object

build()[source]#
close()[source]#
next_spikes()[source]#

bmtk.simulator.dpointnet.id_maps module#

class bmtk.simulator.dpointnet.id_maps.TFIDMap[source]#

Bases: object

Main class used to map SONATA node_ids to tensorflow neuron ids (tf-ids)

This is a singleton class, meaning that for the lifespan of the Python interpreter run the mapping between node-ids and tf-ids will not change. TODO: Consider using Multion pattern that can be tied to each RNN instance.

Things this class must take care of. 1. tf-ids must start with 0 and be contigious. SONATA node_ids must be positive non-overlapping intergers,

but may have gaps and can be out-of-order.

  1. Recurrent nodes (eg. glif cells) must not have overlapping tf-ids. However in SONATA it is possible for a recurrent network to be made up of multiple populations with overlapping node-ids.

  2. Each input network (eg. virtual cell) must have tf-ids [0, n_input_cells]. As above this is not required for SONATA.

add_bmtk_ids(population_name, node_ids, network_type)[source]#
bmtk2tf_id_map(population_name)[source]#
recurrent_bmtk_ids(as_type='dict')[source]#
tf2bmtk_id_map(populations=None)[source]#

bmtk.simulator.dpointnet.io_tools module#

class bmtk.simulator.dpointnet.io_tools.RNNIOUtils[source]#

Bases: IOUtils

bmtk.simulator.dpointnet.network_adaptor module#

class bmtk.simulator.dpointnet.network_adaptor.CachedNetwork(name, file_path, network_type, file_format=None, **options)[source]#

Bases: NetworkAdaptor

get_nodes_df()[source]#
classmethod load_cache(file_path)[source]#
classmethod load_pickle(file_path)[source]#
property n_nodes#
to_dict()[source]#
class bmtk.simulator.dpointnet.network_adaptor.NetworkAdaptor(name, network_type, **options)[source]#

Bases: object

add_components_dirs(components_dirs=None)[source]#
add_edges(edges_pop)[source]#
build(**opt_args)[source]#
property connection_table#
filter_ids(**query)[source]#
static from_dict(networks_dict, allow_mixed_network=False)[source]#
static from_params(cache_file=None, network_type=None, network_name=None, file_format=None)[source]#
get_bmtk_ids(**filter)[source]#
get_nodes_df()[source]#
get_tf_ids(**filter)[source]#
property input_options#
property input_type#
static merge(networks)[source]#
property n_nodes#
property n_spiking_nodes#
property population_name#
property source_node_ids#
property source_tf_ids#
property target_node_ids#
property target_tf_ids#
to_dict()[source]#
class bmtk.simulator.dpointnet.network_adaptor.SONATANetwork(sonata_node_pop, network_type, cache_file=False, filter=None, **opt_args)[source]#

Bases: NetworkAdaptor

add_components_dirs(components_dirs=None)[source]#
add_edges(sonata_edge_pop)[source]#
get_bmtk_ids(**filter)[source]#
get_nodes_df()[source]#
get_tf_ids(**filter)[source]#
property md5hexsdigest#
property n_nodes#
classmethod reset_global_syn_id_mapping()[source]#

Reset the shared syn_id mapping (call before building a new model).

static split_up_virtual_nodes(sonata_node_pop)[source]#
to_dict()[source]#
bmtk.simulator.dpointnet.network_adaptor.lex_sort_indices_np(indices, *arrays)[source]#
bmtk.simulator.dpointnet.network_adaptor.lex_sort_order_np(indices)[source]#
bmtk.simulator.dpointnet.network_adaptor.sort_indices_tf(indices, *arrays)[source]#

bmtk.simulator.dpointnet.optimizers module#

class bmtk.simulator.dpointnet.optimizers.ExponentiatedAdam(*args: Any, **kwargs: Any)[source]#

Bases: Optimizer

Adam-like optimizer with exponentiated gradient updates.

This rewrites the final update from

w <- w - alpha * m / (sqrt(v) + epsilon)

to

w <- w * exp(- alpha * m / (sqrt(v) + epsilon) * sign(w)),

preserving the rest of the Adam algorithm (moments m, v, AMSGrad, etc.). By default, sign(0) = +1 so zero-valued parameters can still move off zero.

Sparse updates are applied consistently via scatter_mul() on the affected slices only.

Reference:
  • “Brain-like learning with exponentiated gradients” (and related papers).

  • The original Adam reference: [Kingma et al., 2014](http://arxiv.org/abs/1412.6980).

build(var_list)[source]#

Initialize optimizer variables.

Similar to Adam: we have slot variables for - m (first moment) - v (second moment) - vhat (if amsgrad=True, for the max of second moments).

get_config()[source]#
update_step(gradient, variable, learning_rate=None)[source]#

Update step given gradient and the associated model variable.

class bmtk.simulator.dpointnet.optimizers.LinearWarmupCosineDecay(*args: Any, **kwargs: Any)[source]#

Bases: LearningRateSchedule

Linear, warmpu followed by cosine decay.

get_config()[source]#
bmtk.simulator.dpointnet.optimizers.build_learning_rate(lr_schedule, **lr_params)[source]#
bmtk.simulator.dpointnet.optimizers.create_optimizer(optimizer, learning_rate, optimizer_params=None)[source]#
bmtk.simulator.dpointnet.optimizers.optimizer_supports_loss_scaling(optimizer)[source]#
bmtk.simulator.dpointnet.optimizers.scale_loss_for_optimizer(optimizer, loss)[source]#
bmtk.simulator.dpointnet.optimizers.unscale_gradients_for_optimizer(optimizer, gradients)[source]#

bmtk.simulator.dpointnet.results module#

class bmtk.simulator.dpointnet.results.RNNExtractorResults(seq_len, dt, batch_size, extractor_results)[source]#

Bases: object

static get_actual_path(output_dir, file_path)[source]#
property model_state#
save_results(**save_opts)[source]#
property spikes#
property voltages#

bmtk.simulator.dpointnet.rnn_model module#

class bmtk.simulator.dpointnet.rnn_model.Inference(rnn, name='inference', batch_size=None, seq_len=None)[source]#

Bases: object

close()[source]#
property data_itr#
property effective_batch_size#
property effective_seq_len#
get_initial_state()[source]#
class bmtk.simulator.dpointnet.rnn_model.RNN(seq_len=None, batch_size=None, dtype='float32', dt=1.0, default_seed=None, cell_cls=None, cell_params=None, **kwargs)[source]#

Bases: object

The primary model and simulation class for dpointnet.

This class is used to store and coordinate all the neccessary information to build, train, and run predctions on the GLIF Recurrent Neural Network model. Includes storing information about the original (sonata) network, the RNN model, and any spiking and state inputs used during training and prediction. It can also be used to extract weights and results from any previous training/predictions.

add_component(name, path)[source]#
add_inference(inference)[source]#
add_init_state(mod)[source]#
add_input(name, mod)[source]#
add_network(network, **args)[source]#
add_nodes(node_population)[source]#
property adjusted_batch_size#
property adjusted_seq_len#
build(rebuild=False, seq_len=None, dtype=tensorflow.float32, use_dummy_state_input=False, use_state_input=True, n_output=2, return_state=True, batch_size=None, **kwargs)[source]#
property cell#
cleanup()[source]#
classmethod from_config(config, **kwargs)[source]#
get_component(name)[source]#
get_init_state(state_names=None)[source]#
get_input_network(population_name)[source]#
get_inputs_mods(mod_names=None)[source]#
get_model_weights(trainable_only=False, deep_copy=True)[source]#
get_network(network_name)[source]#
get_recurrent_network()[source]#
has_component(name)[source]#
property inference#
property input_modules#
property input_populations#
property inputs_populations#
model_inputs(spikes, initial_state=None, state_inputs=None)[source]#
property node_populations#
property ordered_inputs_populations#
static parse_initial_states_from_config(network, json_config)[source]#
parse_input_mods_from_config(json_config)[source]#
property recurrent_network#
property rsnn_layer#
run()[source]#

A generic function to run a full execution of the RNN including building, training, running inference, and saving results (only training/inference/output parameters have been added to the RNN in the config or API).

This is primarily designed for use with the SONATA config, so that user may run:

$ python run_dpointnet.py config.json

and not have to change any of the python code - only the json file. For more grainular control you can call the build(…), train(…), and run_inference(…) function directly through the Python API.

run_extractor(spikes, initial_state)[source]#
run_inference(spikes=None, initial_state=None, inference=None, **kwargs)[source]#
set_training(training_engine=None, **training_params)[source]#
property state_only_model#
train(training_engine=None)[source]#
property training_engine#

bmtk.simulator.dpointnet.spikes_generator module#

bmtk.simulator.dpointnet.spikes_generator.add_background_noise(spikes_table, noise_rate, dt)[source]#
bmtk.simulator.dpointnet.spikes_generator.add_dropout(spikes_table, dropout_prob)[source]#
bmtk.simulator.dpointnet.spikes_generator.add_jitter(spikes_table, jitter_var, dt)[source]#
bmtk.simulator.dpointnet.spikes_generator.create_random_spikes_generator(network, firing_rate, seq_len, dt=1.0, dtype=tensorflow.float32)[source]#
bmtk.simulator.dpointnet.spikes_generator.sonata_spike_files_generator(network, spikes_paths, seq_len, dt=1.0, dtype=tensorflow.float32, cache_spikes_table=False, background_noise_rate=0.0, dropout_prob=0.0, jitter_var=0.0)[source]#

bmtk.simulator.dpointnet.tf_utils module#

bmtk.simulator.dpointnet.tf_utils.cleanup_tensorflow()[source]#
bmtk.simulator.dpointnet.tf_utils.enable_gpu_memory_growth()[source]#
bmtk.simulator.dpointnet.tf_utils.enable_tensorflow_optimizations(enabled=True)[source]#

Enable Grappler graph optimizations (matches the reference V1_GLIF_model).

The critical one for this model is loop_optimization: it performs loop-invariant code motion, hoisting the constant connectivity-variable reads (recurrent/LGN indices, weights, syn_ids) OUT of the RNN tf.while_loop body. Without it, TF re-reads those large tables every timestep and stacks them for the backward pass, which makes backward memory scale with seq_len and OOMs full-network training. min_graph_nodes=0 lets Grappler optimize the many small subgraphs in this model.

bmtk.simulator.dpointnet.tf_utils.get_precision_policy_and_dtype(_dtype)[source]#

Set TensorFlow mixed-precision policy and return the matching tf.DType. Supported values: float16, bfloat16, float32, float64

bmtk.simulator.dpointnet.training module#

class bmtk.simulator.dpointnet.training.InputsSignatureFactory(pnames, ordered_input_pops, ordered_input_mods)[source]#

Bases: object

class InputsSignature(lutables, ysigs)[source]#

Bases: object

get_value(population, name)[source]#
to_dataframe()[source]#
build(input_sigs)[source]#
class bmtk.simulator.dpointnet.training.TrainingEngine(rnn, n_epochs, steps_per_epoch, training_approach=None, **kwargs)[source]#

Bases: object

add_parameters(name, batch_size=None, seq_len=None)[source]#
property adjusted_batch_size#
property adjusted_seq_len#
property batch_indices#
property callbacks#
property init_state#
property inputs_signature_factory#
static merge_generators(spikes_generators)[source]#
property n_parameters#
property optimizer#
property parameters#
set_callbacks(callbacks)[source]#
set_init_state(init_state_mod)[source]#
set_learning_rate(learning_rate)[source]#
set_optimizer(optimizer)[source]#
property step_train_function#
train()[source]#
property training_approach#
class bmtk.simulator.dpointnet.training.TrainingParameters(name, batch_size=None, seq_len=None)[source]#

Bases: object

add_inputs_generator(name, input_mod)[source]#
add_loss_function(name, loss_mod)[source]#
get_inputs_generator(mod_name=None, population_name=None)[source]#
property input_generators#
property loss_functions#

bmtk.simulator.dpointnet.weights module#

class bmtk.simulator.dpointnet.weights.ModelWeights(rnn, cell, trainable_only=False, deep_copy=True)[source]#

Bases: object

property networks#
static parse_name(var_name)[source]#
to_dataframe(cache=False)[source]#
to_sonata(output_dir='.', single_file=False, overwrite=False)[source]#

Module contents#