Example #1
0
    def test_prepare_inputs_with_eeg_monitor(self, operation_factory,
                                             simulator_factory,
                                             surface_index_factory,
                                             sensors_index_factory,
                                             region_mapping_index_factory,
                                             connectivity_index_factory):
        surface_idx, surface = surface_index_factory(cortical=True)
        sensors_idx, sensors = sensors_index_factory()
        proj = ProjectionSurfaceEEG(sensors=sensors,
                                    sources=surface,
                                    projection_data=numpy.ones(3))

        op = operation_factory()
        storage_path = FilesHelper().get_project_folder(op.project, str(op.id))
        prj_db_db = h5.store_complete(proj, storage_path)
        prj_db_db.fk_from_operation = op.id
        dao.store_entity(prj_db_db)

        connectivity = connectivity_index_factory(76, op)
        rm_index = region_mapping_index_factory(conn_gid=connectivity.gid,
                                                surface_gid=surface_idx.gid)

        eeg_monitor = EEGViewModel(projection=proj.gid, sensors=sensors.gid)
        eeg_monitor.region_mapping = rm_index.gid

        sim_folder, sim_gid = simulator_factory(op=op,
                                                monitor=eeg_monitor,
                                                conn_gid=connectivity.gid)
        hpc_client = HPCSchedulerClient()
        input_files = hpc_client._prepare_input(op, sim_gid)
        assert len(input_files) == 11
    def _operation_finished(operation, simulator_gid):
        op_ident = dao.get_operation_process_for_operation(operation.id)
        # TODO: Handle login
        job = Job(
            Transport(os.environ[HPCSchedulerClient.CSCS_LOGIN_TOKEN_ENV_KEY]),
            op_ident.job_id)

        operation = dao.get_operation_by_id(operation.id)
        folder = HPCSchedulerClient.storage_interface.get_project_folder(
            operation.project.name)
        storage_interface = StorageInterface()
        if storage_interface.encryption_enabled():
            storage_interface.inc_project_usage_count(folder)
            storage_interface.sync_folders(folder)

        try:
            sim_h5_filenames, metric_op, metric_h5_filename = \
                HPCSchedulerClient.stage_out_to_operation_folder(job.working_dir, operation, simulator_gid)

            operation.mark_complete(STATUS_FINISHED)
            dao.store_entity(operation)
            HPCSchedulerClient().update_db_with_results(
                operation, sim_h5_filenames, metric_op, metric_h5_filename)

        except OperationException as exception:
            HPCOperationService.LOGGER.error(exception)
            HPCOperationService._operation_error(operation)

        finally:
            if storage_interface.encryption_enabled():
                storage_interface.sync_folders(folder)
                storage_interface.set_project_inactive(operation.project)
Example #3
0
 def test_prepare_inputs(self, operation_factory, simulator_factory):
     op = operation_factory(test_user=self.test_user,
                            test_project=self.test_project)
     sim_folder, sim_gid = simulator_factory(op=op)
     hpc_client = HPCSchedulerClient()
     input_files = hpc_client._prepare_input(op, sim_gid)
     assert len(input_files) == 6
 def _operation_finished(operation, simulator_gid):
     op_ident = dao.get_operation_process_for_operation(operation.id)
     # TODO: Handle login
     job = Job(
         Transport(os.environ[HPCSchedulerClient.CSCS_LOGIN_TOKEN_ENV_KEY]),
         op_ident.job_id)
     sim_h5_filenames, metric_op, metric_h5_filename = \
         HPCSchedulerClient.stage_out_to_operation_folder(job.working_dir, operation, simulator_gid)
     operation.mark_complete(STATUS_FINISHED)
     dao.store_entity(operation)
     HPCSchedulerClient().update_db_with_results(operation,
                                                 sim_h5_filenames,
                                                 metric_op,
                                                 metric_h5_filename)
Example #5
0
    def test_stage_out_to_operation_folder(self, mocker, operation_factory,
                                           simulator_factory,
                                           pse_burst_configuration_factory):
        burst = pse_burst_configuration_factory(self.test_project)
        op = operation_factory(test_user=self.test_user,
                               test_project=self.test_project)
        op.fk_operation_group = burst.fk_operation_group
        dao.store_entity(op)

        sim_folder, sim_gid = simulator_factory(op=op)
        burst.simulator_gid = sim_gid.hex
        dao.store_entity(burst)

        output_path = self._do_operation_launch(op,
                                                sim_gid,
                                                mocker,
                                                is_pse=True)

        def _stage_out_dummy(dir, sim_gid):
            return [
                os.path.join(output_path, enc_file)
                for enc_file in os.listdir(output_path)
            ]

        mocker.patch.object(HPCSchedulerClient, '_stage_out_results',
                            _stage_out_dummy)
        sim_results_files, metric_op, metric_file = HPCSchedulerClient.stage_out_to_operation_folder(
            None, op, sim_gid)
        assert op.id != metric_op.id
        assert os.path.exists(metric_file)
        assert len(sim_results_files) == 1
        assert os.path.exists(sim_results_files[0])
Example #6
0
    def _do_operation_launch(self, op, sim_gid, mocker, is_pse=False):
        # Prepare encrypted dir
        self.encryption_handler = EncryptionHandler(sim_gid)
        job_encrypted_inputs = HPCSchedulerClient()._prepare_input(op, sim_gid)
        self.encryption_handler.encrypt_inputs(job_encrypted_inputs)
        encrypted_dir = self.encryption_handler.get_encrypted_dir()

        mocker.patch('tvb.core.operation_hpc_launcher._request_passfile',
                     _request_passfile_dummy)
        mocker.patch(
            'tvb.core.operation_hpc_launcher._update_operation_status',
            _update_operation_status)

        # Call do_operation_launch similarly to CSCS env
        plain_dir = self.files_helper.get_project_folder(
            self.test_project, 'plain')
        do_operation_launch(sim_gid.hex, 1000, is_pse, '', op.id, plain_dir)
        assert len(os.listdir(encrypted_dir)) == 7
        output_path = os.path.join(encrypted_dir,
                                   HPCSimulatorAdapter.OUTPUT_FOLDER)
        assert os.path.exists(output_path)
        expected_files = 2
        if is_pse:
            expected_files = 3
        assert len(os.listdir(output_path)) == expected_files
        return output_path
Example #7
0
 def _get_backend_client():
     # type: () -> BackendClient
     if TvbProfile.current.hpc.IS_HPC_RUN:
         # Return an entity capable to submit jobs to HPC.
         return HPCSchedulerClient()
     if TvbProfile.current.cluster.IS_DEPLOY:
         # Return an entity capable to submit jobs to the cluster.
         return ClusterSchedulerClient()
     # Return a thread launcher.
     return StandAloneClient()
 def _get_backend_client():
     # type: () -> BackendClient
     if TvbProfile.current.hpc.IS_HPC_RUN:
         if not TvbProfile.current.hpc.CAN_RUN_HPC:
             raise InvalidSettingsException(
                 "We can not enable HPC run. Most probably pyunicore is not installed!"
             )
         # Return an entity capable to submit jobs to HPC.
         return HPCSchedulerClient()
     if TvbProfile.current.cluster.IS_DEPLOY:
         # Return an entity capable to submit jobs to the cluster.
         return ClusterSchedulerClient()
     # Return a thread launcher.
     return StandAloneClient()
    def _get_backend_client(adapter_instance):
        # type: (ABCAdapter) -> BackendClient

        # For the moment run only simulations on HPC
        if TvbProfile.current.hpc.IS_HPC_RUN and type(adapter_instance) is get_class_by_name(
                "{}.{}".format(SIMULATOR_MODULE, SIMULATOR_CLASS)):
            if not TvbProfile.current.hpc.CAN_RUN_HPC:
                raise InvalidSettingsException("We can not enable HPC run. Most probably pyunicore is not installed!")
            # Return an entity capable to submit jobs to HPC.
            return HPCSchedulerClient()
        if TvbProfile.current.cluster.IS_DEPLOY:
            # Return an entity capable to submit jobs to the cluster.
            return ClusterSchedulerClient()
        # Return a thread launcher.
        return StandAloneClient()