本文整理汇总了Python中tvb.core.services.flow_service.FlowService.fire_operation方法的典型用法代码示例。如果您正苦于以下问题:Python FlowService.fire_operation方法的具体用法?Python FlowService.fire_operation怎么用?Python FlowService.fire_operation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tvb.core.services.flow_service.FlowService
的用法示例。
在下文中一共展示了FlowService.fire_operation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_datatypes_groups
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
def test_datatypes_groups(self):
"""
Tests if the dataType group is set correct on the dataTypes resulted from the same operation group.
"""
flow_service = FlowService()
all_operations = dao.get_filtered_operations(self.test_project.id, None)
assert len(all_operations) == 0, "There should be no operation"
adapter_instance = TestFactory.create_adapter('tvb.tests.framework.adapters.testadapter3', 'TestAdapter3')
data = {model.RANGE_PARAMETER_1: 'param_5', 'param_5': [1, 2]}
## Create Group of operations
flow_service.fire_operation(adapter_instance, self.test_user, self.test_project.id, **data)
all_operations = dao.get_filtered_operations(self.test_project.id, None)
assert len(all_operations) == 1, "Expected one operation group"
assert all_operations[0][2] == 2, "Expected 2 operations in group"
operation_group_id = all_operations[0][3]
assert operation_group_id != None, "The operation should be part of a group."
self.operation_service.stop_operation(all_operations[0][0])
self.operation_service.stop_operation(all_operations[0][1])
## Make sure operations are executed
self.operation_service.launch_operation(all_operations[0][0], False)
self.operation_service.launch_operation(all_operations[0][1], False)
resulted_datatypes = dao.get_datatype_in_group(operation_group_id=operation_group_id)
assert len(resulted_datatypes) >= 2, "Expected at least 2, but: " + str(len(resulted_datatypes))
dt = dao.get_datatype_by_id(resulted_datatypes[0].id)
datatype_group = dao.get_datatypegroup_by_op_group_id(operation_group_id)
assert dt.fk_datatype_group == datatype_group.id, "DataTypeGroup is incorrect"
示例2: test_datatypes_groups
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
def test_datatypes_groups(self):
"""
Tests if the dataType group is set correct on the dataTypes resulted from the same operation group.
"""
flow_service = FlowService()
all_operations = dao.get_filtered_operations(self.test_project.id, None)
self.assertEqual(len(all_operations), 0, "There should be no operation")
algogroup = dao.find_group("tvb.tests.framework.adapters.testadapter3", "TestAdapter3")
group, _ = flow_service.prepare_adapter(self.test_project.id, algogroup)
adapter_instance = flow_service.build_adapter_instance(group)
data = {model.RANGE_PARAMETER_1: "param_5", "param_5": [1, 2]}
## Create Group of operations
flow_service.fire_operation(adapter_instance, self.test_user, self.test_project.id, **data)
all_operations = dao.get_filtered_operations(self.test_project.id, None)
self.assertEqual(len(all_operations), 1, "Expected one operation group")
self.assertEqual(all_operations[0][2], 2, "Expected 2 operations in group")
operation_group_id = all_operations[0][3]
self.assertNotEquals(operation_group_id, None, "The operation should be part of a group.")
self.operation_service.stop_operation(all_operations[0][0])
self.operation_service.stop_operation(all_operations[0][1])
## Make sure operations are executed
self.operation_service.launch_operation(all_operations[0][0], False)
self.operation_service.launch_operation(all_operations[0][1], False)
resulted_datatypes = dao.get_datatype_in_group(operation_group_id=operation_group_id)
self.assertTrue(len(resulted_datatypes) >= 2, "Expected at least 2, but: " + str(len(resulted_datatypes)))
dt = dao.get_datatype_by_id(resulted_datatypes[0].id)
datatype_group = dao.get_datatypegroup_by_op_group_id(operation_group_id)
self.assertEqual(dt.fk_datatype_group, datatype_group.id, "DataTypeGroup is incorrect")
示例3: fire_simulation
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
def fire_simulation(project_id=1, **kwargs):
project = dao.get_project_by_id(project_id)
flow_service = FlowService()
# below the holy procedure to launch with the correct parameters taken from the defaults
stored_adapter = flow_service.get_algorithm_by_module_and_class(SIMULATOR_MODULE, SIMULATOR_CLASS)
simulator_adapter = ABCAdapter.build_adapter(stored_adapter)
flatten_interface = simulator_adapter.flaten_input_interface()
itree_mngr = flow_service.input_tree_manager
prepared_flatten_interface = itree_mngr.fill_input_tree_with_options(flatten_interface, project.id,
stored_adapter.fk_category)
launch_args = {}
for entry in prepared_flatten_interface:
value = entry['default']
if isinstance(value, dict):
value = str(value)
if hasattr(value, 'tolist'):
value = value.tolist()
launch_args[entry['name']] = value
launch_args.update(**kwargs)
# end of magic
launched_operation = flow_service.fire_operation(simulator_adapter, project.administrator,
project.id, **launch_args)[0]
return launched_operation
示例4: import_h5
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
def import_h5(file_path, project_id):
flow_service = FlowService()
## This ID of a project needs to exists in Db, and it can be taken from the WebInterface:
project = dao.get_project_by_id(project_id)
adapter_instance = ABCAdapter.build_adapter_from_class(TVBImporter)
## Prepare the input algorithms as if they were coming from web UI submit:
launch_args = {"data_file": file_path}
print "We will try to import file at path " + file_path
## launch an operation and have the results stored both in DB and on disk
launched_operations = flow_service.fire_operation(
adapter_instance, project.administrator, project.id, **launch_args
)
print "Operation launched. Check the web UI"
示例5: ModelValidator
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
class ModelValidator(object):
overwrites = {}
def __init__(self, overwrites=None, settings_file=None):
""" Parameters can be overwritten either from a settigns file or from a dictionary. """
if overwrites is not None:
self.overwrites.update(overwrites)
if settings_file is not None:
settings = open(sys.argv[1]).read()
for line in settings.split('\n'):
key, value = line.split('=')
self.overwrites[key.strip()] = value.strip()
if KEY_PROJECT not in self.overwrites:
raise Exception("Settings file should contain the id of the project: %s=1" % KEY_PROJECT)
self.project = dao.get_project_by_id(self.overwrites[KEY_PROJECT])
self.flow_service = FlowService()
self.operation_service = OperationService()
def launch_validation(self):
"""
Prepare the arguments to be submitted and launch actual operations group.
TODO: Now get the results and check if any errors
"""
stored_adapter = self.flow_service.get_algorithm_by_module_and_class(SIMULATOR_MODULE, SIMULATOR_CLASS)
simulator_adapter = ABCAdapter.build_adapter(stored_adapter)
launch_args = {}
flatten_interface = simulator_adapter.flaten_input_interface()
itree_mngr = self.flow_service.input_tree_manager
prepared_flatten_interface = itree_mngr.fill_input_tree_with_options(flatten_interface, self.project.id,
stored_adapter.fk_category)
for entry in prepared_flatten_interface:
value = entry['default']
if isinstance(value, dict):
value = str(value)
if hasattr(value, 'tolist'):
value = value.tolist()
launch_args[entry['name']] = value
launch_args.update(self.overwrites)
nr_of_operations = 1
for key in self.overwrites:
if key.startswith(PARAM_RANGE_PREFIX):
range_values = self.operation_service.get_range_values(launch_args, key)
nr_of_operations *= len(range_values)
do_launch = False
print "Warning! This will launch %s operations. Do you agree? (yes/no)" % nr_of_operations
while 1:
accept = raw_input()
if accept.lower() == 'yes':
do_launch = True
break
if accept.lower() == 'no':
do_launch = False
break
print "Please type either yes or no"
if do_launch:
self.launched_operations = self.flow_service.fire_operation(simulator_adapter, self.project.administrator,
self.project.id, **launch_args)
return self.validate_results(0)
else:
return "Operation canceled by user."
def validate_results(self, last_verified_index):
error_count = 0
while last_verified_index < len(self.launched_operations):
operation_to_check = self.launched_operations[last_verified_index]
operation = dao.get_operation_by_id(operation_to_check.id)
if not operation.has_finished:
sleep(10)
if operation.status == STATUS_ERROR:
sys.stdout.write("E(" + str(operation_to_check.id) + ")")
error_count += 1
last_verified_index += 1
sys.stdout.flush()
if operation.status == STATUS_FINISHED:
last_verified_index += 1
sys.stdout.write('.')
sys.stdout.flush()
if error_count:
return "%s operations in error; %s operations successfully." % (error_count,
len(self.launched_operations) - error_count)
return "All operations finished successfully!"
示例6: ProjectStructureTest
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
#.........这里部分代码省略.........
self.project_service.remove_datatype(project.id, first_dt.gid)
self._check_if_datatype_was_removed(first_dt)
self._check_if_datatype_was_removed(second_dt)
self._check_if_datatype_was_removed(datatype_group)
self._check_datatype_group_removed(dt_group_id, datatype_group.fk_operation_group)
def test_remove_datatype_group(self):
"""
Tests the deletion of a datatype group.
"""
project, dt_group_id, first_dt, second_dt = self._create_datatype_group()
datatype_group = dao.get_generic_entity(model.DataTypeGroup, dt_group_id)[0]
self.project_service.remove_datatype(project.id, datatype_group.gid)
self._check_if_datatype_was_removed(first_dt)
self._check_if_datatype_was_removed(second_dt)
self._check_if_datatype_was_removed(datatype_group)
self._check_datatype_group_removed(dt_group_id, datatype_group.fk_operation_group)
def _create_mapped_arrays(self, project_id):
"""
:param project_id: the project in which the arrays are created
:return: a list of dummy `MappedArray`
"""
count = self.flow_service.get_available_datatypes(project_id, "tvb.datatypes.arrays.MappedArray")[1]
self.assertEqual(count, 0)
group = dao.get_algorithm_by_module('tvb.tests.framework.adapters.ndimensionarrayadapter', 'NDimensionArrayAdapter')
adapter_instance = ABCAdapter.build_adapter(group)
data = {'param_1': 'some value'}
#create 3 data types
self.flow_service.fire_operation(adapter_instance, self.test_user, project_id, **data)
count = self.flow_service.get_available_datatypes(project_id, "tvb.datatypes.arrays.MappedArray")[1]
self.assertEqual(count, 1)
self.flow_service.fire_operation(adapter_instance, self.test_user, project_id, **data)
count = self.flow_service.get_available_datatypes(project_id, "tvb.datatypes.arrays.MappedArray")[1]
self.assertEqual(count, 2)
self.flow_service.fire_operation(adapter_instance, self.test_user, project_id, **data)
array_wrappers, count = self.flow_service.get_available_datatypes(project_id,
"tvb.datatypes.arrays.MappedArray")
self.assertEqual(count, 3)
return array_wrappers
def _create_operation(self, project_id, algorithm_id):
"""
dummy operation
:param project_id: the project in which the operation is created
:param algorithm_id: the algorithm to be run for the operation
:return: a dummy `Operation` with the given specifications
"""
algorithm = dao.get_algorithm_by_id(algorithm_id)
meta = {DataTypeMetaData.KEY_SUBJECT: "John Doe",
DataTypeMetaData.KEY_STATE: "RAW_DATA"}
operation = model.Operation(self.test_user.id, project_id, algorithm.id, 'test params',
meta=json.dumps(meta), status=model.STATUS_FINISHED)
return dao.store_entity(operation)
def _create_datatype_group(self):
"""
示例7: dict
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
adapter_instance = ABCAdapter.build_adapter_from_class(SimulatorAdapter)
## Prepare the input algorithms as if they were coming from web UI submit:
## TODO create helper methods for working with objects instead of strings.
connectivity = dao.get_generic_entity(Connectivity, DataTypeMetaData.DEFAULT_SUBJECT, "subject")[0]
launch_args = dict()
for f in adapter_instance.flaten_input_interface():
launch_args[f["name"]] = str(f["default"]) if 'default' in f else None
launch_args["connectivity"] = connectivity.gid
launch_args["model_parameters_option_Generic2dOscillator_variables_of_interest"] = 'V'
if len(sys.argv) > 1:
launch_args["model_parameters_option_Generic2dOscillator_tau"] = sys.argv[1]
## launch an operation and have the results stored both in DB and on disk
launched_operation = flow_service.fire_operation(adapter_instance, project.administrator,
project.id, **launch_args)[0]
## wait for the operation to finish
while not launched_operation.has_finished:
sleep(5)
launched_operation = dao.get_operation_by_id(launched_operation.id)
if launched_operation.status == model.STATUS_FINISHED:
ts = dao.get_generic_entity(TimeSeriesRegion, launched_operation.id, "fk_from_operation")[0]
LOG.info("TimeSeries result is: %s " % ts.summary_info)
print ts.summary_info
else:
LOG.warning("Operation ended with problems [%s]: [%s]" % (launched_operation.status,
launched_operation.additional_info))
示例8: FlowServiceTest
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
#.........这里部分代码省略.........
def test_build_adapter_instance(self):
"""
Test standard flow for building an adapter instance.
"""
algo_group = dao.find_group(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_VALID_CLASS)
adapter = ABCAdapter.build_adapter(algo_group)
self.assertTrue(isinstance(adapter, ABCSynchronous), "Something went wrong with valid data!")
def test_build_adapter_invalid(self):
"""
Test flow for trying to build an adapter that does not inherit from ABCAdapter.
"""
group = dao.find_group(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_INVALID_CLASS)
self.assertRaises(OperationException, self.flow_service.build_adapter_instance, group)
def test_prepare_adapter(self):
"""
Test preparation of an adapter.
"""
algo_group = dao.find_group(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_VALID_CLASS)
group, interface = self.flow_service.prepare_adapter(self.test_project.id, algo_group)
self.assertTrue(isinstance(group, model.AlgorithmGroup), "Something went wrong with valid data!")
self.assertTrue("name" in interface[0], "Bad interface created!")
self.assertEquals(interface[0]["name"], "test", "Bad interface!")
self.assertTrue("type" in interface[0], "Bad interface created!")
self.assertEquals(interface[0]["type"], "int", "Bad interface!")
self.assertTrue("default" in interface[0], "Bad interface created!")
self.assertEquals(interface[0]["default"], "0", "Bad interface!")
def test_fire_operation(self):
"""
Test preparation of an adapter and launch mechanism.
"""
algo_group = dao.find_group(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_VALID_CLASS)
adapter = self.flow_service.build_adapter_instance(algo_group)
data = {"test": 5}
result = self.flow_service.fire_operation(adapter, self.test_user, self.test_project.id, **data)
self.assertTrue(result.endswith("has finished."), "Operation fail")
def test_get_filtered_by_column(self):
"""
Test the filter function when retrieving dataTypes with a filter
after a column from a class specific table (e.g. DATA_arraywrapper).
"""
operation_1 = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
operation_2 = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
one_dim_array = numpy.arange(5)
two_dim_array = numpy.array([[1, 2], [2, 3], [1, 4]])
self._store_float_array(one_dim_array, "John Doe 1", operation_1.id)
self._store_float_array(one_dim_array, "John Doe 2", operation_1.id)
self._store_float_array(two_dim_array, "John Doe 3", operation_2.id)
count = self.flow_service.get_available_datatypes(self.test_project.id, "tvb.datatypes.arrays.MappedArray")[1]
self.assertEqual(count, 3, "Problems with inserting data")
first_filter = FilterChain(fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[1])
count = self.flow_service.get_available_datatypes(self.test_project.id,
"tvb.datatypes.arrays.MappedArray", first_filter)[1]
self.assertEqual(count, 2, "Data was not filtered")
second_filter = FilterChain(fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[2])
示例9: FlowServiceTest
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import fire_operation [as 别名]
#.........这里部分代码省略.........
def test_build_adapter_instance(self):
"""
Test standard flow for building an adapter instance.
"""
adapter = TestFactory.create_adapter(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_VALID_CLASS)
self.assertTrue(isinstance(adapter, ABCSynchronous), "Something went wrong with valid data!")
def test_build_adapter_invalid(self):
"""
Test flow for trying to build an adapter that does not inherit from ABCAdapter.
"""
group = dao.get_algorithm_by_module(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_INVALID_CLASS)
self.assertRaises(IntrospectionException, ABCAdapter.build_adapter, group)
def test_prepare_adapter(self):
"""
Test preparation of an adapter.
"""
stored_adapter = dao.get_algorithm_by_module(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_VALID_CLASS)
interface = self.flow_service.prepare_adapter(self.test_project.id, stored_adapter)
self.assertTrue(isinstance(stored_adapter, model.Algorithm), "Something went wrong with valid data!")
self.assertTrue("name" in interface[0], "Bad interface created!")
self.assertEquals(interface[0]["name"], "test", "Bad interface!")
self.assertTrue("type" in interface[0], "Bad interface created!")
self.assertEquals(interface[0]["type"], "int", "Bad interface!")
self.assertTrue("default" in interface[0], "Bad interface created!")
self.assertEquals(interface[0]["default"], "0", "Bad interface!")
def test_fire_operation(self):
"""
Test preparation of an adapter and launch mechanism.
"""
adapter = TestFactory.create_adapter(TEST_ADAPTER_VALID_MODULE, TEST_ADAPTER_VALID_CLASS)
data = {"test": 5}
result = self.flow_service.fire_operation(adapter, self.test_user, self.test_project.id, **data)
self.assertTrue(result.endswith("has finished."), "Operation fail")
def test_get_filtered_by_column(self):
"""
Test the filter function when retrieving dataTypes with a filter
after a column from a class specific table (e.g. DATA_arraywrapper).
"""
operation_1 = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
operation_2 = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
one_dim_array = numpy.arange(5)
two_dim_array = numpy.array([[1, 2], [2, 3], [1, 4]])
self._store_float_array(one_dim_array, "John Doe 1", operation_1.id)
self._store_float_array(one_dim_array, "John Doe 2", operation_1.id)
self._store_float_array(two_dim_array, "John Doe 3", operation_2.id)
count = self.flow_service.get_available_datatypes(self.test_project.id, "tvb.datatypes.arrays.MappedArray")[1]
self.assertEqual(count, 3, "Problems with inserting data")
first_filter = FilterChain(fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[1])
count = self.flow_service.get_available_datatypes(self.test_project.id,
"tvb.datatypes.arrays.MappedArray", first_filter)[1]
self.assertEqual(count, 2, "Data was not filtered")
second_filter = FilterChain(fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[2])
filtered_data = self.flow_service.get_available_datatypes(self.test_project.id,