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
() → Any[source]¶ Check for cached results; then run the model if needed.
- Returns:
- Any: The result of running backend.
-
f
= None¶ The function that handles running the simulation
-
get_disk_cache
(key: str = None) → Any[source]¶ Return result in disk cache for key ‘key’ or None if not found.
- Args:
- key (str, optional): keys that will be used to find cached data. Defaults to None.
- Returns:
- Any: The disk cache for key ‘key’ or None if not found.
-
get_memory_cache
(key: str = None) → dict[source]¶ Return result in memory cache for key ‘key’ or None if not found.
- Args:
- key (str, optional): [description]. Defaults to None.
- Returns:
- dict: The memory cache for key ‘key’ or None if not found.
-
name
= None¶ Name of the backend
-
recorded_variables
= None¶ Optional list of state variables for a backend to record.
-
save_results
(path: Union[str, pathlib.Path] = '.') → None[source]¶ Save results on disk.
- Args:
- path (Union[str, Path], optional): [description]. Defaults to ‘.’.
-
set_disk_cache
(results: Any, key: str = None) → None[source]¶ Store result in disk cache with key matching model state.
- Args:
- results (Any): [description] key (str, optional): [description]. Defaults to None.
-
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.
-
__module__
= 'sciunit.models.base'¶
-
_backend
= None¶ Optional model backend for executing some methods, e.g. simulations.
-
capabilities
¶
-
check_params
() → None[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: int = 0) → str[source]¶ Return the name of the current method (calling this one).
- Args:
- back (int, optional): [description]. Defaults to 0.
- Returns:
- str: The name of the current method that calls this one.
-
description
= ''¶ A description of the model.
-
extra_capability_checks
= None¶ Optional extra checks of capabilities on a per-instance basis.
-
failed_extra_capabilities
¶ Check to see if instance passes its extra_capability_checks.
-
is_match
(match: Union[str, Model]) → bool[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.
- Args:
- match (Union[str, ‘Model’]): [description]
- Returns:
- bool: Whether this model is the same 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)¶
-
-
class
sciunit.models.examples.
CacheByValuePersistentUniformModel
(a, b, name=None)[source]¶ Bases:
sciunit.models.examples.PersistentUniformModel
TODO
-
__module__
= 'sciunit.models.examples'¶
-
produce_number
(**kwargs)¶
-
-
class
sciunit.models.examples.
ConstModel
(constant: Union[int, float], name: str = None)[source]¶ Bases:
sciunit.models.base.Model
,sciunit.capabilities.ProducesNumber
A model that always produces a constant number as output.
-
__module__
= 'sciunit.models.examples'¶
-
-
class
sciunit.models.examples.
PersistentUniformModel
(a, b, name=None)[source]¶ Bases:
sciunit.models.examples.UniformModel
TODO
-
__module__
= 'sciunit.models.examples'¶
-
-
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'¶
-
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.
Override used by sciunit.utils.intern to cache instances of this class.
Override used by sciunit.utils.intern to cache instances of this class.
-
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.
-
__module__
= 'sciunit.models.examples'¶
-
-
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'¶
-
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.
-
__module__
= 'sciunit.models.runnable'¶
-
check_run_params
() → None[source]¶ Check if run parameters are reasonable for this model class.
Raise a sciunit.BadParameterValueError if any of them are not.
-
set_backend
(backend: Union[str, tuple, list, None])[source]¶ Set the simulation backend.
- Args:
- backend (Union[str, tuple, list, None]): One or more name(s) of backend(s).
- The name of backend should be registered before using.
- Raises:
- TypeError: Backend must be string, tuple, list, or None Exception: The backend was not found.
-
set_default_run_params
(**params) → None[source]¶ Set default parameters for all runs.
Note these are parameters of the simulation itself, not the model.
-
set_run_params
(**run_params) → None[source]¶ Set run-time parameters, e.g. the somatic current to inject.
-
state
¶ Get the state of the instance.
- Returns:
- dict: The state of the instance.
-
Module contents¶
SciUnit models.