generation
The generation, reading, processing of connection table. It’s mainly accelerated by multiprocessing and numba.
initialzie_params
make_block
The WBNN model presents the computational basis of the Digital twin brain(WBM) and is composed of two components: the basic computing unites and the network structure.
Generating logic can be basically broken down into the following two steps:
provide constructing information of population (minimum specific unit)
Weighted directed graph of connections between groups
The average degree of neurons in each population
The size scale of each population
Parameters of neuron model
Construct connections for each neuron based on the above information
- generation.make_block.add_debug(debug_block_dir, prop, conn, _dti_block_thresh, debug_idx_path, only_load)[source]
Add debug block to verify the accuracy of simulation with cuda program. Parameters.
- Parameters:
debug_block_dir (str) – the directory of small block which is used to verify accuracy of simulation.
_dti_block_thresh (ndarray) – number of neurons in each population.
debug_idx_path (ndarray) – debug idx in debug block.
only_load (bool) –
- generation.make_block.connect_for_multi_sparse_block(population_connect_prob, population_node_init_kwards=None, degree=1000, prefix=None, multi_conn2single_conn=False, dtype='single')[source]
Main api to generate connection table and save in npz file, if given information contain connection portability of populations, the average degree of neurons in each population, and The size scale of each population.
- Parameters:
population_connect_prob (Tensor or sparse.COO) – the connection probability of populations.
population_node_init_kwards (dict or list) – the information includes size information of each population. if dict, it’s information of one population and will broadcast to each population. if list, it mush be [dict, dict, ..] and contains each population information.
degree (ndarray or int) – specified degree of each population.
prefix (str or None) – specifies the way of generation, 1)writing to prefix 2) return a closure.
- generation.make_block.connect_for_single_sparse_block(population_idx, k, extern_input_rate, extern_input_k_sizes, degree=1000, s=0, e=-1, multi_conn2single_conn=False, dtype='single', sub_block_idx=None)[source]
For each population, we implement the detailed construction of connection table.
- Parameters:
population_idx (int) – the idx of processing population.
k (int) – the number of neurons in this population.
extern_input_rate (ndarray or sprse.COO) – the connection probability from others to itself.
extern_input_k_sizes (ndarray) – for those populations that need to connect here, the total number of neurons that can be sampled, that is their maximum total number of neurons.
degree (int) – number of in-degree for this population.
s (int) – start idx of neurons in this population.
e (int) – end idx of neurons in this population.
Notes
In the processing, we need to ensure that each source population can meet the sampling requirements of the target populaiton. If it is not met, we pop up the error and interrupt the processing. However, although the above requirements are met in terms of probability, a few samples may fail. In this case, we use some tricks to slightly adjust the degree requirements of this population. ——-
- generation.make_block.generate_block_node_property(size=1000, noise_rate=0.01, I_extern_Input=0, sub_block_idx=0, C=1, T_ref=5, g_Li=0.03, V_L=-75, V_th=-50, V_reset=-65, g_ui=(0.01818181818181818, 0.00125, 0.1, 0.00410958904109589), V_ui=(0, 0, -70, -100), tao_ui=(2, 40, 10, 50), s=0, e=-1)[source]
Generate neuronal property for each population.
- Parameters:
noise_rate (float) – different neuron have a background noise, its output spike is calculated as spike | noise.
I_extern_Input (float) – external current to each neuron
sub_block_idx (float) – population idx
C (float) – capacitance
T_ref (float) – refractory time
g_Li (float) – conductance of leaky channel
V_L (float) – leaky potential
V_th (float) – threshold potential
V_reset (float) – reset potential
g_ui (tuple[float, ]) – conductance of 4 synaptic channels
V_ui (tuple[float, ]) – reverse potential of 4 synaptic channels
tao_ui (tuple[float, ]) – timescale of exponential synaptic filter.
s (int) – start index
e (int) – end indext
- Returns:
property – property of LIF neurons, shape=(e-s, 23)
- Return type:
ndarray
Notes
each node contain such property:
noise_rate, blocked_in_stat, I_extern_Input, sub_block_idx, C, T_ref, g_Li, V_L, V_th, V_reset, g_ui, V_ui, tao_ui size: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 4, 4 dtype: f, b, f, i, f, f, f, f, f, f, f, f, f
b means bool(although storage as float), f means float.
this function support broadcast, e.g, C can be a scalar for a total block or a [E_number, I_number] tensor for total nodes.
- generation.make_block.get_k_idx(max_k, num, except_idx)
Fast implementation of random sampling with Numba.
- Parameters:
max_k (int) – allowed range to sample.
num (int) – the number of samples required.
except_idx (int) – whether consider self idx.
- Returns:
sample idx
- Return type:
ndarray
- generation.make_block.merge_dti_distributation_block(orig_path, new_path, dtype='single', avg_degree=(1000,), number=1, block_partition=None, debug_block_dir=None, output_direction=False, MPI_rank=None, only_load=False)[source]
merge to block that is corresponding to gpu card and then save in a npz file.
- Parameters:
orig_path (closure or str) – Call this closure and return three generators. or directory of block npz files.
new_path (str) – directory to save
dtype (str) – “single” indicate it’s a single ensemble. in the old version, it represents the precision of storage data.
number (int) – number of npz files, corresponding to cpu cards.
block_partition (optional, None) – customized block partition in each gpu cards.
debug_block_dir (str or None) – directory to save debug block. None indicate no debug block.
output_direction (bool) – whether the output neurons as priorities.
MPI_rank (int) – mpi rank , assert mpi rank < total gpus.
only_load (bool) – used in debug block.
read_block
- generation.read_block.connect_for_block(block_dir, dense=True, bases=None, return_src=False)[source]
Read npz file , and convert it into node attribute and adjacency matrix id dense is True, else convert to generator.
- Parameters:
block_dir (str) – the directory of these block npz files.
dense (bool) – whether convert to dense case.
bases (optional, None) – the bases of neuronal number.
return_src (bool) – old version, may be eliminated