Exemple #1
0
    def test_export(self):
        op = TestFactory.create_operation(test_user=self.test_user,
                                          test_project=self.test_project)
        burst_config = BurstConfiguration(self.test_project.id)
        burst_config.fk_simulation = op.id
        burst_config.simulator_gid = self.session_stored_simulator.gid.hex
        burst_config = dao.store_entity(burst_config)

        storage_path = FilesHelper().get_project_folder(
            self.test_project, str(op.id))
        h5_path = h5.path_for(storage_path, SimulatorH5,
                              self.session_stored_simulator.gid)
        with SimulatorH5(h5_path) as h5_file:
            h5_file.store(self.session_stored_simulator)

        burst = dao.get_bursts_for_project(self.test_project.id)
        self.sess_mock['burst_id'] = str(burst[0].id)

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_BURST_CONFIG,
                               self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG, burst_config)
            result = self.simulator_controller.export(str(burst[0].id))

        assert path.exists(result.input.name), "Simulation was not exported!"
Exemple #2
0
    def build(project):
        range_1 = ["row1", [1, 2, 10]]
        range_2 = ["row2", [0.1, 0.3, 0.5]]

        group = OperationGroup(
            project.id, ranges=[json.dumps(range_1),
                                json.dumps(range_2)])
        group = dao.store_entity(group)
        group_ms = OperationGroup(
            project.id, ranges=[json.dumps(range_1),
                                json.dumps(range_2)])
        group_ms = dao.store_entity(group_ms)

        datatype_group = DataTypeGroup(group)
        datatype_group.no_of_ranges = 2
        datatype_group.count_results = 10
        dao.store_entity(datatype_group)

        dt_group_ms = DataTypeGroup(group_ms)
        dao.store_entity(dt_group_ms)

        burst = BurstConfiguration(project.id, name='test_burst')
        burst.simulator_gid = uuid.uuid4().hex
        burst.fk_operation_group = group.id
        burst.fk_metric_operation_group = group_ms.id
        burst = dao.store_entity(burst)
        return burst
Exemple #3
0
    def test_load_burst_only(self):
        zip_path = path.join(path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip')
        connectivity = TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path, "John")

        op = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
        burst_config = BurstConfiguration(self.test_project.id)
        burst_config.fk_simulation = op.id
        burst_config.simulator_gid = self.session_stored_simulator.gid.hex
        burst_config.name = 'Test_Burst'
        burst_config = dao.store_entity(burst_config)

        self.sess_mock['burst_id'] = str(burst_config.id)
        self.sess_mock['connectivity'] = connectivity.gid
        self.sess_mock['conduction_speed'] = "3.0"
        self.sess_mock['coupling'] = "Sigmoidal"

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_SIMULATOR_CONFIG, self.session_stored_simulator)
            self.simulator_controller.set_connectivity(**self.sess_mock._data)
            self.simulator_controller.set_stimulus(**self.sess_mock._data)

        storage_path = FilesHelper().get_project_folder(self.test_project, str(op.id))
        SimulatorSerializer().serialize_simulator(self.session_stored_simulator, None, storage_path)

        with patch('cherrypy.session', self.sess_mock, create=True):
            self.simulator_controller.load_burst_read_only(str(burst_config.id))
            is_simulator_load = common.get_from_session(KEY_IS_SIMULATOR_LOAD)
            is_simulator_copy = common.get_from_session(KEY_IS_SIMULATOR_COPY)
            last_loaded_form_url = common.get_from_session(KEY_LAST_LOADED_FORM_URL)

        assert is_simulator_load, "Simulator Load Flag should be True!"
        assert not is_simulator_copy, "Simulator Copy Flag should be False!"
        assert last_loaded_form_url == '/burst/setup_pse', "Incorrect last form URL!"
Exemple #4
0
    def test_export_simulator_configuration(self, operation_factory,
                                            connectivity_index_factory):
        """
        Test export of a simulator configuration
        """
        conn_gid = uuid.UUID(connectivity_index_factory().gid)
        operation = operation_factory(is_simulation=True,
                                      store_vm=True,
                                      test_project=self.test_project,
                                      conn_gid=conn_gid)

        burst_configuration = BurstConfiguration(self.test_project.id)
        burst_configuration.fk_simulation = operation.id
        burst_configuration.simulator_gid = operation.view_model_gid
        burst_configuration.name = "Test_burst"
        burst_configuration = dao.store_entity(burst_configuration)

        op_folder = StorageInterface().get_project_folder(
            self.test_project.name, str(operation.id))
        BurstService().store_burst_configuration(burst_configuration,
                                                 op_folder)

        export_file = self.export_manager.export_simulator_configuration(
            burst_configuration.id)

        assert export_file is not None, "Export process should return path to export file"
        assert os.path.exists(
            export_file
        ), "Could not find export file: %s on disk." % export_file
        assert zipfile.is_zipfile(
            export_file), "Generated file is not a valid ZIP file"
Exemple #5
0
    def test_export_simulator_configuration(self, operation_factory,
                                            connectivity_factory):
        """
        Test export of a simulator configuration
        """
        operation = operation_factory()
        simulator = SimulatorAdapterModel()
        simulator.connectivity = connectivity_factory(4).gid

        burst_configuration = BurstConfiguration(self.test_project.id)
        burst_configuration.fk_simulation_id = operation.id
        burst_configuration.simulator_gid = simulator.gid.hex
        burst_configuration = dao.store_entity(burst_configuration)

        storage_path = FilesHelper().get_project_folder(
            self.test_project, str(operation.id))
        h5_path = h5.path_for(storage_path, SimulatorH5, simulator.gid)
        with SimulatorH5(h5_path) as h5_file:
            h5_file.store(simulator)

        export_file = self.export_manager.export_simulator_configuration(
            burst_configuration.id)

        assert export_file is not None, "Export process should return path to export file"
        assert os.path.exists(
            export_file
        ), "Could not find export file: %s on disk." % export_file
        assert zipfile.is_zipfile(
            export_file), "Generated file is not a valid ZIP file"
Exemple #6
0
 def store_burst(project_id, simulator_config=None):
     """
     Build and persist BurstConfiguration entity.
     """
     burst = BurstConfiguration(project_id)
     if simulator_config is not None:
         burst.simulator_configuration = simulator_config
     return dao.store_entity(burst)
 def _store_burst(self, proj_id, status, sim_config, name):
     """
     Create and store a burst entity, for the project given project_id, having the
     given status and simulator parames config, under the given name.
     """
     burst = BurstConfiguration(proj_id, status, sim_config, name)
     burst.prepare_before_save()
     return dao.store_entity(burst)
 def _store_burst(self, proj_id, status, sim_config, name):
     """
     Create and store a burst entity, for the project given project_id, having the
     given status and simulator parames config, under the given name.
     """
     burst = BurstConfiguration(proj_id, status, sim_config, name)
     burst.prepare_before_save()
     return dao.store_entity(burst)
    def test_set_simulation_length_with_burst_config_name(self):
        burst_config = BurstConfiguration(self.test_project.id)
        burst_config.name = "Test Burst Config"
        self.sess_mock['simulation_length'] = '1000.0'

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_SIMULATOR_CONFIG, self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG, burst_config)
            self.simulator_controller.set_simulation_length(**self.sess_mock._data)

        assert self.session_stored_simulator.simulation_length == 1000.0, "simulation_length was not set correctly."
    def load_burst_entity(self, json_burst, project_id):
        """
        Load BurstConfiguration from JSON (possibly exported from a different machine).
        Nothing gets persisted in DB or on disk.

        :param json_burst: Burst JSON export
        :param project_id: Current project ID (it will be used if the user later starts this simulation)
        :return: BurstConfiguration  filled from JSON
        """

        burst_information = BurstInformation.load_from_dict(json_burst)
        burst_entity = BurstConfiguration(project_id)
        burst_entity.from_dict(burst_information.data)
        burst_entity.prepare_after_load()
        burst_entity.reset_tabs()

        workflow_info = burst_information.get_workflows()[0]
        workflow_entity = Workflow(project_id, None)
        workflow_entity.from_dict(workflow_info.data)

        view_steps = workflow_info.get_view_steps()
        analyze_steps = workflow_info.get_workflow_steps()

        for view_step in view_steps:
            try:
                algorithm = view_step.get_algorithm()
                portlet = view_step.get_portlet()
                view_step_entity = WorkflowStepView(algorithm.id, portlet_id=portlet.id)
                view_step_entity.from_dict(view_step.data)
                view_step_entity.workflow = workflow_entity

                # For each visualize step, also load all of the analyze steps.
                analyzers = []
                for an_step in analyze_steps:
                    if (an_step.data["tab_index"] != view_step_entity.tab_index
                            or an_step.data["index_in_tab"] != view_step_entity.index_in_tab):
                        continue
                    algorithm = an_step.get_algorithm()
                    wf_step_entity = WorkflowStep(algorithm.id)
                    wf_step_entity.from_dict(an_step.data)
                    wf_step_entity.workflow = workflow_entity
                    analyzers.append(wf_step_entity)

                portlet = PortletConfiguration(portlet.id)
                portlet.set_visualizer(view_step_entity)
                portlet.set_analyzers(analyzers)
                burst_entity.set_portlet(view_step_entity.tab_index, view_step_entity.index_in_tab, portlet)

            except Exception:
                # only log exception and ignore this step from loading
                self.logger.exception("Could not restore Workflow Step " + view_step.get_algorithm().name)

        return burst_entity
Exemple #11
0
    def test_load_burst_history(self):
        burst_config1 = BurstConfiguration(self.test_project.id)
        burst_config2 = BurstConfiguration(self.test_project.id)
        burst_config3 = BurstConfiguration(self.test_project.id)

        dao.store_entity(burst_config1)
        dao.store_entity(burst_config2)
        dao.store_entity(burst_config3)

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_BURST_CONFIG, burst_config1)
            burst_parameters = self.simulator_controller.load_burst_history()

        assert len(burst_parameters['burst_list']) == 3, "The burst configurations where not stored."
Exemple #12
0
    def test_set_monitor_equation(self):
        self.sess_mock['tau_s'] = '0.8'
        self.sess_mock['tau_f'] = '0.4'
        self.sess_mock['k_1'] = '5.6'
        self.sess_mock['V_0'] = '0.02'

        self.session_stored_simulator.monitors = [Bold()]
        self.session_stored_simulator.monitors[
            0].equation = FirstOrderVolterra()

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_SIMULATOR_CONFIG,
                               self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG,
                               BurstConfiguration(self.test_project.id))
            self.simulator_controller.set_monitor_equation(
                'Bold', **self.sess_mock._data)

        assert self.session_stored_simulator.monitors[0].equation.parameters[
            'tau_s'] == 0.8, "tau_s value was not set correctly."
        assert self.session_stored_simulator.monitors[0].equation.parameters[
            'tau_f'] == 0.4, "tau_f value was not set correctly."
        assert self.session_stored_simulator.monitors[0].equation.parameters[
            'k_1'] == 5.6, "k_1 value was not set correctly."
        assert self.session_stored_simulator.monitors[0].equation.parameters[
            'V_0'] == 0.02, "V_0 value was not set correctly."
    def _import_bursts(project_entity, bursts_dict):
        """
        Re-create old bursts, but keep a mapping between the id it has here and the old-id it had
        in the project where they were exported, so we can re-add the datatypes to them.
        """
        burst_ids_mapping = {}

        for old_burst_id in bursts_dict:
            burst_information = BurstInformation.load_from_dict(bursts_dict[old_burst_id])
            burst_entity = BurstConfiguration(project_entity.id)
            burst_entity.from_dict(burst_information.data)
            burst_entity = dao.store_entity(burst_entity)
            burst_ids_mapping[int(old_burst_id)] = burst_entity.id
            # We don't need the data in dictionary form anymore, so update it with new BurstInformation object
            bursts_dict[old_burst_id] = burst_information
        return burst_ids_mapping
Exemple #14
0
    def test_export(self):
        op = TestFactory.create_operation()
        simulator_index = SimulatorIndex()
        simulator_index.fill_from_has_traits(self.session_stored_simulator)

        burst_config = BurstConfiguration(self.test_project.id,
                                          simulator_index.id)
        burst_config = dao.store_entity(burst_config)

        simulator_index.fk_from_operation = op.id
        simulator_index = dao.store_entity(simulator_index)
        simulator_index.fk_parent_burst = burst_config.id
        simulator_index = dao.store_entity(simulator_index)

        simulator_h5 = h5.path_for_stored_index(simulator_index)
        with SimulatorH5(simulator_h5) as h5_file:
            h5_file.store(self.session_stored_simulator)

        burst = dao.get_bursts_for_project(self.test_project.id)
        self.sess_mock['burst_id'] = str(burst[0].id)

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_BURST_CONFIG,
                               self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG, burst_config)
            result = self.simulator_controller.export(str(burst[0].id))

        assert path.exists(result.input.name), "Simulation was not exported!"
    def test_export_simulator_configuration(self, operation_factory):
        """
        Test export of a simulator configuration
        """
        operation = operation_factory()
        simulator = Simulator()
        simulator_index = SimulatorIndex()
        simulator_index.fill_from_has_traits(simulator)
        simulator_index.fk_from_operation = operation.id
        simulator_index = dao.store_entity(simulator_index)

        burst_configuration = BurstConfiguration(self.test_project.id,
                                                 simulator_index.id)
        burst_configuration = dao.store_entity(burst_configuration)
        simulator_index.fk_parent_burst = burst_configuration.id
        simulator_index = dao.store_entity(simulator_index)

        simulator_h5 = h5.path_for_stored_index(simulator_index)
        with SimulatorH5(simulator_h5) as h5_file:
            h5_file.store(simulator)

        export_file = self.export_manager.export_simulator_configuration(
            burst_configuration.id)

        assert export_file is not None, "Export process should return path to export file"
        assert os.path.exists(
            export_file
        ), "Could not find export file: %s on disk." % export_file
        assert zipfile.is_zipfile(
            export_file), "Generated file is not a valid ZIP file"
Exemple #16
0
    def test_get_history_status(self):
        burst_config = BurstConfiguration(self.test_project.id)
        burst_config.start_time = datetime.now()
        dao.store_entity(burst_config)
        burst = dao.get_bursts_for_project(self.test_project.id)
        self.sess_mock['burst_ids'] = '["' + str(burst[0].id) + '"]'

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_BURST_CONFIG, self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG, burst_config)
            result = self.simulator_controller.get_history_status(**self.sess_mock._data).split(',')

        assert int(result[0][2:]) == burst[0].id, "Incorrect burst was used."
        assert result[1] == ' "running"', "Status should be set to running."
        assert result[2] == ' false', "Burst shouldn't be group."
        assert result[3] == ' ""', "Message should be empty, which means that there shouldn't be any errors."
        assert int(result[4][2:-4]) >= 0, "Running time should be greater than or equal to 0."
    def test_rename_burst(self):
        burst_config = BurstConfiguration(self.test_project.id)
        burst_config.name = 'Test Burst Configuration'
        new_name = "Test Burst Configuration 2"
        dao.store_entity(burst_config)
        burst = dao.get_bursts_for_project(self.test_project.id)
        self.sess_mock['burst_id'] = str(burst[0].id)
        self.sess_mock['burst_name'] = new_name

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_BURST_CONFIG, self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG, burst_config)
            result = self.simulator_controller.rename_burst(str(burst[0].id), new_name)

        assert result == '{"success": "Simulation successfully renamed!"}', \
            "Some error happened at renaming, probably because of invalid new name."
        assert dao.get_bursts_for_project(self.test_project.id)[0].name == new_name, "Name wasn't actually changed."
Exemple #18
0
    def load_datatype_from_file(self,
                                current_file,
                                op_id,
                                datatype_group=None,
                                current_project_id=None):
        # type: (str, int, DataTypeGroup, int) -> HasTraitsIndex
        """
        Creates an instance of datatype from storage / H5 file 
        :returns: DatatypeIndex
        """
        self.logger.debug("Loading DataType from file: %s" % current_file)
        h5_class = H5File.h5_class_from_file(current_file)

        if h5_class is BurstConfigurationH5:
            if current_project_id is None:
                op_entity = dao.get_operationgroup_by_id(op_id)
                current_project_id = op_entity.fk_launched_in
            h5_file = BurstConfigurationH5(current_file)
            burst = BurstConfiguration(current_project_id)
            burst.fk_simulation = op_id
            h5_file.load_into(burst)
            result = burst
        else:
            datatype, generic_attributes = h5.load_with_links(current_file)
            index_class = h5.REGISTRY.get_index_for_datatype(
                datatype.__class__)
            datatype_index = index_class()
            datatype_index.fill_from_has_traits(datatype)
            datatype_index.fill_from_generic_attributes(generic_attributes)

            # Add all the required attributes
            if datatype_group:
                datatype_index.fk_datatype_group = datatype_group.id
                if len(datatype_group.subject) == 0:
                    datatype_group.subject = datatype_index.subject
                    dao.store_entity(datatype_group)
            datatype_index.fk_from_operation = op_id

            associated_file = h5.path_for_stored_index(datatype_index)
            if os.path.exists(associated_file):
                datatype_index.disk_size = FilesHelper.compute_size_on_disk(
                    associated_file)
            result = datatype_index

        return result
Exemple #19
0
 def set_burst_config(self, burst_config=None):
     # type: (BurstConfiguration) -> None
     """
     Create a new burst instance only if one does not exist in the context.
     """
     if not burst_config and not self.burst_config:
         burst_config = BurstConfiguration(self.project.id)
     if burst_config:
         common.add2session(self.KEY_BURST_CONFIG, burst_config)
Exemple #20
0
 def load_burst_configuration_from_folder(simulator_folder, project):
     bc_h5_filename = DirLoader(
         simulator_folder,
         None).find_file_for_has_traits_type(BurstConfiguration)
     burst_config = BurstConfiguration(project.id)
     with BurstConfigurationH5(
             os.path.join(simulator_folder, bc_h5_filename)) as bc_h5:
         bc_h5.load_into(burst_config)
     return burst_config
Exemple #21
0
    def reset_simulator_configuration(self):
        burst_config = BurstConfiguration(self.context.project.id)
        self.context.init_session_at_sim_reset(burst_config, SimulatorWizzardURLs.SET_CONNECTIVITY_URL)
        self.monitors_handler.clear_next_monitors_dict()

        form = self.prepare_first_fragment()
        rendering_rules = SimulatorFragmentRenderingRules(form, SimulatorWizzardURLs.SET_CONNECTIVITY_URL,
                                                          is_first_fragment=True)
        return rendering_rules.to_dict()
Exemple #22
0
 def build(test_user, test_project, simulation_length=10, is_group=False):
     model = SimulatorAdapterModel()
     model.connectivity = connectivity_index_factory().gid
     model.simulation_length = simulation_length
     burst = BurstConfiguration(test_project.id, name="Sim " + str(datetime.now()))
     burst.start_time = datetime.now()
     algorithm = dao.get_algorithm_by_module(SIMULATOR_MODULE, SIMULATOR_CLASS)
     service = SimulatorService()
     if is_group:
         range_param = RangeParameter("conduction_speed", float, Range(lo=50.0, hi=100.0, step=20.0))
         burst.range1 = range_param.to_json()
         burst = BurstService().prepare_burst_for_pse(burst)
         op = service.async_launch_and_prepare_pse(burst, test_user, test_project, algorithm,
                                                   range_param, None, model)
     else:
         dao.store_entity(burst)
         op = service.async_launch_and_prepare_simulation(burst, test_user, test_project, algorithm, model)
     return op
Exemple #23
0
 def store_burst(project_id, operation=None):
     """
     Build and persist BurstConfiguration entity.
     """
     burst = BurstConfiguration(project_id)
     if operation is not None:
         burst.name = 'dummy_burst'
         burst.status = BurstConfiguration.BURST_FINISHED
         burst.start_time = datetime.now()
         burst.range1 = '["conduction_speed", {"lo": 50, "step": 1.0, "hi": 100.0}]'
         burst.range2 = '["connectivity", null]'
         burst.fk_simulation = operation.id
         burst.simulator_gid = uuid.uuid4().hex
         BurstService().store_burst_configuration(burst)
     return dao.store_entity(burst)
    def test_launch_simulation_with_default_parameters(self):
        self.sess_mock['input-simulation-name-id'] = 'HappySimulation'
        launch_mode = 'new'

        burst_config = BurstConfiguration(self.test_project.id)

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_BURST_CONFIG, burst_config)
            common.add2session(common.KEY_SIMULATOR_CONFIG, self.session_stored_simulator)
            self.simulator_controller.launch_simulation(launch_mode, **self.sess_mock._data)
Exemple #25
0
    def test_load_burst_only(self):
        zip_path = path.join(path.dirname(tvb_data.__file__), 'connectivity',
                             'connectivity_66.zip')
        TestFactory.import_zip_connectivity(self.test_user, self.test_project,
                                            zip_path, "John")
        connectivity = TestFactory.get_entity(self.test_project,
                                              ConnectivityIndex)

        simulator_index = SimulatorIndex()
        simulator_index.fill_from_has_traits(self.session_stored_simulator)

        burst_config = BurstConfiguration(self.test_project.id,
                                          simulator_index.id)
        burst_config = dao.store_entity(burst_config)

        simulator_index.fk_from_operation = burst_config.id
        simulator_index = dao.store_entity(simulator_index)
        simulator_index.fk_parent_burst = burst_config.id
        simulator_index = dao.store_entity(simulator_index)

        burst = dao.get_bursts_for_project(self.test_project.id)

        self.sess_mock['burst_id'] = str(burst[0].id)
        self.sess_mock['_connectivity'] = connectivity.gid
        self.sess_mock['_conduction_speed'] = "3.0"
        self.sess_mock['_coupling'] = "Sigmoidal"

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_SIMULATOR_CONFIG,
                               self.session_stored_simulator)
            self.simulator_controller.set_connectivity(**self.sess_mock._data)
            self.simulator_controller.set_stimulus(**self.sess_mock._data)

        storage_path = FilesHelper().get_project_folder(
            self.test_project, str(simulator_index.fk_from_operation))
        simulator_service = SimulatorService()
        SimulatorSerializer().serialize_simulator(
            self.session_stored_simulator, simulator_index.gid, None,
            storage_path)

        with patch('cherrypy.session', self.sess_mock, create=True):
            self.simulator_controller.load_burst_read_only(str(burst[0].id))
            is_simulator_load = common.get_from_session(KEY_IS_SIMULATOR_LOAD)
            is_simulator_copy = common.get_from_session(KEY_IS_SIMULATOR_COPY)
            last_loaded_form_url = common.get_from_session(
                KEY_LAST_LOADED_FORM_URL)

        database_simulator = dao.get_generic_entity(SimulatorIndex,
                                                    burst_config.id,
                                                    'fk_parent_burst')[0]

        assert simulator_index.gid == database_simulator.gid, "Simulator was not added correctly!"
        assert is_simulator_load, "Simulator Load Flag should be True!"
        assert not is_simulator_copy, "Simulator Copy Flag should be False!"
        assert last_loaded_form_url == '/burst/setup_pse', "Incorrect last form URL!"
Exemple #26
0
def fire_simulation(project_id, simulator):
    project = dao.get_project_by_id(project_id)
    assert isinstance(simulator, Simulator)
    # Load the SimulatorAdapter algorithm from DB
    cached_simulator_algorithm = FlowService(
    ).get_algorithm_by_module_and_class(IntrospectionRegistry.SIMULATOR_MODULE,
                                        IntrospectionRegistry.SIMULATOR_CLASS)

    # Instantiate a SimulatorService and launch the configured simulation
    simulator_service = SimulatorService()
    burst = BurstConfiguration(project.id)
    burst.name = "Sim " + str(datetime.now())
    burst.start_time = datetime.now()
    dao.store_entity(burst)

    launched_operation = simulator_service.async_launch_and_prepare_simulation(
        burst, project.administrator, project, cached_simulator_algorithm,
        simulator, None)
    LOG.info("Operation launched ....")
    return launched_operation
    def test_export_simulator_configuration(self, operation_factory):
        """
        Test export of a simulator configuration
        """
        operation = operation_factory(is_simulation=True, store_vm=True)

        burst_configuration = BurstConfiguration(self.test_project.id)
        burst_configuration.fk_simulation = operation.id
        burst_configuration.simulator_gid = operation.view_model_gid
        burst_configuration = dao.store_entity(burst_configuration)

        export_file = self.export_manager.export_simulator_configuration(
            burst_configuration.id)

        assert export_file is not None, "Export process should return path to export file"
        assert os.path.exists(
            export_file
        ), "Could not find export file: %s on disk." % export_file
        assert zipfile.is_zipfile(
            export_file), "Generated file is not a valid ZIP file"
Exemple #28
0
    def test_set_monitors(self):
        self.sess_mock['monitors'] = ['Temporal average']
        self.session_stored_simulator.monitors[0].variables_of_interest = numpy.array([0])
        self.session_stored_simulator.model.variables_of_interest = ['V', 'W']

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_SIMULATOR_CONFIG, self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG, BurstConfiguration(self.test_project.id))
            self.simulator_controller.set_monitors(**self.sess_mock._data)

        assert isinstance(self.session_stored_simulator.monitors[0], TemporalAverage), 'Monitor class is incorrect.'
Exemple #29
0
    def load_burst_entity(self, json_burst, project_id):
        """
        Load BurstConfiguration from JSON (possibly exported from a different machine).
        Nothing gets persisted in DB or on disk.

        :param json_burst: Burst JSON export
        :param project_id: Current project ID (it will be used if the user later starts this simulation)
        :return: BurstConfiguration  filled from JSON
        """

        burst_entity = BurstConfiguration(project_id)
        return burst_entity
Exemple #30
0
    def test_set_seeg_monitor_params(self):
        region_mapping = self.set_region_mapping()

        seeg_sensors_file = path.join(path.dirname(tvb_data.sensors.__file__),
                                      'seeg_588.txt')
        seeg_sensors = TestFactory.import_sensors(
            self.test_user, self.test_project, seeg_sensors_file,
            SensorsImporterModel.OPTIONS['Internal Sensors'])

        surface_file = path.join(path.dirname(tvb_data.surfaceData.__file__),
                                 'cortex_16384.zip')
        surface = TestFactory.import_surface_zip(self.test_user,
                                                 self.test_project,
                                                 surface_file, CORTICAL, True)

        seeg_projection_file = path.join(
            path.dirname(tvb_data.projectionMatrix.__file__),
            'projection_seeg_588_surface_16k.npy')
        seeg_projections = TestFactory.import_projection_matrix(
            self.test_user, self.test_project, seeg_projection_file,
            seeg_sensors.gid, surface.gid)

        self.session_stored_simulator.model.variables_of_interest = ('V', 'W',
                                                                     'V - W')
        variable_of_interest_indexes = {'W': 1, 'V - W': 2}
        self.sess_mock['variables_of_interest'] = list(
            variable_of_interest_indexes.keys())
        self.sess_mock['period'] = '0.75'
        self.sess_mock['region_mapping'] = region_mapping.gid
        self.sess_mock['projection'] = seeg_projections.gid
        self.sess_mock['sigma'] = "1.0"
        self.sess_mock['sensors'] = seeg_sensors.gid

        self.session_stored_simulator.monitors = [iEEG()]

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_SIMULATOR_CONFIG,
                               self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG,
                               BurstConfiguration(self.test_project.id))
            self.simulator_controller.set_monitor_params(
                'iEEG', **self.sess_mock._data)

        assert self.session_stored_simulator.monitors[
            0].period == 0.75, "Period was not set correctly."
        assert list(self.session_stored_simulator.monitors[0].variables_of_interest) == \
            list(variable_of_interest_indexes.values()), "Variables of interest were not set correctly."
        assert self.session_stored_simulator.monitors[0].region_mapping.gid.hex == region_mapping.gid, \
            "Region Mapping wasn't set and stored correctly."
        assert self.session_stored_simulator.monitors[0].sensors.gid.hex == seeg_sensors.gid, \
            "Region Mapping wasn't set and stored correctly."
        assert self.session_stored_simulator.monitors[0].projection.gid is not None, \
            "Projection wasn't stored correctly."
Exemple #31
0
 def test_get_selected_burst(self):
     """
     Create burst, add it to session, then check that get_selected_burst
     return the same burst. Also check that for an unstored entity we get
     back 'None'
     """
     burst_entity = BurstConfiguration(self.test_project.id, 'started', {}, 'burst1')
     cherrypy.session[b_c.KEY_BURST_CONFIG] = burst_entity
     stored_id = self.burst_c.get_selected_burst()
     self.assertEqual(stored_id, 'None')
     burst_entity = dao.store_entity(burst_entity)
     cherrypy.session[b_c.KEY_BURST_CONFIG] = burst_entity
     stored_id = self.burst_c.get_selected_burst()
     self.assertEqual(str(stored_id), str(burst_entity.id))