def __init__(self, name: str = "", **kwargs) -> None: self.output = ipywidgets.Output() self._computing_progress = ipywidgets.IntProgress( value=0, min=0, max=6, description="0 computing") self._requested_progress = ipywidgets.IntProgress( value=0, min=0, max=6, description="0 HTTP rqs") completed = ipywidgets.Label(value="0 completed,") traitlets.dlink((self, "completed"), (completed, "value"), lambda c: f"{c} completed,") cancelled = ipywidgets.Label(value="0 cancelled,") traitlets.dlink((self, "cancelled"), (cancelled, "value"), lambda c: f"{c} cancelled,") errored = ipywidgets.Label(value="0 errored") traitlets.dlink((self, "errored"), (errored, "value"), lambda c: f"{c} errored") super().__init__( children=[ ipywidgets.HTML(value=f"<b>{name}</b>"), self._requested_progress, self._computing_progress, ipywidgets.HBox(children=[ completed, cancelled, errored, ]), self.output, ], **kwargs, )
def show_bars(self): self._pbar = ipywidgets.IntProgress() self._pbar_desc = ipywidgets.HTML(value=self._status_initial) self._pbar_total = ipywidgets.IntProgress() self._pbar_total_desc = ipywidgets.HTML(value=self._status_initial) display( ipywidgets.VBox([ ipywidgets.HBox([self._pbar_total, self._pbar_total_desc]), ipywidgets.HBox([self._pbar, self._pbar_desc]) ]))
def reduction_impact(pipeline, X, y, *, grid_opts={"n_jobs": -1}, **grids): """ Train classifiers with and without the proided reducers. reduce -- reducer to use grid -- grid to search X -- Dataframe of observations to train on y -- Series of labels of labels to train on grid_opts -- parameters to pass to the grid search on construction Returns: {id: w/reduction} {id: w/o reuduction) """ control_report = widgets.IntProgress(value=0, min=0, max=len(grids), description='Control', bar_style='info', orientation='Horizontal') reduced_report = widgets.IntProgress(value=0, min=0, max=len(grids), description='Reduced', bar_style='', orientation='Horizontal') detail = widgets.HTML(value='<i>initializing</i>', disabled=True) display(widgets.VBox([control_report, reduced_report, detail])) def _search_each(pipeline, grid, progress): return { name: _search(pipeline, config, name, progress) for name, config in grid.items() } def _search(pipeline, grid, label, progress): detail.value = "Searching " + label clf = GridSearchCV(pipeline, grid, **grid_opts) with warnings.catch_warnings(): warnings.simplefilter("ignore") clf.fit(X, y) progress.value = progress.value + 1 return clf p2 = Pipeline(steps=[e for e in pipeline.steps if e[0] != "reduce_dim"]) refs = _search_each(p2, grids, control_report) ress = _search_each(pipeline, grids, reduced_report) detail.value = "Search complete" return ress, refs
def pwidget(name, num, basic): if basic: return widgets.IntProgress(value=0, min=0, max=num, orientation='horizontal', layout=widgets.Layout(width='95%')) else: return widgets.IntProgress(value=0, min=0, max=num, description='%s:' % name, orientation='horizontal', style={'description_width': 'initial'}, layout=widgets.Layout(width='95%'))
def test_Estimate(self): random.seed(23) self.__settings = Settings('test_app.ini') self.__gcs = sGCS(self.__settings) self.__stochastic = Stochastic() abbading_format_loader = AbbadingoFormatLoader() abbading_format_loader.load('../../NewTestSets/TomitaNew/tomita_1.txt') self.__gcs.train_data = abbading_format_loader.input_data self.__gcs.reset_grammar() non_terminal_rules = set() non_terminal_rules = deepcopy(self.__gcs.grammar.get_non_terminal_rules()) for rule in non_terminal_rules: self.__gcs.grammar.remove_rule(rule) n_symbols = self.__gcs.grammar.nonTerminalSymbols t_symbols = self.__gcs.grammar.terminalSymbols self.__gcs.grammar.add_rules([sRule([n_symbols[0], n_symbols[0], n_symbols[1]], prob=random.uniform(0, 1)), sRule([n_symbols[0], n_symbols[0], n_symbols[2]], prob=random.uniform(0, 1)), sRule([n_symbols[1], t_symbols[1]], prob=random.uniform(0, 1)), sRule([n_symbols[2], t_symbols[0]], prob=random.uniform(0, 1)), sRule([n_symbols[0], t_symbols[1]], prob=random.uniform(0, 1)), sRule([n_symbols[0], t_symbols[0]], prob=random.uniform(0, 1))]) all_rules = self.__gcs.grammar.get_rules() are_terminals = [rule.is_terminal(AaaRulesHandlingType.TERMINALS) for rule in all_rules] loader_widget = widgets.IntProgress(value=0, min=0, step=1, bar_style='info', orientation='horizontal', layout=widgets.Layout(width='100%', height='100%'), style={'description_width': 'initial'}) self.__stochastic.normalize(self.__gcs.grammar) self.__gcs.process(True, loader_widget) all_rules = self.__gcs.grammar.get_rules() pass
def __init__(self, api, patients: Queryable = None): self.api = api self.tiles = list() self.hypercube = Hypercube() self.__linked_tile = None if isinstance(patients, Queryable): self.subject_set_id = api.create_patient_set( repr(patients), patients).get('id') counts = api.observations.counts_per_study_and_concept( subject_set_id=self.subject_set_id) self.nodes = filter_tree(api.tree_dict, counts) else: self.subject_set_id = None self.nodes = None self.out = widgets.Box() self.out.layout.flex_flow = 'row wrap' self.combination_out = widgets.Box() self.combination_out.layout.flex_flow = 'row wrap' self.cp = ConceptPicker(self.plotter, api, self.nodes) self.counter = widgets.IntProgress(value=10, min=0, max=10, step=1, orientation='horizontal')
def __init__(self, classes, images, output_path, output_name, images_classes=None): # task classes self.__classes = classes self.__current_image_annotations = [] self.__current_class_for_ann = [] self.__output_path = output_path self.__output_name = output_name self.__file_path = os.path.join(self.__output_path, self.__output_name + ".json") self.__images = images # classes for each img self.__images_classes = images_classes self.__current_img = -1 self.__image_id = -1 self.__annotation_id = -1 self.__selected_ann = None if os.path.exists(self.__file_path): self.__load_coco_file() else: self.__create_coco_format() self.__id_for_class = {cl['name']: cl['id'] for cl in self.__CATEGORIES} self.__create_btns() self.__progress = widgets.IntProgress(min=0, max=len(images), value=1, description='{}/{}'.format(1, len(images))) self.__progress.bar_style = 'info' self.__title_lbl = widgets.Label(value="title") self.__create_map() self.__create_classes_btns() self.__validation_show = widgets.HTML(value="") self.__map_classes = widgets.HBox(children=[self.__map, widgets.VBox(children=self.__classes_btns)]) self.__all_widgets = widgets.VBox(children=[self.__progress, self.__buttons, self.__validation_show, self.__title_lbl, self.__map_classes])
def __init__(self, completed_len: int, visible: bool = True): """ Instantiate new _Progress UI. Parameters ---------- completed_len : int The expected value that indicates 100% done. visible : bool If True start the progress UI visible, by default True. """ self._completed = 0 self._total = completed_len self._progress = widgets.IntProgress( value=0, max=100, step=1, description="Progress:", bar_style="info", orientation="horizontal", ) self._done_label = widgets.Label(value="0%") self._progress.visible = visible self._done_label.visible = visible display(widgets.HBox([self._progress, self._done_label]))
def run_with_progress_bar(num_items: int, fn: Callable, item_type: str = "doc") \ -> List[pd.DataFrame]: """ Display a progress bar while iterating over a list of dataframes. :param num_items: Number of items to iterate over :param fn: A function that accepts a single integer argument -- let's call it `i` -- and performs processing for document `i` and returns a `pd.DataFrame` of results :param item_type: Human-readable name for the items that the calling code is iterating over """ _UPDATE_SEC = 0.1 result = [] # Type: List[pd.DataFrame] last_update = time.time() progress_bar = ipywidgets.IntProgress( 0, 0, num_items, description="Starting...", layout=ipywidgets.Layout(width="100%"), style={"description_width": "12%"}) display(progress_bar) for i in range(num_items): result.append(fn(i)) now = time.time() if i == num_items - 1 or now - last_update >= _UPDATE_SEC: progress_bar.value = i + 1 progress_bar.description = f"{i + 1}/{num_items} {item_type}s" last_update = now progress_bar.bar_style = "success" return result
def __init__(self, title="Progress Bar", **kwargs): """Initialize ProgressBarWidget.""" self.title = title self.correspondance = { "created": 0, "running": 1, "waiting": 1, "killed": 2, "excepted": 2, "finished": 2, } self.progress_bar = ipw.IntProgress( value=0, min=0, max=2, step=1, description="Progress:", bar_style="warning", # 'success', 'info', 'warning', 'danger' or '' orientation="horizontal", layout={"width": "800px"}, ) self.state = ipw.HTML( description="Calculation state:", value="Created", style={"description_width": "initial"}, ) super().__init__(children=[self.progress_bar, self.state], **kwargs)
def execute_notebook(notebook_filename, notebook_save_filename, params): with open(notebook_filename) as file_handler: notebook = nbformat.read(file_handler, as_version=4) b_errors = False if params: for nb_cell in notebook.cells: if nb_cell.cell_type == 'code': new_cell_source = utils.substitute_params( nb_cell.source, params) nb_cell.source = new_cell_source break try: execute_preprocessor.nb = notebook progress_bar = widgets.IntProgress( value=0, min=0, max=len(notebook.cells), step=1, bar_style= 'info', # 'success', 'info', 'warning', 'danger' or '' orientation='horizontal') display_label = notebook_filename if notebook_save_filename: display_label = display_label + ' : ' + notebook_save_filename display( widgets.HBox( [widgets.Label(display_label), progress_bar])) for idx, nb_cell in enumerate(notebook.cells): execute_preprocessor.preprocess_cell( nb_cell, resources={'metadata': {}}, cell_index=idx) progress_bar.value = idx + 1 except CellExecutionError: b_errors = True progress_bar.bar_style = 'danger' if kernel_manager or kernel_comm: kernel_comm.stop_channels() kernel_manager.shutdown_kernel() raise finally: if notebook_save_filename: with open(notebook_save_filename, mode='wt') as file_handler: nbformat.write(notebook, file_handler) if not b_errors: progress_bar.bar_style = 'success'
def __init__(self, task_num=10): self.pbar = ipy.IntProgress(min=0, max=task_num, bar_style='') # (value=0, min=0, max=max, step=1, description=description, bar_style='') self.labl = ipy.Label() IPython.display.display(ipy.HBox([self.pbar, self.labl])) self.task_num = task_num self.completed = 0 self.start()
def __init__(self, update_interval=0.5): self.update_interval = update_interval self.num_cpus = psutil.cpu_count() self.perf_thread = threading.Thread(target=self.update_data, daemon=True) self.keep_running = True self.perf_thread.start() self.bars = [] for i in range(self.num_cpus): widget = widgets.IntProgress( value=0, min=0, max=100, step=1, description='CPU #{}'.format(i), bar_style= 'success', # 'success', 'info', 'warning', 'danger' or '' orientation='vertical', readout=True, readout_format='d') self.bars.append(widget) items_layout = Layout(width='auto') box_layout = Layout(display='flex', flex_flow='row', align_items='stretch', border='solid', width='auto') box = Box(children=self.bars, layout=box_layout) display(box)
def generate_jobs_pending_widget(): """Generates a jobs_pending progress bar widget. """ pbar = widgets.IntProgress(value=0, min=0, max=50, description='', orientation='horizontal', layout=widgets.Layout(max_width='180px')) pbar.style.bar_color = '#71cddd' pbar_current = widgets.Label(value=str(pbar.value), layout=widgets.Layout(min_width='auto')) pbar_max = widgets.Label(value=str(pbar.max), layout=widgets.Layout(min_width='auto')) def _on_max_change(change): pbar_max.value = str(change['new']) def _on_val_change(change): pbar_current.value = str(change['new']) pbar.observe(_on_max_change, names='max') pbar.observe(_on_val_change, names='value') jobs_widget = widgets.HBox([pbar_current, pbar, pbar_max], layout=widgets.Layout(max_width='250px', min_width='250px', justify_content='center')) return jobs_widget
def generate_jobs_pending_widget(): """Generates a jobs_pending progress bar widget.""" pbar = widgets.IntProgress( value=0, min=0, max=50, description="", orientation="horizontal", layout=widgets.Layout(max_width="180px"), ) pbar.style.bar_color = "#71cddd" pbar_current = widgets.Label(value=str(pbar.value), layout=widgets.Layout(min_width="auto")) pbar_max = widgets.Label(value=str(pbar.max), layout=widgets.Layout(min_width="auto")) def _on_max_change(change): pbar_max.value = str(change["new"]) def _on_val_change(change): pbar_current.value = str(change["new"]) pbar.observe(_on_max_change, names="max") pbar.observe(_on_val_change, names="value") jobs_widget = widgets.HBox( [pbar_current, pbar, pbar_max], layout=widgets.Layout(max_width="250px", min_width="250px", justify_content="center"), ) return jobs_widget
def _kfold_scoring(dataset, k, algo): """ Scored the given datset with the given algo unsing k-fold train/test. Parameters ---------- dataset : rankeval.dataset.Dataset The dataset instance. k : int Number of folds. algo : function See :func:`bias_variance`. Returns ------- score : numpy.ndarray A vecotr of num_instances scores. """ if ipywidgets: progress_bar = ipywidgets.IntProgress( min=0, max=k, description="Processing k folds") display(progress_bar) scores = np.zeros(dataset.n_instances, dtype=np.float32) query_sizes = dataset.get_query_sizes() # shuffle queries shuffled_qid = np.random.permutation(dataset.n_queries) chunk_query_size = int(math.ceil(dataset.n_queries/float(k))) for p in range(0, dataset.n_queries, chunk_query_size): if ipywidgets: progress_bar.value += 1 # p-th fold is used for testing test_rows = np.full(dataset.n_instances, fill_value=False, dtype=np.bool) for q in shuffled_qid[p: p + chunk_query_size]: test_rows[dataset.query_offsets[q]:dataset.query_offsets[q+1]] = True # other folds are used for training train_rows = np.logical_not(test_rows) train_q = np.full(dataset.n_queries, fill_value=True, dtype=np.bool) train_q[shuffled_qid[p: p+chunk_query_size]] = False # get algorithm predictions fold_scores = algo( dataset.X[train_rows], dataset.y[train_rows], query_sizes[train_q], dataset.X[test_rows] ) # update scores for the current fold scores[test_rows] = fold_scores progress_bar.bar_style = "success" progress_bar.close() return scores
def watch(): while optimiser.run_state is None: time.sleep(0.2) label = widgets.HTML() bar = widgets.IntProgress(min=0, max=optimiser.run_state.max_jobs, value=0, description='', layout=widgets.Layout(width='100%'), bar_style='info') box = widgets.VBox(children=[label, bar]) display(box) while optimiser.run_state is not None: bar.value = optimiser.run_state.finished_this_run label.value = 'Finished Jobs: {}/{}'.format(bar.value, bar.max) time.sleep(0.2) if close_when_complete: box.close() else: bar.value = bar.max label.value = 'Finished Jobs: {}/{}'.format(bar.value, bar.max) bar.bar_style = 'success'
def _get_tasks_gridbox(grid_job): gridbox_children = [task_gridbox_children] task_details_list = [] for task_name in grid_job.tasks.names: progress = grid_job.tasks.get(task_name).progress status = grid_job.tasks.get(task_name).status progress = widgets.IntProgress(value=progress, min=0, max=100) status_label = widgets.Label(status) task_name_label = widgets.Label(task_name) task_details = widgets.Output() logs = grid_job.tasks.get(task_name).logs details_button = _get_details_button(_toggle_info_display, task_details, task_name, logs) task_details_list.append(task_details) row_children = [ task_name_label, progress, status_label, details_button ] row_box = widgets.GridBox( children=row_children, layout=widgets.Layout(grid_template_columns='43% 43% 9% 5%')) gridbox_children.append(row_box) gridbox_children.append(task_details) grid_box = widgets.GridBox(children=gridbox_children, layout=widgets.Layout(width='100%')) return grid_box
def get_progress_bar(max_trials): return widgets.IntProgress(value=0, min=0, max=max_trials, step=1, description='Progress', orientation='horizontal')
def minimize_PyDE(self, npop=100, de_iter=200, mc_iter=500, mcmc=True, maximize=True): """ Minimize using the PyDE NOTES: https://github.com/hpparvi/PyDE """ centers = self.lpf.gp.get_parameter_vector() print("Running PyDE Optimizer") self.de = pyde.de.DiffEvol( self.lpf, self.lpf.ps.bounds, npop, maximize=maximize) # we want to maximize the likelihood self.min_pv, self.min_pv_lnval = self.de.optimize(ngen=de_iter) print("Optimized using PyDE") print("Final parameters:") self.print_param_diagnostics(self.min_pv) print("LogLn value:", self.min_pv_lnval) print("Log priors", self.lpf.ps.c_log_prior(self.min_pv)) if mcmc: print("Running MCMC") self.sampler = emcee.EnsembleSampler(npop, self.lpf.ps.ndim, self.lpf) pb = ipywidgets.IntProgress(max=mc_iter / 50) display(pb) for i, c in enumerate( self.sampler.sample(self.de.population, iterations=mc_iter)): if i % 50 == 0: pb.value += 1 print("Finished MCMC")
def __init__(self, header, jobNumberField, buildJobFunc, buildNewJobsFunc, buildArgumentsListFunc, updateScreenFieldsFunc, callProgramFunc, program): self.existingJobs = [] self.jobCounter = 1 self.jobNumber = jobNumberField self.program = program #the buildJob function as implemented by the consuming class self.buildJob = buildJobFunc #the buildNewJobs function as implemented by the consuming class self.buildNewJobs = buildNewJobsFunc #the buildArgumentsList function as implemented by the consuming class self.buildArgumentsList = buildArgumentsListFunc #the updateScreenFields function as implemented by the consuming class self.updateScreenFields = updateScreenFieldsFunc #the callProgram function as implemented by the consuming class self.callProgram = callProgramFunc self.jobsList = widgets.SelectMultiple( description='Jobs: ', options=header, disabled=False, style={'description_width': 'initial'}, rows=10, layout=Layout(width='90%')) self.addButton = widgets.Button(description='Add', disabled=False, button_style='', tooltip='Add job') self.deleteButton = widgets.Button(description='Delete', disabled=False, button_style='', tooltip='Delete job(s)') self.selectButton = widgets.Button(description='Select', disabled=False, button_style='', tooltip='Select job for editing.') self.updateButton = widgets.Button(description='Update', disabled=False, button_style='', tooltip='Update job.') self.runAllButton = widgets.Button(description='Run All', disabled=False, button_style='', tooltip='Run all jobs') self.runProgress = widgets.IntProgress(value=0, min=0, max=10, step=1, description='Progress:', bar_style='', orientation='horizontal')
def ProgressBarLabelled(num, label=''): try: f = ipw.IntProgress(0, max=num) l = ipw.Label(label) display(ipw.HBox([l, f])) return f except: pass
def __init__(self): self.w_progress_bar = ipywidgets.IntProgress( value=0, min=0, max=1, description="Progress:", bar_style="info") self.w_progress_bar.layout.display = "none"
def __init__(self, wait_sec): num_half_sec = int(wait_sec * 2) progressbar = widgets.IntProgress(min=0, max=num_half_sec, value=0) display(progressbar) for i in range(0, num_half_sec): progressbar.value = i time.sleep(0.5) progressbar.value = num_half_sec pass
def start(self, iterations): self.touched = True self.iter = int(iterations) self.t_start = time.time() self.progress_bar = widgets.IntProgress(min=0, max=self.iter, value=0) self.progress_bar.bar_style = 'info' self.label = widgets.HTML() self.box = widgets.VBox(children=[self.label, self.progress_bar]) display(self.box)
def _init_progress(self, total, progress): self._progress_bar = wd.IntProgress(min=0, max=total, value=progress, step=1, description="Progress") self._progress_label = wd.Label( value=self.format_progress_label(total, progress)) self._progress = wd.HBox([self._progress_bar, self._progress_label])
def init_progress(self): self.hbox = ipywidgets.HBox([ ipywidgets.IntProgress(min=0,max=len(self.wavelengths)), ipywidgets.Label(self.prog_string(0)) ]) self.progress = self.hbox.children[0] self.prog_label = self.hbox.children[1] display(self.hbox)
def define_int_progress_bar(): return widgets.IntProgress(value=0, min=0, max=10, step=1, description='Loading:', bar_style='success', orientation='horizontal', position='top')
def __init__(self, features, labels, classifier=None, display_func=None, data_iterator=None, keyboard_shortcuts=True): """ Make a class that allows semi-supervision. Parameters ---------- classifier : object An object that implements the standard sklearn fit/predict methods. features : np.array | pd.DataFrame The input array for your model labels : np.array | pd.Series | pd.DataFrame The labels for your data. visualisation : str | func Either a function that accepts one row of features and returns what should be displayed with IPython's `display`, or a string that is any of 'img' (sqaure images)... confidence : np.array | pd.Series | pd.DataFrame optionally, provide the confidence for your labels. """ self.layout = widgets.VBox([]) self.classifier = self._valid_classifier(classifier) self.features = self._valid_data(features) self.labels = self._valid_data(labels) self.progressbar = widgets.IntProgress(min=0, max=10, value=0, description='Progress:') self._display_func = (display_func if display_func is not None else display_functions._default_display_func) if data_iterator is not None: self._data_iterator = data_iterator elif isinstance(features, pd.DataFrame): self._data_iterator = iterator_functions._iterate_over_df elif isinstance(features, pd.Series): self._data_iterator = iterator_functions._iterate_over_series else: self._data_iterator = iterator_functions._default_data_iterator if keyboard_shortcuts: self.event_manager = ipyevents.events.Event( source=self.layout, watched_events=['keydown']) self.event_manager.on_dom_event(self._onkeydown) else: self.event_manager = None
def __init__(self, measurements_dir: str) -> None: self.progress_bar = widgets.IntProgress(value=0, step=1, description='Loading', orientation='horizontal') display(self.progress_bar) self.dns_graph = dg.load_dns_records_graph( os.path.join(measurements_dir, "dns_records.json"), self.update_progress) self.progress_bar.bar_style = "success"