Code Monkey home page Code Monkey logo

Comments (8)

rgerkin avatar rgerkin commented on July 29, 2024

@russelljjarvis
I've just fixed this in the backend-refactor branch (the one with the open PR). So now I can do:

m = StaticModel(vm)  # Make a static model based on this response
t = InputResistanceTest({'mean': 450*pq.MOhm, 'std': 50*pq.MOhm})
s = t.judge(m)

and get the expected score for a given vm, in the backend-refactor branch of this fork.

Origin of the problem and its solution:
Yes ProtocolToFeaturesTest requires a run method, and the easy way to achieve that is to make StaticModel inherit from sciunit.models.runnable.RunnableModel instead of from just sciunit.Model. But the other issue is that the tests itself (e.g. InputResistanceTest) requires the ability to call methods of the backend (like set_stop_time). Most of the backends have this, but of course the whole point of StaticModel is to not have to have any actual backend. And I noticed that all of those methods (like set_stop_time) where defined in all of the backends but without a reference backend class which defines the signatures of those methods. So I created an empty Backend class which StaticModel can use, which doesn't do anything at all (those methods are implemented as pass), consistent with the nature of StaticModel.

So if this is a blocking issue for you, I propose that we merge that branch today in our meeting, and see then address any new issues that arise from that.

from neuronunit.

russelljjarvis avatar russelljjarvis commented on July 29, 2024

With the newer version of sciunit dev installed

RheobaseTest
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/git/sciunit/sciunit/models/base.py in __getattr__(self, attr)
    108         try:
--> 109             result = super(Model, self).__getattribute__(attr)
    110         except AttributeError:

AttributeError: 'StaticModel' object has no attribute 'run_params'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
~/git/sciunit/sciunit/models/base.py in __getattr__(self, attr)
    111             try:
--> 112                 result = self._backend.__getattribute__(attr)
    113             except:

AttributeError: 'EmptyBackend' object has no attribute 'run_params'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-7-9eeb01b46f3a> in <module>
      8 for t in tt:
      9     print(t.name)
---> 10     score = t.judge(SM)
     11 #tt = switch_logic(tt)
     12 #not_suite = TSD({t.name:t for t in tt.tests})

~/git/sciunit/sciunit/tests.py in judge(self, model, skip_incapable, stop_on_error, deep_error)
    330                 score.test = self
    331         if isinstance(score, ErrorScore) and stop_on_error:
--> 332             raise score.score  # An exception.
    333         return score
    334 

~/git/sciunit/sciunit/tests.py in judge(self, model, skip_incapable, stop_on_error, deep_error)
    319         else:
    320             try:
--> 321                 score = self._judge(model, skip_incapable=skip_incapable)
    322             except CapabilityError as e:
    323                 score = NAScore(str(e))

~/git/sciunit/sciunit/tests.py in _judge(self, model, skip_incapable)
    259 
    260         # 2.
--> 261         prediction = self.generate_prediction(model)
    262         self.check_prediction(prediction)
    263         self.last_model = model

~/safe2/neuronunit/neuronunit/tests/fi.py in generate_prediction(self, model)
    103         # Method implementation guaranteed by
    104         # ProducesActionPotentials capability.
--> 105         self.condition_model(model)
    106         prediction = {'value': None}
    107         model.rerun = True

~/safe2/neuronunit/neuronunit/tests/fi.py in condition_model(self, model)
     97             self.params['tmax'] = 2000.0*pq.ms
     98         else:
---> 99             model.set_run_params(t_stop=self.params['tmax'])
    100 
    101     def generate_prediction(self, model):

~/git/sciunit/sciunit/models/runnable.py in set_run_params(self, **run_params)
     84     def set_run_params(self, **run_params):
     85         """Set run-time parameters, e.g. the somatic current to inject."""
---> 86         self.run_params.update(run_params)
     87         self.check_run_params()
     88         self._backend.set_run_params(**run_params)

~/git/sciunit/sciunit/models/base.py in __getattr__(self, attr)
    113             except:
    114                 raise AttributeError("Model %s has no attribute %s"
--> 115                                      % (self, attr))
    116         return result
    117 

AttributeError: Model None has no attribute run_params```

from neuronunit.

rgerkin avatar rgerkin commented on July 29, 2024

@russelljjarvis I don't know what you are doing to get this because you printed the traceback but not the code that produced it.

from neuronunit.

rgerkin avatar rgerkin commented on July 29, 2024

@russelljjarvis OK, I think I figured it out based on the traceback. RheobaseTest does not inherit from TestPulseTest so it needed a few bug fixes to work. I applied them in the rick branch of this repository, so check that out and it should work (or at least you shouldn't get that bug). For example, I can run a RheobaseTest on a static model (whereas it resulted an error before). Be aware that if you are running a RheobaseTest on a static model, you'll need to have a cached waveform for every value of current injected -- not sure that is actually possible?

I am assuming you were running a RheobaseTest since that is what was printed at the very top of the stack trace.

from neuronunit.

russelljjarvis avatar russelljjarvis commented on July 29, 2024

Its down the bottom of this file:

https://github.com/russelljjarvis/NeuronunitOpt/blob/master/neuronunit/unit_test/working/NeuroML2_Izhi.ipynb

from neuronunit.

rgerkin avatar rgerkin commented on July 29, 2024

@russelljjarvis Does the fix in the rick branch work for you? I am able to run most of your notebook above with that branch, although I needed to make a few changes in the notebook:

Specific to me:

  • import os; os.environ['NEURON_HOME'] = '/opt/conda' # The path to my NEURON installation
  • In terminal: cd ~/neuronunit/neuronunit/models/NeuroML2; nrnivmodl

General

  • Replace all calls to set_params(var) with set_params(**var) (set_params takes key-value pairs, so a dict much be passed with **).
  • Replace all calls to model.inject_square_current(iparams) with model.inject_square_current(iparams['injected_square_current']) (inject_square_current expects an injected_square_current dict, not a whole dict of all params)
  • Not sure where model.results['sim_time'] is coming from, so I just got rid of all of those.
  • Several cells need to be reordered since earlier cells use variables created in later cells.
  • Fixes required in get_neab.

I'll push a new version of the notebook to my branch soon.

from neuronunit.

rgerkin avatar rgerkin commented on July 29, 2024

Actually, I cannot finish because of an issue in get_neab. You wouldn't have encountered it because you have the all_tests.p pickle file, but I cannot reconstruct it because of this line, which I don't understand, and which raises an Exception (you are trying to call a dictionary as a function). I see that you are trying to build a list of observations and tests. I get the observations (lists of NeuroElectroSummary objects for each cell), but I'm not sure whether you are actually trying instantiate tests here or what.

In any case, if you want to move forward, you can apply the same fixes as above in my last message, on the rick branch (which has all of your commits from master) and see if it works for you, since you already have all_tests.p.

from neuronunit.

russelljjarvis avatar russelljjarvis commented on July 29, 2024

The method get_neab.process_all_cells(). Seems to be the only method that runs without failing. Even then, it can't access every cell data set it was designed to obtain.

I put in a link to the wrong file.
https://github.com/russelljjarvis/NeuronunitOpt/blob/master/neuronunit/unit_test/working/NeuroML2_HH.ipynb

I will test out the rick branch later tonight.

from neuronunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.