Skip to content

Commit

Permalink
Moved base Backend and RunnableModel into sciunit
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerkin committed Aug 13, 2018
1 parent dd6d107 commit 94b72ec
Show file tree
Hide file tree
Showing 14 changed files with 542 additions and 287 deletions.
74 changes: 14 additions & 60 deletions docs/chapter3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"![SciUnit Logo](https://raw.githubusercontent.com/scidash/assets/master/logos/sciunit.png)\n",
"\n",
Expand All @@ -18,58 +15,40 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"import sciunit"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"### In this chapter we will use the same toy model in Chapter 1 but write a more interesting test with additional features included in SciUnit. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from sciunit.models import ConstModel # One of many dummy models included for illustration. \n",
"from sciunit.models.examples import ConstModel # One of many dummy models included for illustration. \n",
"const_model_37 = ConstModel(37, name=\"Constant Model 37\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"Now let's write a test that validates the `observation` and returns more informative `score` type."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from sciunit.capabilities import ProducesNumber\n",
Expand Down Expand Up @@ -102,10 +81,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"We've done two new things here:\n",
"- The optional `validate_observation` method checks the `observation` to make sure that it is the right type, that it has the right attributes, etc. This can be used to ensures that the `observation` is exactly as the other core test methods expect. If we don't provide the right kind of observation:\n",
Expand All @@ -119,11 +95,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"observation = {'mean':37.8, 'std':2.1}\n",
Expand All @@ -132,45 +104,31 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"- Instead of returning a `BooleanScore`, encoding a `True`/`False` value, we return a `ZScore` encoding a more quantitative summary of the relationship between the observation and the prediction. When we execute the test:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"score = mean_37_test.judge(const_model_37)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"Then we get a more quantitative summary of the results:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -192,11 +150,7 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down
25 changes: 25 additions & 0 deletions sciunit/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,28 @@ class ProducesNumber(Capability):
def produce_number(self):
"""Produce a number."""
raise NotImplementedError("Must implement produce_number.")


class Runnable(Capability):
"""Capability for models that can be run, i.e. simulated."""

def run(self, **run_params):
"""Run, i.e. simulate the model."""
return NotImplementedError("%s not implemented" %
inspect.stack()[0][3])

def set_run_params(self, **run_params):
"""Set parameters for the next run.
Note these are parameters of the simulation itself, not the model.
"""
return NotImplementedError("%s not implemented" %
inspect.stack()[0][3])

def set_default_run_params(self, **default_run_params):
"""Set default parameters for all runs.
Note these are parameters of the simulation itself, not the model.
"""
return NotImplementedError("%s not implemented" %
inspect.stack()[0][3])
170 changes: 0 additions & 170 deletions sciunit/models.py

This file was deleted.

4 changes: 4 additions & 0 deletions sciunit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""SciUnit models."""

from .base import Model
from .runnable import RunnableModel
Loading

0 comments on commit 94b72ec

Please sign in to comment.