AllenInstitute / AllenInstitute/bmtk

Cannot simulate PointNet network with custom set_syn_weight function

Open
#381 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
335
Forks
102
Avg merge
1d 5h
Merged PRs (30d)
6

Description

Hello!

I built a pointnet network for which I used add_properties to define the delays with a given rule. By doing that, i deleted the "nsyn" section in the edge h5 file (which is compensated by adding multiple time a connection in the edge h5 file according to its number of synapses). However, during the simulation of the config file I get this error:

Traceback (most recent call last):
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/BMTK_Simulations/grid_searching_l4l4.py", line 31, in <module>
    sim = pointnet.PointSimulator.from_config(configure, graph)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/pointsimulator.py", line 243, in from_config
    graph.build_recurrent_edges()
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/pointnetwork.py", line 167, in build_recurrent_edges
    for edge in edge_pop.get_edges():
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/core/sonata_reader/network_reader.py", line 191, in get_edges
    for edge in edge_adaptor.get_batches(edge_group):
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/sonata_adaptors.py", line 335, in get_batches
    type_params[edge_id]['weight'] = weight_fnc(edges, source_nodes, target_nodes)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/default_setters/synaptic_weights.py", line 7, in default_weight_fnc
    return np.array(edge_props['syn_weight']*edge_props.nsyns)
                                             ^^^^^^^^^^^^^^^^
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/pandas/core/generic.py", line 6296, in __getattr__
    return object.__getattribute__(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'DataFrame' object has no attribute 'nsyns'
srun: error: node105: task 0: Exited with exit code 1

I tried to overwrite the default set_syn_weight function by building my own set_syn_weight function (which I will also need to use in the future since I want to do a grid searching in order to find an optimal synaptic weight according to a targeted output frequency):

list_grid=[1,2,3,4]
grid_search = {
    'exc':list_grid,
    'in':[0]*len(list_grid)
}

@synaptic_weight
def set_syn_weight(edge_props, source_nodes, target_nodes):

    target_type = target_nodes['cell_line'].unique()[0]
    new_syn_weight = grid_search[target_type][current_itr]
    
    weights_table[target_type].append(new_syn_weight)
    
    return np.array(new_syn_weight*edge_props.nsyns)

But I get this error:

Traceback (most recent call last):
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/BMTK_Simulations/grid_searching_l4l4.py", line 95, in <module>
    sim = pointnet.PointSimulator.from_config(configure, graph)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/pointsimulator.py", line 243, in from_config
    graph.build_recurrent_edges()
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/pointnetwork.py", line 173, in build_recurrent_edges
    self._nest_connect(nest_srcs, nest_trgs, conn_spec='one_to_one', syn_spec=edge.nest_params)
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/pointnetwork.py", line 232, in _nest_connect
    nest.Connect(nest_srcs, nest_trgs, conn_spec=conn_spec, syn_spec=syn_spec)
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/nest/ll_api.py", line 229, in stack_checker_func
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/nest/lib/hl_api_connections.py", line 257, in Connect
    connect_arrays(pre, post, weights, delays, synapse_model, syn_param_keys, syn_param_values)
  File "pynestkernel.pyx", line 300, in pynestkernel.NESTEngine.connect_arrays
TypeError: weights must be a 1-dimensional NumPy array
srun: error: node200: task 0: Exited with exit code 1

I changed the function with:

return np.array(new_syn_weight*pd.Series([1]))

But then again I get this error:

Traceback (most recent call last):
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/BMTK_Simulations/grid_searching_l4l4.py", line 95, in <module>
    sim = pointnet.PointSimulator.from_config(configure, graph)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/pointsimulator.py", line 243, in from_config
    graph.build_recurrent_edges()
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/pointnetwork.py", line 173, in build_recurrent_edges
    self._nest_connect(nest_srcs, nest_trgs, conn_spec='one_to_one', syn_spec=edge.nest_params)
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/bmtk/simulator/pointnet/pointnetwork.py", line 232, in _nest_connect
    nest.Connect(nest_srcs, nest_trgs, conn_spec=conn_spec, syn_spec=syn_spec)
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/nest/ll_api.py", line 229, in stack_checker_func
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/nest/lib/hl_api_connections.py", line 214, in Connect
    processed_syn_spec = _process_syn_spec(
                         ^^^^^^^^^^^^^^^^^^
  File "/gpfs/users/calicem/.conda/envs/ENV_NEST33/lib/python3.11/site-packages/nest/lib/hl_api_connection_helpers.py", line 89, in _process_syn_spec
    raise kernel.NESTError(
nest.lib.hl_api_exceptions.NESTErrors.NESTError: 'weight' has to be an array of dimension 299430.
srun: error: node200: task 0: Exited with exit code 1

How can I build my own set_syn_weight function and avoid this issue ?

I am using NEST 3.3 and BMTK 1.0.8.

Thanks in advance for your help,
Margaux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pointnet/default_setters/synaptic_weights.py and pointnet/sonata_adaptors.py, then trace how the custom function's edge_props result reaches pointnet/pointnetwork.py and NEST Connect. Check the expected edge properties and weight array shape against the reported 299430 connections; done means a custom set_syn_weight function runs successfully with the provided edge data.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.