scidash / neuronunit

A package for data-driven validation of neuron and ion channel models using SciUnit
http://neuronunit.scidash.org
38 stars 24 forks source link

Replacing ReducedModel with VeryReducedModel desirable but results in cryptic errors. #223

Closed russelljjarvis closed 4 years ago

russelljjarvis commented 4 years ago

It's desirable to have a model class that does not force unused variables like LEMS path.

Efforts to define one such as below cause a bad interaction between DEAP and sciunit. I think it has something to do with the code used to remove NEURON C objects from models to make them pickable.

What doesn't work: Both of the classes below (1 and 2) work superficially and would run with code for obtaining Rheobase etc. These objects only fail when entering +1 generations of DEAP optimisation, and then it seems like it is because of DEAPs backend and sciunit backend competing to try to do some kind of object attribute manipulation.

1 Inheriting from External model

class VeryReducedModel(mod.ExternalModel,
                   cap.ReceivesCurrent,
                   cap.ProducesActionPotentials,
                   ):
    """Base class for reduced models, not using LEMS, and not requiring file paths this is to wrap pyNN models, brian models, and other self contained models+model descriptions"""

    def __init__(self, name=None, backend=None, attrs=None):
        """Instantiate a reduced model.
        LEMS_file_path: Path to LEMS file (an xml file).
        name: Optional model name.
        """
        super(ReducedModel,self).__init__(name=name,
                                          backend=backend,attrs=attrs)
        self.run_number = 0
        self.tstop = None

2 Inhering from Runnable

class VeryReducedModel(RunnableModel,
                       cap.ReceivesCurrent,
                       cap.ProducesActionPotentials,
                       ):
    """Base class for reduced models, not using LEMS,
    and not requiring file paths this is to wrap pyNN models, Brian models,
    and other self contained models+model descriptions"""

    def __init__(self, name=None, backend=None, attrs=None):
        """Instantiate a reduced model.

        LEMS_file_path: Path to LEMS file (an xml file).
        name: Optional model name.
        """
        super(VeryReducedModel, self).__init__(name, backend=backend, attrs=attrs)
        # self.backend = backend
        # self.attrs = attrs
        self.run_number = 0
        self.tstop = None

https://github.com/russelljjarvis/neuronunit/blob/barcelona/models/very_reduced.py

Using the regular ReducedModel still works.

Stack trace.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "easy.py", line 16, in <module>
    NSGA = True, MU = 4, model_type = str('ADEXP'))
  File "/home/russell/outside/neuronunit/neuronunit/optimisation/optimisation_management.py", line 1295, in run_ga
    ga_out = DO.run(max_ngen = max_ngen)
  File "/home/russell/outside/neuronunit/neuronunit/optimisation/optimisations.py", line 413, in run
    td = self.td)
  File "/home/russell/outside/neuronunit/neuronunit/optimisation/algorithms.py", line 187, in eaAlphaMuPlusLambdaCheckpoint
    offspring = [ toolbox.clone(ind) for ind in offspring ]
  File "/home/russell/outside/neuronunit/neuronunit/optimisation/algorithms.py", line 187, in <listcomp>
    offspring = [ toolbox.clone(ind) for ind in offspring ]
  File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python3.5/copy.py", line 297, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.5/copy.py", line 243, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.5/copy.py", line 218, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.5/copy.py", line 223, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/usr/lib/python3.5/copy.py", line 223, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/usr/lib/python3.5/copy.py", line 166, in deepcopy
    y = copier(memo)
TypeError: cannot deepcopy this pattern object
rgerkin commented 4 years ago

Can you gradually change ReducedModel into VeryReducedModel to identify which step of the change causes it to fail during DEAP optimization? Maybe you can start by having VeryReducedModel actually subclass ReducedModel, but then just start overloading its various methods and emptying them out to see which one turns out to be important.

russelljjarvis commented 4 years ago

Yes, I think that too. Subclass Reduced model and override the constructor.

russelljjarvis commented 4 years ago

This is done, as a temporary measure.

russelljjarvis commented 4 years ago

I now have VeryReducedModel.