Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with dense.set_object_properties() #41

Open
SBottani opened this issue Apr 29, 2020 · 4 comments
Open

Problem with dense.set_object_properties() #41

SBottani opened this issue Apr 29, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@SBottani
Copy link
Contributor

A new issue when updating neurite parameters with dense.set_object_properties(), occuring possibly only with environment enabled (example program worked fine on april 9th):
Continuing the simulation after parameter update leads to segmentation fault.

# Two successive simulation runs : ok
ds.simulate(1*day)
ds.simulate(1*day)
# Now update of parameters (error persist even if neurite_parameters unchanged)
  dense.set_object_properties(gids, neurite_params=neurite_params)
# Addition simulation run
ds.simulate(1*day)   # leads to segmentation fault

m
Repeating simulation steps without calling dense.set_object_properties() works

    for i in range(3):
        ds.simulate(1*day)

Example code:

import os
import shutil
import time
import numpy as np
import matplotlib.pyplot as plt
import nngt
import dense as ds
from dense.units import *

current_dir = os.path.abspath(os.path.dirname(__file__))
main_dir = current_dir[:current_dir.rfind("/")]

def CleanFolder(tmp_dir, make=True):
    if os.path.isdir(tmp_dir):
        shutil.rmtree(tmp_dir)
    if make:
        os.mkdir(tmp_dir)
    return tmp_dir

def step(n, loop_n, plot=True):
    print("simulating", n)
    ds.simulate(n)
    print("done")
    if plot:
        _, ax = plt.subplots()
        ds.plot.plot_neurons(mode='mixed', subsample=1, axis=ax,
                             show_nodes=True, show_neuron_id=True, show=True)

'''
Main parameters
'''
np.random.seed(0)

soma_radius = 5.
num_neurons = 10

gc_model = 'cst_po_nwa'
use_vp = True

neuron_params = {
    "soma_radius": soma_radius * um,
}

dendrite_params = {
    "use_van_pelt": True,
    "growth_cone_model": gc_model,
    "speed_growth_cone": 0.06 * um / minute,
    "filopodia_wall_affinity": 0.01,
    "persistence_length": 200. * um,
    "B": 6. * cph,
    "T": 1000. * minute,
    "E": 1.,
}

axon_params = {
    "growth_cone_model": gc_model,
    "use_uniform_branching": False,
    "sensing_angle": 70.*deg,
    "speed_growth_cone": 0.1 * um / minute,
    "filopodia_wall_affinity": 10.,
    "filopodia_finger_length": 10. * um,
    "filopodia_min_number": 30,
    "affinity_axon_axon_other_neuron": 100.,

    "persistence_length": 500.*um,
    "taper_rate": 1./400.,
    "diameter_ratio_avg": 0.5,
    # branching
    "use_van_pelt": True,
    "use_uniform_branching": False,
    "filopodia_wall_affinity": 10.
}

neurite_params = {
    "axon": axon_params,
    "dendrites": dendrite_params
}

'''
Simulation
'''

if __name__ == '__main__':
    num_omp = 10
    kernel = {
              "seeds": range(num_omp),
              "num_local_threads": num_omp,
              "environment_required": True,
              "resolution": 5. * minute,
              "interactions": True}

    np.random.seed(118239)  # seeds for the neuron positions

    ds.set_kernel_status(kernel, simulation_id="ID")
    gids, culture = None, None

    if kernel["environment_required"]:
        shape = ds.environment.Shape.disk(300.)
        culture = ds.set_environment(shape)
        # generate the neurons inside the left chamber
        # pos_left = culture.seed_neurons(
        # neurons=100, xmax=540, soma_radius=soma_radius)
        neuron_params['position'] = culture.seed_neurons(
            neurons=num_neurons, soma_radius=soma_radius)
    else:
        neuron_params['position'] = \
            np.random.uniform(-1000, 1000, (num_neurons, 2))*um

    print("\nCreating neurons\n")
    gids = ds.create_neurons(n=num_neurons,
                             culture=culture,
                             params=neuron_params,
                             neurite_params=neurite_params,
                             num_neurites=3)

    rec = ds.create_recorders(gids, "num_growth_cones")
    start = time.time()
    for i in range(3):
        step(1 * day, 0, True)

    # dendrite_params.update({"speed_growth_cone": 0.04 * um / minute,
    #                         "use_van_pelt": False})

    # axon_params.update({"speed_growth_cone": 0.1 * um / minute,
    #                     "use_van_pelt": False,
    #                     "use_uniform_branching": True,
    #                     "uniform_branching_rate": 0.1 * cph,})
    # NB dictionary neurite_params is updated
    print("update parameters")
    ds.set_object_properties(gids, neurite_params=neurite_params)
    print("parameters updated")
    print("extension run")
    step(1 * day, 0, True)
    print("extension run done")
    duration = time.time() - start
    print(ds.get_kernel_status("time"))
    plt.show(block=True)
    print("SIMULATION ENDED")
@SBottani SBottani added the bug Something isn't working label Apr 29, 2020
@Silmathoron
Copy link
Contributor

This bug is very weird... may take me a while to debug...

@Silmathoron
Copy link
Contributor

could you confirm that the bug does not occur if you use a single thread?

@SBottani
Copy link
Contributor Author

You're right !
Setting only ONE threat it runs OK, bug does not occur !

@tfardet
Copy link
Contributor

tfardet commented Jun 11, 2021

OK, solved the issue, it was actually a pretty bad problem in the way parameters were set in parallel.
Will create some tests to make sure it does not happen again and create a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants