Exemplo n.º 1
0
    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"
Exemplo n.º 2
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!"
Exemplo n.º 3
0
    def async_launch_and_prepare_pse(self, burst_config, user, project, simulator_algo, range_param1, range_param2,
                                     session_stored_simulator):
        try:
            simulator_id = simulator_algo.id
            algo_category = simulator_algo.algorithm_category
            operation_group = burst_config.operation_group
            metric_operation_group = burst_config.metric_operation_group
            operations = []
            range_param2_values = []
            if range_param2:
                range_param2_values = range_param2.get_range_values()
            for param1_value in range_param1.get_range_values():
                for param2_value in range_param2_values:
                    simulator = copy.deepcopy(session_stored_simulator)
                    self._set_simulator_range_parameter(simulator, range_param1.name, param1_value)
                    self._set_simulator_range_parameter(simulator, range_param2.name, param2_value)

                    simulator_index = SimulatorIndex()
                    simulator_index.fk_parent_burst = burst_config.id
                    simulator_index = dao.store_entity(simulator_index)
                    ranges = json.dumps({range_param1.name: param1_value[0], range_param2.name: param2_value[0]})

                    operation = self._prepare_operation(project.id, user.id, simulator_id, simulator_index,
                                                        algo_category, operation_group,
                                                        {DataTypeMetaData.KEY_BURST: burst_config.id}, ranges)

                    simulator_index.fk_from_operation = operation.id
                    dao.store_entity(simulator_index)

                    storage_path = self.files_helper.get_project_folder(project, str(operation.id))
                    self.serialize_simulator(simulator, simulator_index.gid, None, storage_path)
                    operations.append(operation)

            first_operation = operations[0]
            datatype_group = DataTypeGroup(operation_group, operation_id=first_operation.id,
                                           fk_parent_burst=burst_config.id,
                                           state=json.loads(first_operation.meta_data)[DataTypeMetaData.KEY_STATE])
            dao.store_entity(datatype_group)

            metrics_datatype_group = DataTypeGroup(metric_operation_group, fk_parent_burst=burst_config.id)
            dao.store_entity(metrics_datatype_group)

            wf_errs = 0
            for operation in operations:
                try:
                    OperationService().launch_operation(operation.id, True)
                except Exception as excep:
                    self.logger.error(excep)
                    wf_errs += 1
                    BurstService2().mark_burst_finished(burst_config, error_message=str(excep))

            self.logger.debug("Finished launching workflows. " + str(len(operations) - wf_errs) +
                              " were launched successfully, " + str(wf_errs) + " had error on pre-launch steps")

        except Exception as excep:
            self.logger.error(excep)
            BurstService2().mark_burst_finished(burst_config, error_message=str(excep))
Exemplo n.º 4
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!"
Exemplo n.º 5
0
    def async_launch_and_prepare_simulation(self, burst_config, user, project,
                                            simulator_algo,
                                            session_stored_simulator,
                                            simulation_state_gid):
        try:
            simulator_index = SimulatorIndex()
            metadata = {}
            if burst_config:
                simulator_index.fk_parent_burst = burst_config.id
                metadata.update({DataTypeMetaData.KEY_BURST: burst_config.id})
            dao.store_entity(simulator_index)
            simulator_id = simulator_algo.id
            algo_category = simulator_algo.algorithm_category
            operation = self._prepare_operation(project.id, user.id,
                                                simulator_id, simulator_index,
                                                algo_category, None, metadata)

            simulator_index.fk_from_operation = operation.id
            dao.store_entity(simulator_index)

            storage_path = self.files_helper.get_project_folder(
                project, str(operation.id))
            SimulatorSerializer().serialize_simulator(session_stored_simulator,
                                                      simulator_index.gid,
                                                      simulation_state_gid,
                                                      storage_path)

            wf_errs = 0
            try:
                OperationService().launch_operation(operation.id, True)
                return operation
            except Exception as excep:
                self.logger.error(excep)
                wf_errs += 1
                if burst_config:
                    BurstService().mark_burst_finished(
                        burst_config, error_message=str(excep))

            self.logger.debug(
                "Finished launching workflow. The operation was launched successfully, "
                + str(wf_errs) + " had error on pre-launch steps")

        except Exception as excep:
            self.logger.error(excep)
            if burst_config:
                BurstService().mark_burst_finished(burst_config,
                                                   error_message=str(excep))