services Package

This module contains the ‘services’ layer in TVB application.

Most of the business logic happens here; which is agnostic of the UI.


Service layer, for executing computational steps in the application. Code related to launching/duplicating operations is placed here.


Bases: object

Service Layer for Algorithms manipulation (e.g. find all Uploaders, Filter algo by category, etc)

For a list of dataType IDs and a project id create all the required links.

fill_adapter_form(adapter_instance: ABCAdapter, post_data: dict, project_id: int, user: User) ABCAdapterForm[source]
fill_selectfield_with_datatypes(field: TraitDataTypeSelectField, project_id: int, extra_conditions: list | None = None) None[source]
static get_algorithm_by_identifier(ident)[source]

Retrieve Algorithm entity by ID. Return None, if ID is not found in DB.

static get_algorithm_by_module_and_class(module, classname)[source]

Get the db entry from the algorithm table for the given module and class.

static get_analyze_groups()[source]

list of AlgorithmTransientGroup entities

static get_category_by_id(identifier)[source]

Pass to DAO the retrieve of category by ID operation.

static get_generic_entity(entity_type, filter_value, select_field)[source]

datatype_gid – Filter only algorithms compatible with this GUID


dict(category_name: List AlgorithmTransientGroup)

get_launchable_algorithms_for_datatype(datatype, categories)[source]
static get_operation_numbers(proj_id)[source]

Count total number of operations started for current project.

static get_raw_categories()[source]

AlgorithmCategory list of entities that have results in RAW state (Creators/Uploaders)

static get_selections_for_project(project_id, datatype_gid)[source]

Retrieved from DB saved selections for current project. If a certain selection doesn’t have all the labels between the labels of the given connectivity than this selection will not be returned. :returns: List of ConnectivitySelection entities.

static get_stored_pse_filters(datatype_group_gid)[source]
static get_upload_algorithms()[source]

List of StoredAdapter entities

static get_visualisers_category()[source]

Retrieve all Algorithm categories, with display capability

prepare_adapter_form(adapter_instance: ABCAdapter = None, form_instance: ABCAdapterForm = None, project_id: int = None, user: User = None, extra_conditions: [] = None) ABCAdapterForm[source]

Remove the link from the datatype given by dt_id to project given by project_id.

static save_measure_points_selection(ui_name, selected_nodes, datatype_gid, project_id)[source]

Store in DB a ConnectivitySelection.

static save_pse_filter(ui_name, datatype_group_gid, threshold_value, applied_on)[source]

Store in DB a PSE filter.



Bases: object

Keycloak configuration class

static get_keycloak_instance()[source]

Bases: type

Metaclass used to generate the singleton instance



Bases: object

static execute(operation_id, user_name_label, adapter_instance)[source]
static stop_operation(operation_id)[source]


Service for serializing a Burst (Simulator) configuration.


Bases: object

Constructs data types based on a burst configuration. Updates the burst configuration.

static group_parameter_values_by_name(model_parameters_list)[source]
@:param model_parameters_list: Given a list of model parameters like this:
[{“a”: 2.0, ‘b’: 1.0},

{“a”: 3.0, ‘b’: 7.0}])

@:return: This method will group them by param name to get:

{‘a’: [2.0, 3.0], ‘b’: [1.0, 7.0]}

write_model_parameters(model_name, model_parameters_list)[source]

Update model parameters in burst config.

  • model_name – This model will be selected in burst

  • model_parameters_list – A list of model parameter configurations. One for each connectivity node. Ex. [{‘a’: 1, ‘b’: 2}, …]


Set noise dispersions in burst config. It will set all nsig fields it can find in the config (at least 1 per stochastic integrator). :param noise_dispersions: A list of noise dispersions. One for each connectivity node. Ex [{‘V’: 1, ‘W’:2}, …]



Bases: object

LAUNCH_BRANCH = 'branch'
LAUNCH_NEW = 'new'
static get_available_bursts(project_id)[source]

Return all the burst for the current project.

static get_burst_for_operation_id(operation_id, is_group=False)[source]
static get_range_param_by_name(param_name, all_range_parameters)[source]
static handle_range_params_at_loading(burst_config, all_range_parameters)[source]
static load_burst_configuration(burst_config_id: int) BurstConfiguration[source]
static load_burst_configuration_from_folder(simulator_folder, project)[source]
load_simulation_from_zip(zip_file, project)[source]
mark_burst_finished(burst_entity, burst_status=None, error_message=None, store_h5_file=True)[source]

Mark Burst status field. Also compute ‘weight’ for current burst: no of operations inside, estimate time on disk…

  • burst_entity – BurstConfiguration to be updated, at finish time.

  • burst_status – BurstConfiguration status. By default BURST_FINISHED

  • error_message – If given, set the status to error and perpetuate the message.

persist_operation_state(operation, operation_status, message=None)[source]

Update Operation instance state. Store it in DB and on HDD/ :param operation: Operation instance :param operation_status: new status :param message: message in case of error :return: operation instance changed

static populate_burst_disk_usage(bursts)[source]

Adds a disk_usage field to each burst object. The disk usage is computed as the sum of the datatypes generated by a burst

static prepare_burst_for_pse(burst_config: BurstConfiguration) BurstConfiguration[source]
prepare_data_for_burst_copy(burst_config_id, burst_name_format, project)[source]
prepare_index_for_metric_result(operation, result_filename, burst)[source]
prepare_indexes_for_simulation_results(operation, result_filenames, burst)[source]
static prepare_metrics_operation(operation)[source]
static prepare_simulation_name(burst, project_id)[source]
static remove_burst_configuration(burst_config_id: int) None[source]
rename_burst(burst_id, new_name)[source]

Rename the burst given by burst_id, setting it’s new name to burst_name.

static store_burst(burst_config)[source]
static store_burst_configuration(burst_config)[source]

For each burst_id received in the id_list read new status from DB and return a list [id, new_status, is_group, message, running_time] tuple.

static update_simulation_fields(burst, op_simulation_id, simulation_gid)[source]

email_sender, address_to, email_subject, email_content, ignore_exception=True)[source]

Sends an Email Message


Exceptions for services layer of the application.

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case of a problem at project import.

exception, parent_exception=None)[source]

Bases: ImportException

Exception to be thrown in case there are issues when importing a datatype group.

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case an email cannot be sent to a user

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case of a problem at project import.

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case of a problem at project import.

exception, parent_exception=None)[source]

Bases: ImportException

Exception to be thrown in case there are missing references when importing a H5 file.

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case of a problem related to Launching and Executing TVB specific Operations.

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case of a problem in the projectservice module.

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case some one tries to remove an entity that is used by other entities.

exception, parent_exception=None)[source]

Bases: TVBException

Base Exception class for Services layer in the application.

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case of a problem related to Structure Storage.

exception, parent_exception=None)[source]

Bases: ServicesBaseException

Exception to be thrown in case of a problem related to creating or managing a user.


Service layer, for storing/retrieving Resulting Figures in TVB.


Bases: object

Service layer for Figure entities.

edit_result_figure(figure_id, **data)[source]

Retrieve and edit a previously stored figure.

static load_figure(figure_id)[source]

Loads a stored figure by its id.


Remove figure from DB and file storage.

retrieve_result_figures(project, user, selected_session_name='all_sessions')[source]

Retrieve from DB all the stored Displayer previews that belongs to the specified session. The previews are for current user and project; grouped by session.

store_result_figure(project, user, img_type, export_data, image_name=None)[source]

Store into a file, Result Image and reference in DB.



Bases: object

LOGGER = <Logger (INFO)>
static check_operations_job()[source]
static handle_hpc_status_changed(operation: Operation, simulator_gid: str, new_status: str) None[source]



Bases: object

Service for importing TVB entities into system. It supports TVB exported H5 files as input, but it should also handle H5 files generated outside of TVB, as long as they respect the same structure.

build_operation_from_file(project, operation_file)[source]

Create Operation entity from metadata file.

static check_import_references(file_path, datatype)[source]
create_view_model(operation_entity, operation_data, new_op_folder, generic_attributes=None, add_params=None)[source]
import_list_of_operations(project, import_path, is_group=False, importer_operation_id=None)[source]

This method scans provided folder and identify all operations that needs to be imported

static import_operation(operation_entity, migration=False)[source]

Store a Operation entity.

import_project_structure(uploaded, user_id)[source]

Execute import operations:

  1. check if ZIP or folder

  2. find all project nodes

  3. for each project node:
    • create project

    • create all operations and groups

    • import all images

    • create all dataTypes

load_datatype_from_file(current_file: str, op_id: int, datatype_group: DataTypeGroup | None = None, current_project_id: int | None = None) HasTraitsIndex[source]

Creates an instance of datatype from storage / H5 file :returns: DatatypeIndex

store_datatype(datatype, current_file=None)[source]

This method stores data type into DB

class, operation_folder, main_view_model=None, dt_paths=None, all_view_model_files=None, is_fake=False, info_from_xml=None)[source]

Bases: object

property is_old_form
property order_field


Module in charge with Launching an operation (creating the Operation entity as well, based on gathered parameters).


Bases: object

Class responsible for preparing an operation launch. It will prepare parameters, and decide if the operation is to be executed immediately, or to be sent on the cluster.

ATT_UID = 'uid'
fire_operation(adapter_instance, current_user, project_id, visible=True, view_model=None)[source]

Launch an operation, specified by AdapterInstance, for current_user and project with project_id.

fits_max_operation_size(adapter_instance, view_model, project_id, range_length=1)[source]
group_operation_launch(user_id, project, algorithm_id, category_id)[source]

Create and prepare the launch of a group of operations.

initiate_operation(current_user, project, adapter_instance, visible=True, model_view=None)[source]

Gets the parameters of the computation from the previous inputs form, and launches a computation (on the cluster or locally).

Invoke custom method on an Adapter Instance. Make sure when the operation has finished that the correct results are stored into DB.

initiate_prelaunch(operation, adapter_instance)[source]

Public method. This should be the common point in calling an adapter- method.

launch_operation(operation_id, send_to_cluster=False, adapter_instance=None)[source]

Method exposed for Burst-Workflow related calls. It is used for cascading operation in the same workflow.

static load_operation(operation_id)[source]

Retrieve previously stored Operation from DB, and load operation.burst attribute

static prepare_metadata(algo_category, burst=None, current_ga=<tvb.core.entities.generic_attributes.GenericAttributes object>)[source]

Gather generic_metadata from submitted fields and current to be execute algorithm. Will populate STATE, GROUP, etc in generic_metadata

prepare_operation(user_id, project, algorithm, visible=True, view_model=None, ranges=None, burst_gid=None, op_group_id=None)[source]

Do all the necessary preparations for storing an operation. If it’s the case of a range of values create an operation group and multiple operations for each possible instance from the range.

static stop_operation(operation_id: int, is_group: bool = False, remove_after_stop: bool = False) bool[source]

Stop (also named Cancel) the operation given by operation_id, and potentially also remove it after (with all linked data). In case the Operation has a linked Burst, remove that too. :param operation_id: ID for Operation (or OperationGroup) to be canceled/removed :param is_group: When true stop all the operations from that group. :param remove_after_stop: if True, also remove the operation(s) after stopping :returns True if the stop step was successfully

static store_view_model(operation, project, view_model)[source]


Service Layer for the Project entity.


Bases: object

Services layer for Project entities.

static count_filtered_operations(project_id, filters=None)[source]

Pass to DAO counters for filtered operations


Simply retrieve Project entity from Database.


Simply retrieve Project entity from Database by gid.

static get_all_datatypes_from_data(data)[source]

This method builds an array with all data types to be processed later. - If current data is a simple data type is added to an array. - If it is an data type group all its children are loaded and added to array.

static get_all_operations_for_uploaders(project_id)[source]

Returns all finished upload operations.

static get_datatype_by_id(datatype_id)[source]

Retrieve a DataType DB reference by its id.

static get_datatype_details(datatype_gid)[source]

an array. First entry in array is an instance of DataTypeOverlayDetails The second one contains all the possible states for the specified dataType.

static get_datatype_in_group(group)[source]

Return all dataTypes that are the result of the same DTgroup.

static get_datatypegroup_by_gid(datatypegroup_gid)[source]

Returns the DataTypeGroup with the specified gid.

static get_datatypegroup_by_op_group_id(operation_group_id)[source]

Returns the DataTypeGroup with the specified id.

static get_datatypes_from_datatype_group(datatype_group_id)[source]

Retrieve all dataType which are part from the given dataType group.

static get_datatypes_in_project(project_id)[source]
static get_filterable_meta()[source]

Contains all the attributes by which the user can structure the tree of DataTypes

static get_linkable_projects_for_user(user_id, data_id)[source]

Find projects with are visible for current user, and in which current datatype hasn’t been linked yet.


the file paths to the datatypes that are linked in project

get_operation_details(operation_gid, is_group)[source]

an entity OperationOverlayDetails filled with all information for current operation details.

static get_operation_group_by_gid(operation_group_gid)[source]

Loads OperationGroup from DB

static get_operation_group_by_id(operation_group_id)[source]

Loads OperationGroup from DB

static get_operations_in_group(operation_group)[source]

Return all the operations from an operation group.

get_project_structure(project, visibility_filter, first_level, second_level, filter_value)[source]

Find all DataTypes (including the linked ones and the groups) relevant for the current project. In case of a problem, will return an empty list.

static get_results_for_operation(operation_id)[source]

Retrieve the DataTypes entities resulted after the execution of the given operation.

static is_datatype_group(datatype_gid)[source]

Used to check if the dataType with the specified GID is a DataTypeGroup.

static is_upload_operation(operation_gid)[source]

Returns True only if the operation with the given GID is an upload operation.

static load_operation_by_gid(operation_gid)[source]

Retrieve loaded Operation from DB

static load_operation_lazy_by_gid(operation_gid)[source]

Retrieve lazy Operation from DB

remove_datatype(project_id, datatype_gid, skip_validation=False, existing_dt_links=None)[source]

Method used for removing a dataType. If the given dataType is a DatatypeGroup or a dataType from a DataTypeGroup than this method will remove the entire group. The operation(s) used for creating the dataType(s) will also be removed.

remove_member_from_project(proj_id, user_id)[source]

remove a user from the list of members of that project


Remove a given operation


Remove Project from DB and File Storage.

static retrieve_all_user_projects(user_id, page_start=0, page_size=20)[source]

Return a list with all projects visible for current user, without pagination.

retrieve_project_full(project_id, applied_filters=None, current_page=1)[source]

Return a Tuple with Project entity and Operations for current Project. :param project_id: Current Project Identifier :param applied_filters: Filters to apply on Operations :param current_page: Number for current page in operations

retrieve_projects_for_user(user_id, current_page=1)[source]

Return a list with all Projects visible for current user.

static set_datatype_visibility(datatype_gid, is_visible)[source]

Sets the dataType visibility. If the given dataType is a dataType group or it is part of a dataType group than this method will set the visibility for each dataType from this group.

set_operation_and_group_visibility(entity_gid, is_visible, is_operation_group=False)[source]

Sets the operation visibility.

If ‘is_operation_group’ is True than this method will change the visibility for all the operation from the OperationGroup with the GID field equal to ‘entity_gid’.

store_project(current_user, is_create, selected_id, **data)[source]

We want to create/update a project entity.


Update DataType/ DataTypeGroup metadata THROW StructureException when input data is invalid.[source]

Create Projects storage root folder in case it does not exist.


Service layer for saving/editing TVB settings.


Bases: object

Handle all TVB Setting related problems, at the service level.


Validate DB URL, that a connection can be done.

static get_disk_free_space(storage_path)[source]

the available HDD space in KB in TVB_STORAGE folder.


Check if new settings are correct. Make necessary changes, then save new data in configuration file.


two boolean values -there were any changes to the configuration; -a reset should be performed on the TVB relaunch.



Bases: object

async_launch_and_prepare_pse(burst_config, user, project, simulator_algo, range_param1, range_param2, session_stored_simulator)[source]
async_launch_and_prepare_simulation(burst_config, user, project, simulator_algo, simulator)[source]
async_launch_simulation_on_server(operation, zip_folder_path)[source]
static compute_conn_branch_conditions(is_branch, simulator)[source]
get_simulation_state_index(burst_config, simulation_history_class)[source]
prepare_simulation_on_server(user_id, project, algorithm, zip_folder_path, simulator_file)[source]
reset_at_connectivity_change(is_simulator_copy, form, session_stored_simulator)[source]

In case the user copies a simulation and changes the Connectivity, we want to reset the Model and Noise parameters because they might not fit to the new Connectivity’s nr of regions.

reset_at_surface_change(is_simulator_copy, form, session_stored_simulator)[source]

In case the user copies a surface-simulation and changes the Surface, we want to reset the Model parameters because they might not fit to the new Surface’s nr of vertices.

static validate_first_fragment(form, project_id, conn_idx)[source]


Converts a color scheme texture image to json arrays, img_width, band_height)[source]
  • img_pth – Path to the texure

  • img_width – Texture width

  • band_height – Height of a color scheme band


A list of img_width/band_height color schemes. A scheme is a list of img_width colors


Service layer for USER entities.


Bases: object

CRUD methods for USER entities are here.

static check_login(username, password)[source]

Service layer to check if given UserName and Password are according to DB.

static compute_user_generated_disk_size(user_id)[source]
create_user(username=None, display_name=None, password=None, password2=None, role=None, email=None, comment=None, email_msg=None, validated=False, skip_import=False, gid=None, skip_sending_email=False)[source]

Service Layer for creating a new user.


Delete a user with a given ID. Return True when successfully, or False.

edit_user(edited_user, old_password=None)[source]

Retrieve a user by and id, then modify it’s role and validate status.

static get_administrators()[source]

Retrieve system administrators. Will be used for sending emails, for example.

static get_user_by_gid(gid)[source]

Retrieves a user by its gid.

static get_user_by_id(user_id)[source]

Retrieves a user by its id.

static get_user_by_name(username)[source]

Retrieves a user by its username.

get_users_for_project(user_name, project_id, page=1)[source]

Return tuple: (All Users except the project administrator, Project Members). Parameter “user_name” is the current user. Parameter “user_name” is used for new projects (project_id is None). When “project_id” not None, parameter “user_name” is ignored.

static is_username_valid(name)[source]

Service layer for checking if a given UserName is unique or not.


Service Layer for resetting a password.

static retrieve_users_except(usernames: list, current_page: int, page_size: int)[source]

Return all users from the database except the given users

static save_project_to_user(user_id, project_id)[source]

Mark for current user that the given project is the last one selected.

validate_user(name='', user_id=None)[source]

Service layer for editing a user and validating the account.