BlueBrain / BluePyOpt

Blue Brain Python Optimisation Library
https://bluepyopt.readthedocs.io/en/latest/
Other
203 stars 98 forks source link

distinguishing areal from point locations in hoc #421

Open anilbey opened 2 years ago

anilbey commented 2 years ago
    This is the reproducing example:
BluePyOpt$ ipython
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from bluepyopt import ephys

In [2]: ephys.create_hoc.create_hoc(mechs=[], parameters=[ephys.parameters.NrnSectionParameter(name='param', value=1., locations=[ephys.locations.NrnSectionCompLocation(name='loc', sec_name='soma[0]', comp_x=0.5)])])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [2], line 1
----> 1 ephys.create_hoc.create_hoc(mechs=[], parameters=[ephys.parameters.NrnSectionParameter(name='param', value=1., locations=[ephys.locations.NrnSectionCompLocation(name='loc', sec_name='soma[0]', comp_x=0.5)])])

File ~/src/arbor/bluepyopt_test/BluePyOpt/bluepyopt/ephys/create_hoc.py:156, in create_hoc(mechs, parameters, morphology, ignored_globals, replace_axon, template_name, template_filename, disable_banner, template_dir, custom_jinja_params)
    152     template = template_file.read()
    153     template = jinja2.Template(template)
    155 global_params, section_params, range_params, location_order = \
--> 156     _generate_parameters(parameters)
    157 channels = _generate_channels_by_location(mechs, location_order)
    159 ignored_global_params = {}

File ~/src/arbor/bluepyopt_test/BluePyOpt/bluepyopt/ephys/create_hoc.py:76, in _generate_parameters(parameters)
     73         assert isinstance(
     74             param.locations, (tuple, list)), 'Must have locations list'
     75         for location in param.locations:
---> 76             param_locations[location.seclist_name].append(param)
     78 section_params = defaultdict(list)
     79 range_params = []

AttributeError: 'NrnSectionCompLocation' object has no attribute 'seclist_name'

If create_hoc only supports areal locations, I think neither of the other CompLocations should be accepted by create_hoc (NrnSeclistCompLocation, NrnSomaDistanceCompLocation, NrnSecSomaDistanceCompLocation, NrnTrunkSomaDistanceCompLocation). Effectively, it seems that only NrnSeclistLocation is supported for the mechanism location, hence, I've added a check. It might be worth distinguishing areal from point locations in the class hierarchy (below locations.Location) in the future. In Arbor this is the difference between regions and locsets.

_Originally posted by @lukasgd in https://github.com/BlueBrain/BluePyOpt/pull/393#discussion_r1002772807_

anilbey commented 2 years ago

The attribute error is fixed in 9bbc68e.

Consider @lukasgd's suggestion:

I think follow-up issues should focus on extending hoc-support or, as suggested above, introducing another level in the locations class hierarchy that distinguishes areal from point locations.

lukasgd commented 2 years ago

The two points connected by the "or" above are actually separate and independent aspects: