The Virtual Brain Project

Table Of Contents

Previous topic

core Package

Next topic

code_versions Package

This Page

adapters Package

abcadapter

Root classes for adding custom functionality to the code.

class tvb.core.adapters.abcadapter.ABCAdapter[source]

Bases: object

Root Abstract class for all TVB Adapters.

INTERFACE_ATTRIBUTES = 'attributes'
INTERFACE_ATTRIBUTES_ONLY = 'attributes-only'
KEYWORD_OPTION = 'option_'
KEYWORD_PARAMS = '_parameters_'
KEYWORD_SEPARATOR = '_'
KEY_ALL = 'allValue'
KEY_ATTRIBUTES = 'attributes'
KEY_CONDITION = 'conditions'
KEY_DATATYPE = 'datatype'
KEY_DEFAULT = 'default'
KEY_DESCRIPTION = 'description'
KEY_DISABLED = 'disabled'
KEY_DTYPE = 'elementType'
KEY_FILTERABLE = 'filterable'
KEY_ID = 'id'
KEY_LABEL = 'label'
KEY_NAME = 'name'
KEY_OPTIONS = 'options'
KEY_REQUIRED = 'required'
KEY_TYPE = 'type'
KEY_UI_HIDE = 'ui_hidden'
KEY_VALUE = 'value'
STATIC_ACCEPTED_TYPES = ('str', 'float', 'int', 'upload', 'bool', 'dict', 'array', 'select', 'selectMultiple', 'dynamic', 'list')
TYPE_MULTIPLE = 'selectMultiple'
TYPE_SELECT = 'select'
add_operation_additional_info(message)[source]

Adds additional info on the operation to be displayed in the UI. Usually a warning message.

static build_adapter(stored_adapter)[source]

Having a module and a class name, create an instance of ABCAdapter.

static build_adapter_from_class(adapter_class)[source]

Having a subclass of ABCAdapter, prepare an instance for launching an operation with it.

static can_be_active()[source]

To be overridden where needed (e.g. Matlab dependent adapters). :return: By default True, and False when the current Adapter can not be executed in the current env for various reasons (e.g. no Matlab or Octave installed)

configure(**kwargs)[source]

To be implemented in each Adapter that requires any specific configurations before the actual launch.

convert_ui_inputs(kwargs, validation_required=True)[source]

Convert HTTP POST parameters into Python parameters.

flaten_input_interface()[source]

Return a simple dictionary, instead of a Tree.

get_execution_time_approximation(**kwargs)[source]

Method should approximate based on input arguments, the time it will take for the operation to finish (in seconds).

classmethod get_group_description()[source]
classmethod get_group_name()[source]
get_input_tree()[source]

Describes inputs and outputs of the launch method.

get_output()[source]

Describes inputs and outputs of the launch method.

get_required_disk_size(**kwargs)[source]

Abstract method to be implemented in each adapter. Should return the required memory for launching the adapter in kilo-Bytes.

get_required_memory_size(**kwargs)[source]

Abstract method to be implemented in each adapter. Should return the required memory for launching the adapter.

classmethod get_ui_description()[source]
classmethod get_ui_name()[source]
classmethod get_ui_subsection()[source]
launch()[source]

To be implemented in each Adapter. Will contain the logic of the Adapter. Any returned DataType will be stored in DB, by the Framework.

static load_entity_by_gid(data_gid)[source]

Load a generic DataType, specified by GID.

noise_configurable_parameters()[source]
prepare_ui_inputs(kwargs, validation_required=True)[source]

Prepare the inputs received from a HTTP Post in a form that will be used by the Python adapter.

review_operation_inputs(parameters)[source]
Returns:a list with the inputs from the parameters list that are instances of DataType, and a dictionary with all parameters which are different than the declared defauts
stored_adapter = None
class tvb.core.adapters.abcadapter.ABCAsynchronous[source]

Bases: tvb.core.adapters.abcadapter.ABCAdapter

Abstract class, for marking adapters that are prone to be executed on Cluster.

array_size2kb(size)[source]
Parameters:size – size in bytes
Returns:size in kB
class tvb.core.adapters.abcadapter.ABCSynchronous[source]

Bases: tvb.core.adapters.abcadapter.ABCAdapter

Abstract class, for marking adapters that are prone to be NOT executed on Cluster.

tvb.core.adapters.abcadapter.nan_allowed()[source]

Annotation that configures NumPy not to throw an exception in case of floating points errors are computed. It should be used on Adapter methods where computation of NaN/ Inf/etc. is allowed.

tvb.core.adapters.abcadapter.nan_not_allowed()[source]

Annotation that guides NumPy behavior in case of floating point errors. The NumPy default is to just print a warning to sys.stdout, this annotation will raise our custom exception. This annotation will enforce that an exception is thrown in case a floating point error is produced.

e.g. If NaN is take as input and not produced inside the context covered by this annotation,
nothing happens from this method p.o.v.
e.g. If inside a method annotated with this method we have something like numpy.log(-1),
then LaunchException is thrown.

abcdisplayer

class tvb.core.adapters.abcdisplayer.ABCDisplayer[source]

Bases: tvb.core.adapters.abcadapter.ABCSynchronous

Abstract class, for marking Adapters used for UI display only.

KEY_CONTENT = 'mainContent'
KEY_CONTENT_MODULE = 'keyContentModule'
KEY_IS_ADAPTER = 'isAdapter'
PARAM_FIGURE_SIZE = 'figure_size'
VISUALIZERS_ROOT = ''
VISUALIZERS_URL_PREFIX = ''
build_display_result(template, parameters, pages=None)[source]

Helper method for building the result of the ABCDisplayer. :param template : path towards the HTML template to display. It can be absolute path, or relative :param parameters : dictionary with parameters for “template” :param pages : dictionary of pages to be used with <xi:include>

static build_template_params_for_subselectable_datatype(sub_selectable)[source]

creates a template dict with the initial selection to be displayed in a time series viewer

static dump_with_precision(xs, precision=3)[source]

Dump a list of numbers into a string, each at the specified precision.

generate_preview(**kwargs)[source]

Should be implemented by all visualizers that can be used by portlets.

static get_one_dimensional_list(list_of_elements, expected_size, error_msg)[source]

Used for obtaining a list of ‘expected_size’ number of elements from the list ‘list_of_elements’. If the list ‘list_of_elements’ doesn’t have sufficient elements then an exception will be thrown.

list_of_elements - a list of one or two dimensions expected_size - the number of elements that should have the returned list error_msg - the message that will be used for the thrown exception.

get_output()[source]
get_required_disk_size(**kwargs)[source]

Visualizers should no occupy any additional disk space.

static paths2url(datatype_entity, attribute_name, flatten=False, parameter=None)[source]

Prepare a File System Path for passing into an URL.

abcremover

class tvb.core.adapters.abcremover.ABCRemover(handled_datatype)[source]

Bases: object

remove_datatype(skip_validation=False)[source]

Perform basic operation, should overwrite in specific implementations.

constants

exceptions

exception tvb.core.adapters.exceptions.IntrospectionException(message, parent_exception=None)[source]

Bases: tvb.basic.traits.exceptions.TVBException

Exception class for problems when introspection failed.

exception tvb.core.adapters.exceptions.InvalidParameterException(message, parent_exception=None)[source]

Bases: tvb.core.adapters.exceptions.LaunchException

Exception class for parameter validation issue.

exception tvb.core.adapters.exceptions.LaunchException(message, parent_exception=None)[source]

Bases: tvb.basic.traits.exceptions.TVBException

Exception class for problem with launching an operation.

exception tvb.core.adapters.exceptions.NoMemoryAvailableException(message, parent_exception=None)[source]

Bases: tvb.basic.traits.exceptions.TVBException

Exception class raised when an adapter requires more memory that is available on machine.

exception tvb.core.adapters.exceptions.ParseException(message, parent_exception=None)[source]

Bases: tvb.basic.traits.exceptions.TVBException

Exception class for problem with parsing files an operation.

exception tvb.core.adapters.exceptions.XmlParserException(message, parent_exception=None)[source]

Bases: tvb.core.adapters.exceptions.IntrospectionException

Exception class for problems when parsing xml files.

input_tree

Preparation validation and manipulation of adapter input trees .. moduleauthor:: Mihai Andrei <mihai.andrei@codemart.ro>

class tvb.core.adapters.input_tree.InputTreeManager[source]

Bases: object

append_required_defaults(kwargs, algorithm_inputs)[source]

Add if necessary any parameters marked as required that have a default value in the algorithm interface but were not submitted from the UI. For example in operations launched from context-menu or from data structure.

convert_ui_inputs(flat_input_interface, kwargs, metadata_out, validation_required=True)[source]

Convert HTTP POST parameters into Python parameters.

static fill_defaults(adapter_interface, data, fill_unselected_branches=False)[source]

Change the default values in the Input Interface Tree.

fill_input_tree_with_options(attributes_list, project_id, category_key)[source]

For a datatype node in the input tree, load all instances from the db that fit the filters.

flatten(params_list, prefix=None)[source]

Internal method, to be used recursively, on parameters POST.

static form_prefix(input_param, prefix=None, option_prefix=None)[source]

Compute parameter prefix. We need to be able from the flatten submitted values in UI, to be able to re-compose the tree of parameters, and to make sure all submitted names are uniquely identified.

populate_option_values_for_dtype(project_id, type_name, filter_condition=None, category_key=None)[source]

Converts all datatypes that match the project_id, type_name and filter_condition to a {name: , value:} dict used to populate options in the input tree ui

static prepare_param_names(attributes_list, prefix=None, add_option_prefix=False)[source]

For a given attribute list, change the name of the attributes where needed. Changes refer to adding a prefix, to identify groups. Will be used on parameters page GET.

review_operation_inputs(parameters, flat_interface)[source]

Find out which of the submitted parameters are actually DataTypes and return a list holding all the dataTypes in parameters. :returns: list of dataTypes and changed parameters.

static select_simulator_inputs(full_tree, selection_dictionary, prefix='')[source]

Cut Simulator input Tree, to display only user-checked inputs.

Parameters:
  • full_tree – the simulator input tree
  • selection_dictionary – a dictionary that keeps for each entry a default value and if it is check or not.
  • prefix – a prefix to be added to the ui_name in case a select with subtrees is not selected

input_tree2

Preparation validation and manipulation of adapter input trees .. moduleauthor:: Mihai Andrei <mihai.andrei@codemart.ro>

class tvb.core.adapters.input_tree2.InputTreeManager[source]

Bases: object

append_required_defaults(kwargs, algorithm_inputs)[source]

Add if necessary any parameters marked as required that have a default value in the algorithm interface but were not submitted from the UI. For example in operations launched from context-menu or from data structure.

convert_ui_inputs(flat_input_interface, kwargs, metadata_out, validation_required=True)[source]

Convert HTTP POST parameters into Python parameters.

static fill_defaults(adapter_interface, data, fill_unselected_branches=False)[source]

Change the default values in the Input Interface Tree.

fill_input_tree_with_options(attributes_list, project_id, category_key)[source]

For a datatype node in the input tree, load all instances from the db that fit the filters.

flatten(params_list, prefix=None)[source]

Internal method, to be used recursively, on parameters POST.

static form_prefix(input_param, prefix=None, option_prefix=None)[source]

Compute parameter prefix. We need to be able from the flatten submitted values in UI, to be able to re-compose the tree of parameters, and to make sure all submitted names are uniquely identified.

populate_option_values_for_dtype(project_id, type_name, filter_condition=None, category_key=None, complex_dt_attributes=None)[source]

Converts all datatypes that match the project_id, type_name and filter_condition to a {name: , value:} dict used to populate options in the input tree ui

static prepare_param_names(attributes_list, prefix=None, add_option_prefix=False)[source]

For a given attribute list, change the name of the attributes where needed. Changes refer to adding a prefix, to identify groups. Will be used on parameters page GET.

review_operation_inputs(parameters, flat_interface)[source]

Find out which of the submitted parameters are actually DataTypes and return a list holding all the dataTypes in parameters. :returns: list of dataTypes and changed parameters.

static select_simulator_inputs(full_tree, selection_dictionary, prefix='')[source]

Cut Simulator input Tree, to display only user-checked inputs.

Parameters:
  • full_tree – the simulator input tree
  • selection_dictionary – a dictionary that keeps for each entry a default value and if it is check or not.
  • prefix – a prefix to be added to the ui_name in case a select with subtrees is not selected

introspector

class tvb.core.adapters.introspector.Introspector(introspected_module)[source]

This class will handle any external module introspection. By introspecting other Python modules, we expect to find dynamic adapters and DataTypes.

get_events_path()[source]

Returns the EVENTS_FOLDER variable for a given module.

get_removers_dict()[source]

Returns the removers for the datatypes of the current introspected module.

introspect(do_create)[source]
Introspect a given module to:
  • create tables for custom DataType;
  • populate adapter algorithms references.