def open_preferences(self): from kromatography.utils.app_utils import get_preferences from kromatography.tools.preferences_view import \ RevealChromatographyPreferenceView prefs = get_preferences() view = RevealChromatographyPreferenceView(model=prefs) view.edit_traits(kind="livemodal")
def _job_manager_default(self): from kromatography.model.factories.job_manager import \ create_start_job_manager from kromatography.utils.app_utils import get_preferences preferences = get_preferences() job_manager = create_start_job_manager( max_workers=preferences.solver_preferences.executor_num_worker) return job_manager
def _setup_logging(self): from kromatography.utils.app_utils import get_preferences, \ initialize_logging if self.verbose: verbose = True else: preferences = get_preferences() verbose = preferences.app_preferences.console_logging_level <= 10 self.log_filepath = initialize_logging(verbose=verbose)
def _submit_simulations_as_job(sims): """ New Generator function for creating sim_workitems but avoiding passing a complicated HasTraits instance since they are painful to pickle/unpickle. Parameters ---------- sims : list List of simulations to submit as a job work item. """ from kromatography.solve.api import run_cadet_simulator from kromatography.utils.app_utils import get_preferences prefs = get_preferences() use_slurm = prefs.solver_preferences.use_slurm_scheduler for sim in sims: output_file = prepare_simulation_for_run(sim) yield run_cadet_simulator, (output_file,), {"use_slurm": use_slurm}
def _prepare_exit(self): """ Do any application-level state saving and clean-up. """ from kromatography.utils.app_utils import empty_cadet_input_folder, \ get_preferences if self.job_manager: self.job_manager.shutdown() self.job_manager = None # Lazily load preferences to give a chance to a user to change that # parameters after starting: preferences = get_preferences() if preferences.solver_preferences.auto_delete_solver_files_on_exit: empty_cadet_input_folder() # Remember the recent files preferences.file_preferences.recent_files = self.recent_files preferences.to_preference_file()
def param_scans_to_sim_group(group_name, parameter_scans, center_sim, lazy_loading=False, max_size=None, group_type=SIM_GROUP_GRID_TYPE, group_size=-1, auto_delete_run_sims=False): """ Returns simulation grid from a list of regular parameter scans. Parameters ---------- group_name : str Target group name. parameter_scans : list(ParameterScanDescription) List of parameter scan descriptions. center_sim : Simulation Center point simulation from which to create all simulations in the future group. group_type : str [OPTIONAL] Type of the future group(s) to be created. Should be one of the values allowed for the :attr:`simulation_group.SimulationGroup.type` attribute. Set to a regular grid by default. lazy_loading : bool (default: False) Save memory by making the output group of the lazy loading kind. max_size : None or int [OPTIONAL] Max size of the group(s) created. If a non-zero value is specified, a list of simulation group is returned, each with a number of simulation diffs smaller or equal to max_size. group_size : int [OPTIONAL] Size of the resulting group, used only if of Monte-Carlo type. Size is computed from parameter scan descriptions for the grid type. auto_delete_run_sims : bool [OPTIONAL, default=False] Delete CADET files and in memory simulations once they run? Returns ------- SimulationGroup or list(SimulationGroup) SimulationGroup created from the list of parameter scans the group should explore. If a max_size is provided, returns a list of SimulationGroup instances collectively scanning the entire parameter space described by parameter_scans, each with 0 < size <= max_size. """ # Override the number of threads per run from preferences in case it has # changed. Do it on the center sim to avoid having to do it on each # simulation of the group: prefs = get_preferences() target_nthreads = prefs.solver_preferences.cadet_num_threads if lazy_loading and not isinstance(center_sim, LazyLoadingSimulation): center_sim = LazyLoadingSimulation.from_simulation(center_sim) center_sim.solver.nthreads = target_nthreads else: # if the nthreads will be overridden, make a copy to avoid modifying # the source simulation if center_sim.solver.nthreads != target_nthreads: center_sim = center_sim.copy() center_sim.solver.nthreads = target_nthreads if group_type == SIM_GROUP_GRID_TYPE: simulation_diffs = sim_diffs_from_grid_parameter_scans(parameter_scans) elif group_type == SIM_GROUP_MC_TYPE: simulation_diffs = sim_diffs_from_random_parameter_scans( parameter_scans, group_size) else: msg = "Unsupported group type: {}".format(group_type) logger.exception(msg) raise ValueError(msg) return build_group_or_groups(group_name, center_sim, simulation_diffs, max_size, group_type=group_type, auto_delete_run_sims=auto_delete_run_sims)
def _max_recent_files_default(self): from kromatography.utils.app_utils import get_preferences preferences = get_preferences() return preferences.file_preferences.max_recent_files
def _confirm_on_window_close_default(self): from kromatography.utils.app_utils import get_preferences prefs = get_preferences() ui_prefs = prefs.ui_preferences return ui_prefs.confirm_on_window_close
def _auto_close_empty_windows_on_open_default(self): from kromatography.utils.app_utils import get_preferences prefs = get_preferences() ui_prefs = prefs.ui_preferences return ui_prefs.auto_close_empty_windows_on_open
def _window_size_default(self): from kromatography.utils.app_utils import get_preferences prefs = get_preferences() ui_prefs = prefs.ui_preferences return ui_prefs.app_width, ui_prefs.app_height
def _balance_threshold_default(self): from kromatography.utils.app_utils import get_preferences prefs = get_preferences() return prefs.file_preferences.exp_importer_mass_threshold
def _get_app_pref_view(self): return AppPreferencesView(model=self.model.app_preferences) def _get_ui_prefs_view(self): return UIPreferencesView(model=self.model.ui_preferences) def _get_solver_prefs_view(self): return SolverPreferencesView(model=self.model.solver_preferences) def _get_file_pref_view(self): return FilePreferencesView(model=self.model.file_preferences) def factory_reset(self): self.model = RevealChromatographyPreferences( preference_filepath=get_preference_file() ) def _instructions_default(self): return "Most preferences will take effect as soon as the preferences" \ " are saved. No need to restart the application unless " \ "specified." if __name__ == '__main__': from kromatography.utils.app_utils import get_preferences prefs = get_preferences() view = RevealChromatographyPreferenceView(model=prefs) view.configure_traits()
def test_get_local_preferences(self): reset_preferences(target_file=join(HERE, "preferences.yaml")) prefs = get_preferences(fileloc=HERE) assert_has_traits_almost_equal(prefs, RevealChromatographyPreferences())
def test_get_default_preferences(self): prefs = get_preferences() self.assertIsInstance(prefs, RevealChromatographyPreferences) self.assertEqual(prefs.version, CUR_VERSION)
def _nthreads_default(self): from kromatography.utils.app_utils import get_preferences prefs = get_preferences() return prefs.solver_preferences.cadet_num_threads
def _slurm_binary_default(self): from kromatography.utils.app_utils import get_preferences prefs = get_preferences() return prefs.solver_preferences.slurm_binary
def setUp(self): self.prefs = get_preferences()