sciunit.models package

Submodules

sciunit.models.backends module

Base class for simulator backends for SciUnit models.

class sciunit.models.backends.Backend[source]

Bases: object

Base class for simulator backends.

Should only be used with model classes derived from RunnableModel. Supports caching of simulation results. Backend classes should implement simulator-specific details of modifying, running, and reading results from the simulation.

__module__ = 'sciunit.models.backends'
__weakref__

list of weak references to the object (if defined)

_backend_run()[source]

Run the model via the backend.

backend_run()[source]

Check for cached results; then run the model if needed.

f = None

The function that handles running the simulation

get_disk_cache(key=None)[source]

Return result in disk cache for key ‘key’ or None if not found.

get_memory_cache(key=None)[source]

Return result in memory cache for key ‘key’ or None if not found.

init_backend(*args, **kwargs)[source]

Initialize the backend.

init_cache()[source]

Initialize the cache.

init_disk_cache()[source]

Initialize the on-disk version of the cache.

init_memory_cache()[source]

Initialize the in-memory version of the cache.

load_model()[source]

Load the model into memory.

name = None

Name of the backend

recorded_variables = None

Optional list of state variables for a backend to record.

save_results(path='.')[source]

Save results on disk.

set_attrs(**attrs)[source]

Set model attributes on the backend.

set_disk_cache(results, key=None)[source]

Store result in disk cache with key matching model state.

set_memory_cache(results, key=None)[source]

Store result in memory cache with key matching model state.

set_run_params(**run_params)[source]

Set model attributes on the backend.

exception sciunit.models.backends.BackendException[source]

Bases: Exception

Generic backend exception class.

__module__ = 'sciunit.models.backends'
__weakref__

list of weak references to the object (if defined)

sciunit.models.backends.register_backends(vars)[source]

Register backends for use with models.

vars should be a dictionary of variables obtained from e.g. locals(), at least some of which are Backend classes, e.g. from imports.

sciunit.models.base module

Base class for SciUnit models.

class sciunit.models.base.Model(name=None, **params)[source]

Bases: sciunit.base.SciUnit

Abstract base class for sciunit models.

__getattr__(attr)[source]
__init__(name=None, **params)[source]

Instantiate model.

__module__ = 'sciunit.models.base'
__str__()[source]

Return the model name.

_backend = None

Optional model backend for executing some methods, e.g. simulations.

property capabilities
check_params()[source]

Check model parameters to see if they are reasonable.

For example, this method could check self.params to see if a particular value was within an acceptable range. This should be implemented as needed by specific model classes.

curr_method(back=0)[source]

Return the name of the current method (calling this one).

describe()[source]

Describe the model.

description = ''

A description of the model.

extra_capability_checks = None

Optional extra checks of capabilities on a per-instance basis.

property failed_extra_capabilities

Check to see if instance passes its extra_capability_checks.

classmethod get_capabilities()[source]

List the model’s capabilities.

is_match(match)[source]

Return whether this model is the same as match.

Matches if the model is the same as or has the same name as match.

name = None

The name of the model. Defaults to the class name.

params = None

The parameters to the model (a dictionary). These distinguish one model of a class from another.

run_args = None

These are the run-time arguments for the model. Execution of run() should make use of these arguments.

sciunit.models.examples module

Example SciUnit model classes.

class sciunit.models.examples.CacheByInstancePersistentUniformModel(a, b, name=None)[source]

Bases: sciunit.models.examples.PersistentUniformModel

TODO

__module__ = 'sciunit.models.examples'
produce_number(**kwargs)

Produce a number.

class sciunit.models.examples.CacheByValuePersistentUniformModel(a, b, name=None)[source]

Bases: sciunit.models.examples.PersistentUniformModel

TODO

__module__ = 'sciunit.models.examples'
produce_number(**kwargs)

Produce a number.

class sciunit.models.examples.ConstModel(constant, name=None)[source]

Bases: sciunit.models.base.Model, sciunit.capabilities.ProducesNumber

A model that always produces a constant number as output.

__init__(constant, name=None)[source]

Instantiate model.

__module__ = 'sciunit.models.examples'
produce_number()[source]

Produce a number.

class sciunit.models.examples.PersistentUniformModel(a, b, name=None)[source]

Bases: sciunit.models.examples.UniformModel

TODO

__module__ = 'sciunit.models.examples'
produce_number()[source]

Produce a number.

run()[source]
class sciunit.models.examples.RepeatedRandomNumberModel(name=None, **params)[source]

Bases: sciunit.models.base.Model, sciunit.capabilities.ProducesNumber

An example model to demonstrate ProducesNumber with cypy.lazy.

__module__ = 'sciunit.models.examples'
produce_number(**kwargs)[source]

Each call to this method will produce the same random number as was returned in the first call, ensuring reproducibility and eliminating computational overhead.

class sciunit.models.examples.SharedModel(*args, **kwargs)[source]

Bases: sciunit.models.base.Model

A model that, each time it is instantiated with the same parameters, will return the same instance at the same locaiton in memory. Attributes should not be set post-instantiation unless the goal is to set those attributes on all models of this class.

__module__ = 'sciunit.models.examples'
static __new__(cls, *args, **kwargs)

Override used by cypy.intern to cache instances of this class.

static __static_new__(cls, *args, **kwargs)

Override used by cypy.intern to cache instances of this class.

_intern__pool = {}
class sciunit.models.examples.UniformModel(a, b, name=None)[source]

Bases: sciunit.models.base.Model, sciunit.capabilities.ProducesNumber

A model that always produces a random uniformly distributed number in [a,b] as output.

__init__(a, b, name=None)[source]

Instantiate model.

__module__ = 'sciunit.models.examples'
produce_number()[source]

Produce a number.

class sciunit.models.examples.UniqueRandomNumberModel(name=None, **params)[source]

Bases: sciunit.models.base.Model, sciunit.capabilities.ProducesNumber

An example model to ProducesNumber.

__module__ = 'sciunit.models.examples'
produce_number()[source]

Each call to this method will produce a different random number.

sciunit.models.runnable module

Runnable model.

class sciunit.models.runnable.RunnableModel(name, backend=None, attrs=None)[source]

Bases: sciunit.models.base.Model, sciunit.capabilities.Runnable

A model which can be run to produce simulation results

__del__()[source]
__init__(name, backend=None, attrs=None)[source]

Instantiate model.

__module__ = 'sciunit.models.runnable'
check_run_params()[source]

Check if run parameters are reasonable for this model class.

Raise a sciunit.BadParameterValueError if any of them are not.

get_backend()[source]

Return the simulation backend.

reset_default_run_params()[source]
reset_run_params()[source]
run(**run_params)[source]

Run the simulation (or lookup the results in the cache).

set_attrs(**attrs)[source]

Set model attributes, e.g. input resistance of a cell.

set_backend(backend)[source]

Set the simulation backend.

set_default_run_params(**params)[source]

Set default parameters for all runs.

Note these are parameters of the simulation itself, not the model.

set_run_params(**run_params)[source]

Set run-time parameters, e.g. the somatic current to inject.

property state
use_default_run_params()[source]

Module contents

SciUnit models.