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

KeyError: 'injected_square_current' #207

Closed NeZanyat closed 5 years ago

NeZanyat commented 5 years ago

Branch: dash

Error:

Traceback (most recent call last):
  File "/Users/roman/.virtualenvs/scidash/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/roman/.virtualenvs/scidash/lib/python3.6/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/Users/roman/.virtualenvs/scidash/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/roman/.virtualenvs/scidash/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/roman/.virtualenvs/scidash/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/roman/.virtualenvs/scidash/lib/python3.6/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/roman/Projects/metacell/scidash/scidash/general/views.py", line 154, in post
    self.calculate_score(simulation_result, score_instance)
  File "/Users/roman/Projects/metacell/scidash/scidash/general/views.py", line 103, in calculate_score
    score = test_instance.judge(model_instance)
  File "/Users/roman/Projects/metacell/scidash/sciunit/sciunit/tests.py", line 295, in judge
    raise score.score  # An exception.
  File "/Users/roman/Projects/metacell/scidash/sciunit/sciunit/tests.py", line 284, in judge
    score = self._judge(model, skip_incapable=skip_incapable)
  File "/Users/roman/Projects/metacell/scidash/sciunit/sciunit/tests.py", line 224, in _judge
    prediction = self.generate_prediction(model)
  File "/Users/roman/Projects/metacell/scidash/neuronunit/neuronunit/tests/fi.py", line 45, in generate_prediction
    lookup = self.threshold_FI(model, units)
  File "/Users/roman/Projects/metacell/scidash/neuronunit/neuronunit/tests/fi.py", line 96, in threshold_FI
    f(high)
  File "/Users/roman/Projects/metacell/scidash/neuronunit/neuronunit/tests/fi.py", line 72, in f
    current = self.params.copy()['injected_square_current']
KeyError: 'injected_square_current'

My guess is that it happens because parameters which was set here https://github.com/scidash/neuronunit/blob/dash/neuronunit/tests/fi.py#L25

are redefined at parent's init method here: https://github.com/scidash/sciunit/blob/dash/sciunit/tests.py#L33

russelljjarvis commented 5 years ago

I have seen this error before too. My hackish workaround.

Even better again, would be to find the code that creates current injection dictionaries, without adding a inject_square_current key.


if 'injected_square_current' in self.params.keys():
    current = self.params.copy()['injected_square_current']
else:
    temp = self.params
    self.params['injected_square_current'] = temp
rgerkin commented 5 years ago

I think this is fixed in the dev branch. I would prefer that the changes made there be pulled back into the dash branch, rather than have conflicting fixes. I will handle it this week.

rgerkin commented 5 years ago

@NeZanyat Could you give a minimal example to reproduce this, so I make sure that I've fixed it?

NeZanyat commented 5 years ago

Sure. Here is the example

https://github.com/NeZanyat/neuronunit/blob/dash/param_error.ipynb

rgerkin commented 5 years ago

@NeZanyat I think the relevant fix is in 85b706cfde0b70e44a89f67a3db9fe73b435b4ef in the dev branch, but it was difficult to try to figure out if any other commits were needed, so I just merged dev and dash completely. This could introduce new problems, but almost all of the dev commits were about optimization or direct simulation with NEURON and so shouldn't change much here. I also merged sciunit's dev and dash to match.

You can see a working version of something like your notebook above (with additional features to demonstrate what should work) here.

Let me know if this runs for you, and then what else breaks as a result of the merge.