brainpy.base module#

The base module for whole BrainPy ecosystem.

  • This module provides the most fundamental class Base, and its associated helper class Collector and ArrayCollector.

  • For each instance of “Base” class, users can retrieve all the variables (or trainable variables), integrators, and nodes.

  • This module also provides a Function class to wrap user-defined functions. In each function, maybe several nodes are used, and users can initialize a Function by providing the nodes used in the function. Unfortunately, Function class does not have the ability to gather nodes automatically.

  • This module provides io helper functions to help users save/load model states, or share user’s customized model with others.

  • This module provides naming tools to guarantee the unique nameing for each Base object.

Details please see the following.

Base Class#

Base([name])

The Base class for whole BrainPy ecosystem.

Function Wrapper#

Function(f[, nodes, dyn_vars, name])

The wrapper for Python functions.

Collectors#

Collector

A Collector is a dictionary (name, var) with some additional methods to make manipulation of collections of variables easy.

TensorCollector

A ArrayCollector is a dictionary (name, var) with some additional methods to make manipulation of collections of variables easy.

Exporting and Loading#

save_as_h5(filename, variables)

Save variables into a HDF5 file.

save_as_npz(filename, variables[, compressed])

Save variables into a numpy file.

save_as_pkl(filename, variables)

Save variables into a pickle file.

save_as_mat(filename, variables)

Save variables into a HDF5 file.

load_by_h5(filename, target[, verbose])

Load variables in a HDF5 file.

load_by_npz(filename, target[, verbose])

Load variables from a numpy file.

load_by_pkl(filename, target[, verbose])

Load variables from a pickle file.

load_by_mat(filename, target[, verbose])

Load variables from a numpy file.

SUPPORTED_FORMATS

Built-in mutable sequence.

Naming Tools#

check_name_uniqueness(name, obj)

Check the uniqueness of the name for the object type.

get_unique_name(type_)

Get the unique name for the given object type.

clear_name_cache()

Clear the cached names.