Skip to content

Commit e35c6c2

Browse files
authored
Merge pull request #103 from scidash/dev
Merged dev into master for release
2 parents 7a4f6c9 + 08f2e8a commit e35c6c2

24 files changed

+503
-207
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ GeneratedFiles
2020
GeneratedFiles/*.py
2121

2222
\.idea/
23+
.vscode

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
| [![RTFD](https://readthedocs.org/projects/sciunit/badge/?version=master)](http://sciunit.readthedocs.io/en/latest/?badge=master) | [![RTFD](https://readthedocs.org/projects/sciunit/badge/?version=dev)](http://sciunit.readthedocs.io/en/latest/?badge=dev) |
55
| [![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/scidash/sciunit/master?filepath=docs%2Fchapter1.ipynb) | |
66
| [![Coveralls](https://coveralls.io/repos/github/scidash/sciunit/badge.svg?branch=master)](https://coveralls.io/github/scidash/sciunit?branch=master) | [![Coveralls](https://coveralls.io/repos/github/scidash/sciunit/badge.svg?branch=dev)](https://coveralls.io/github/scidash/sciunit?branch=dev) |
7-
| [![Requirements](https://requires.io/github/scidash/sciunit/requirements.svg?branch=master)](https://requires.io/github/scidash/sciunit/requirements/?branch=master) | [![Requirements](https://requires.io/github/scidash/sciunit/requirements.svg?branch=dev)](https://requires.io/github/scidash/sciunit/requirements/?branch=dev) |
7+
| [![Requirements](https://requires.io/github/scidash/sciunit/requirements.svg?branch=master)](https://requires.io/github/scidash/sciunit/requirements/?branch=master) | [![Requirements](https://requires.io/github/scidash/sciunit/requirements.svg?branch=dev)](https://requires.io/github/scidash/sciunit/requirements/?branch=dev) |
88
| [![Docker Build Status](https://img.shields.io/docker/build/scidash/sciunit.svg)](https://hub.docker.com/r/scidash/sciunit/builds/) |
9+
| [![Repos using Sciunit](https://img.shields.io/librariesio/dependent-repos/pypi/sciunit.svg)](https://github.com/scidash/sciunit/network/dependents?dependent_type=REPOSITORY)
910

1011
<img src="https://raw.githubusercontent.com/scidash/assets/master/logos/SciUnit/sci-unit-square-small.png" alt="SciUnit Logo" width="400px">
1112

@@ -15,7 +16,7 @@
1516
[The conference paper](https://github.com/cyrus-/papers/raw/master/sciunit-icse14/sciunit-icse14.pdf)
1617

1718
## Documentation
18-
[Chapter 1](https://github.com/scidash/sciunit/blob/master/docs/chapter1.ipynb) /
19+
[Chapter 1](https://github.com/scidash/sciunit/blob/master/docs/chapter1.ipynb) /
1920
[Chapter 2](https://github.com/scidash/sciunit/blob/master/docs/chapter2.ipynb) /
2021
[Chapter 3](https://github.com/scidash/sciunit/blob/master/docs/chapter3.ipynb) /
2122

@@ -27,8 +28,8 @@ score = my_test.judge() # Runs the test and return a rich score containing test
2728
```
2829

2930
## Domain-specific libraries and information
30-
31-
[NeuronUnit](https://github.com/scidash/neuronunit) for neuron and ion channel physiology
31+
[NeuronUnit](https://github.com/scidash/neuronunit) for neuron and ion channel physiology<br>
32+
See others [here](https://github.com/scidash/sciunit/network/dependents?dependent_type=REPOSITORY)
3233

3334
## Mailing List
3435
There is a [mailing list](https://groups.google.com/forum/?fromgroups#!forum/sciunit) for announcements and discussion.
@@ -37,7 +38,7 @@ Please join it if you are at all interested!
3738
## Contributors
3839
* [Rick Gerkin](http://rick.gerk.in), Arizona State University (School of Life Science)
3940
* [Cyrus Omar](http://cs.cmu.edu/~comar), Carnegie Mellon University (Dept. of Computer Science)
40-
41+
4142
## Reproducible Research ID
4243
RRID:[SCR_014528](https://scicrunch.org/resources/Any/record/nlx_144509-1/3faed1d9-6579-5da6-b4b4-75a5077656bb/search?q=sciunit&l=sciunit)
4344

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ ipykernel
1010
nbformat
1111
gitpython
1212
cerberus>=1.2
13+
backports.tempfile

sciunit/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"""
66

77
from __future__ import print_function
8+
from __future__ import unicode_literals
89

9-
from .utils import settings
10+
from .utils import settings, log
1011
from .models import Model
1112
from .capabilities import Capability
1213
from .tests import Test, TestM2M
@@ -15,4 +16,4 @@
1516
from .errors import Error
1617
from .scores.collections import ScoreArray, ScoreMatrix, ScorePanel
1718
from .scores.collections_m2m import ScoreArrayM2M, ScoreMatrixM2M
18-
from .version import __version__
19+
from .version import __version__

sciunit/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from git.cmd import Git
1414

1515
PYTHON_MAJOR_VERSION = sys.version_info.major
16+
PLATFORM = sys.platform
1617

1718
if PYTHON_MAJOR_VERSION < 3: # Python 2
1819
from StringIO import StringIO

sciunit/capabilities.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class __metaclass__(type):
4747
def name(cls):
4848
return cls.__name__
4949

50+
def __str__(self):
51+
return self.name
52+
5053

5154
class ProducesNumber(Capability):
5255
"""An example capability for producing some generic number."""

sciunit/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class ObservationError(Error):
1313
pass
1414

1515

16+
class ParametersError(Error):
17+
"""Raised when params passed to a test are invalid."""
18+
pass
19+
20+
1621
class CapabilityError(Error):
1722
"""Error raised when a required capability is not
1823
provided by a model."""

sciunit/models/backends.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def init_backend(self, *args, **kwargs):
4949
"""The function that handles running the simulation"""
5050
f = None
5151

52+
"""Optional list of state variables for a backend to record."""
53+
recorded_variables = None
54+
5255
def init_cache(self):
5356
"""Initialize the cache."""
5457
self.init_memory_cache()
@@ -107,7 +110,7 @@ def set_attrs(self, **attrs):
107110
pass
108111

109112
def set_run_params(self, **run_params):
110-
"""Set run parameters on the backend."""
113+
"""Set model attributes on the backend."""
111114
pass
112115

113116
def backend_run(self):

sciunit/models/base.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def __init__(self, name=None, **params):
1818
self.params = params
1919
if params is None:
2020
params = {}
21-
self.extra_capability_checks = {}
2221
super(Model, self).__init__()
2322
self.check_params()
2423

@@ -39,16 +38,31 @@ def __init__(self, name=None, **params):
3938
extra_capability_checks = None
4039
"""Optional extra checks of capabilities on a per-instance basis."""
4140

42-
@property
43-
def capabilities(self):
41+
@classmethod
42+
def get_capabilities(cls):
4443
"""List the model's capabilities."""
4544
capabilities = []
46-
for cls in self.__class__.mro():
47-
if issubclass(cls, Capability) and cls is not Capability \
48-
and not issubclass(cls, Model):
49-
capabilities.append(cls.__name__)
45+
for _cls in cls.mro():
46+
if issubclass(_cls, Capability) and _cls is not Capability \
47+
and not issubclass(_cls, Model):
48+
capabilities.append(_cls)
5049
return capabilities
5150

51+
@property
52+
def capabilities(self):
53+
return self.__class__.get_capabilities()
54+
55+
@property
56+
def failed_extra_capabilities(self):
57+
"""Check to see if instance passes its `extra_capability_checks`."""
58+
failed = []
59+
for capability, f_name in self.extra_capability_checks.items():
60+
f = getattr(self, f_name)
61+
instance_capable = f()
62+
if isinstance(self, capability) and not instance_capable:
63+
failed.append(capability)
64+
return failed
65+
5266
def describe(self):
5367
"""Describe the model."""
5468
result = "No description available"
@@ -87,6 +101,17 @@ def is_match(self, match):
87101
result = True # Found by instance or name
88102
return result
89103

104+
def __getattr__(self, attr):
105+
try:
106+
result = super(Model, self).__getattribute__(attr)
107+
except AttributeError:
108+
try:
109+
result = self._backend.__getattribute__(attr)
110+
except:
111+
raise AttributeError("Model %s has no attribute %s"
112+
% (self, attr))
113+
return result
114+
90115
def __str__(self):
91116
"""Return the model name."""
92117
return '%s' % self.name

sciunit/scores/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ def get_raw(self):
153153
def set_raw(self, raw):
154154
self._raw = raw
155155

156+
def __repr__(self):
157+
return self.__str__()
158+
156159
def __str__(self):
157160
return '%s' % self.score
158161

0 commit comments

Comments
 (0)