def _widget(self): """ Create IPython widget for display within a notebook """ try: return self._cached_widget except AttributeError: pass try: from ipywidgets import Layout, VBox, HBox, IntText, Button, HTML, Accordion except ImportError: self._cached_widget = None return None layout = Layout(width="150px") if self.dashboard_link: link = '<p><b>Dashboard: </b><a href="%s" target="_blank">%s</a></p>\n' % ( self.dashboard_link, self.dashboard_link, ) else: link = "" title = "<h2>%s</h2>" % self._cluster_class_name title = HTML(title) dashboard = HTML(link) status = HTML(self._widget_status(), layout=Layout(min_width="150px")) if self._supports_scaling: request = IntText(0, description="Workers", layout=layout) scale = Button(description="Scale", layout=layout) minimum = IntText(0, description="Minimum", layout=layout) maximum = IntText(0, description="Maximum", layout=layout) adapt = Button(description="Adapt", layout=layout) accordion = Accordion( [HBox([request, scale]), HBox([minimum, maximum, adapt])], layout=Layout(min_width="500px"), ) accordion.selected_index = None accordion.set_title(0, "Manual Scaling") accordion.set_title(1, "Adaptive Scaling") def adapt_cb(b): self.adapt(minimum=minimum.value, maximum=maximum.value) update() adapt.on_click(adapt_cb) def scale_cb(b): with log_errors(): n = request.value with suppress(AttributeError): self._adaptive.stop() self.scale(n) update() scale.on_click(scale_cb) else: accordion = HTML("") box = VBox([title, HBox([status, accordion]), dashboard]) self._cached_widget = box def update(): status.value = self._widget_status() cluster_repr_interval = parse_timedelta( dask.config.get("distributed.deploy.cluster-repr-interval", default="ms")) pc = PeriodicCallback(update, cluster_repr_interval * 1000) self.periodic_callbacks["cluster-repr"] = pc pc.start() return box
def create_param_widget(self, param, value): from ipywidgets import Layout, HBox children = (HBox(),) if isinstance(value, bool): from ipywidgets import Label, ToggleButton p = Label(value=param, layout=Layout(width='10%')) t = ToggleButton(description=str(value), value=value) def on_bool_change(change): t.description = str(change['new']) self.params[self._method][param] = change['new'] self.replot_peaks() t.observe(on_bool_change, names='value') children = (p, t) elif isinstance(value, float): from ipywidgets import FloatSlider, FloatText, BoundedFloatText, \ Label from traitlets import link p = Label(value=param, layout=Layout(flex='0 1 auto', width='10%')) b = BoundedFloatText(value=0, min=1e-10, layout=Layout(flex='0 1 auto', width='10%'), font_weight='bold') a = FloatText(value=2 * value, layout=Layout(flex='0 1 auto', width='10%')) f = FloatSlider(value=value, min=b.value, max=a.value, step=np.abs(a.value - b.value) * 0.01, layout=Layout(flex='1 1 auto', width='60%')) l = FloatText(value=f.value, layout=Layout(flex='0 1 auto', width='10%'), disabled=True) link((f, 'value'), (l, 'value')) def on_min_change(change): if f.max > change['new']: f.min = change['new'] f.step = np.abs(f.max - f.min) * 0.01 def on_max_change(change): if f.min < change['new']: f.max = change['new'] f.step = np.abs(f.max - f.min) * 0.01 def on_param_change(change): self.params[self._method][param] = change['new'] self.replot_peaks() b.observe(on_min_change, names='value') f.observe(on_param_change, names='value') a.observe(on_max_change, names='value') children = (p, l, b, f, a) elif isinstance(value, int): from ipywidgets import IntSlider, IntText, BoundedIntText, \ Label from traitlets import link p = Label(value=param, layout=Layout(flex='0 1 auto', width='10%')) b = BoundedIntText(value=0, min=1e-10, layout=Layout(flex='0 1 auto', width='10%'), font_weight='bold') a = IntText(value=2 * value, layout=Layout(flex='0 1 auto', width='10%')) f = IntSlider(value=value, min=b.value, max=a.value, step=1, layout=Layout(flex='1 1 auto', width='60%')) l = IntText(value=f.value, layout=Layout(flex='0 1 auto', width='10%'), disabled=True) link((f, 'value'), (l, 'value')) def on_min_change(change): if f.max > change['new']: f.min = change['new'] f.step = 1 def on_max_change(change): if f.min < change['new']: f.max = change['new'] f.step = 1 def on_param_change(change): self.params[self._method][param] = change['new'] self.replot_peaks() b.observe(on_min_change, names='value') f.observe(on_param_change, names='value') a.observe(on_max_change, names='value') children = (p, l, b, f, a) container = HBox(children) return container
def __init__(self, net, width="95%", height="550px", play_rate=0.5): self._ignore_layer_updates = False self.player = _Player(self, play_rate) self.player.start() self.net = net r = random.randint(1, 1000000) self.class_id = "picture-dashboard-%s-%s" % (self.net.name, r) self._width = width self._height = height ## Global widgets: style = {"description_width": "initial"} self.feature_columns = IntText(description="Detail columns:", value=self.net.config["dashboard.features.columns"], min=0, max=1024, style=style) self.feature_scale = FloatText(description="Detail scale:", value=self.net.config["dashboard.features.scale"], min=0.1, max=10, style=style) self.feature_columns.observe(self.regenerate, names='value') self.feature_scale.observe(self.regenerate, names='value') ## Hack to center SVG as justify-content is broken: self.net_svg = HTML(value="""<p style="text-align:center">%s</p>""" % ("",), layout=Layout( width=self._width, overflow_x='auto', overflow_y="auto", justify_content="center")) # Make controls first: self.output = Output() controls = self.make_controls() config = self.make_config() super().__init__([config, controls, self.net_svg, self.output])
def test_widget_utils(): box = HBox() i0 = IntText() i0._ngl_name = 'i0' i1 = IntText() i1._ngl_name = 'i1' box.children = [i0, i1] assert i0 is widget_utils.get_widget_by_name(box, 'i0') assert i1 is widget_utils.get_widget_by_name(box, 'i1') box.children = [i1, i0] assert i0 is widget_utils.get_widget_by_name(box, 'i0') assert i1 is widget_utils.get_widget_by_name(box, 'i1') assert widget_utils.get_widget_by_name(box, 'i100') is None assert widget_utils.get_widget_by_name(None, 'i100') is None
def _make_slider_input(self, label, description, min_val, max_val): label_widget = Label(description) slider = widgets.IntSlider(continuous_update=True, min=min_val, max=max_val, readout=False) self._input[label] = IntText(continuous_update=True, layout={"width": "80px"}) widgets.link((self._input[label], "value"), (slider, "value")) return HBox([label_widget, slider, self._input[label]])
def _build_procesing_panel(self, processing_info): """ Build up the processing panel for filtering data. Parameters ---------- processing_info: dict Processing information that contains name and parameters. Returns ------- """ self._processing_parameters = processing_info parameter_list = [] # Add the title to the top of the processing area. title = Label('Process: ' + processing_info['name'], style={'font-weight': 'bold', 'font-size': '1.5em'}) title.layout.width = '100%' parameter_list.append(title) # Add all the parameters for parameter in self._processing_parameters.get('parameters'): if isinstance(parameter[1], (int, float, str, list, tuple)): label = Label(parameter[0]) label.layout.width = '50%' # TODO: This needs to be cleaned up / generalized. if isinstance(parameter[1], int): ft = IntText(value=parameter[1]) elif isinstance(parameter[1], float): ft = FloatText(value=parameter[1]) else: ft = Text(value=str(parameter[1])) ft.layout.width = '50%' box = HBox((label, ft )) parameter_list.append(box) # Add the Cancel and Process buttons cancel_button = Button(description='Cancel', value='Cancel') cancel_button.button_style = 'danger' cancel_button.on_click(self._processing_cancel_button_callback) process_button = Button(description='Process', value='Process') process_button.button_style = 'success' process_button.on_click(self._processing_process_button_callback) parameter_list.append(HBox((process_button, cancel_button))) # Add them all to the VBox self._processing_vbox.children = tuple(parameter_list)
def __init__(self, data, dimensions, **kwargs): GluePlotly.__init__(self, data, dimensions, **kwargs) self.DefaultLayoutTitles("", "", "") self.options['grouping_limit'] = IntText(description = 'Group limiy', value = 12) self.options['grouping_limit'].observe(lambda v:self.updateRender(), names='value') cl_options = list(cl.scales['8']['qual'].keys()) cl_options.append(GlueParallelCategoriesPlotly.default_color) self.options['colorscale'] = Dropdown(description = 'Color Palette:', value = GlueParallelCategoriesPlotly.default_color, options = cl_options) self.options['colorscale'].observe(lambda v:self.updateRender(), names='value') self.DefaultLegend('h', 0.01, -0.05); self.updateRender()
def _counter_nb(items, tot=None): from ipywidgets import IntProgress, IntText from IPython.display import display if tot is not None: g = IntText(value=0, description='total = %d' % tot) f = IntProgress(min=0, max=tot) display(f) g.desription = 'hi' else: g = IntText(value=0) f = None display(g) for ii, item in enumerate(items): if f: f.value += 1 g.value += 1 yield item
def __init__(self, title, function, length, play_rate=0.5): self.player = _Player(self, play_rate) self.player.start() self.title = title self.function = function self.length = length self.output = Output() self.position_text = IntText(value=0, layout=Layout(width="100%")) self.total_text = Label(value="of %s" % self.length, layout=Layout(width="100px")) controls = self.make_controls() super().__init__([controls, self.output])
def __init__(self, displayer: Callable[[Figure, Selection], Callable[[int, Any], None]], resolution: int = None, fig_kw={}, children=(), toolbar=(), **ka): from ipywidgets import BoundedIntText, IntText, Label def select(bounds_): i = self.level + 1 w_level.active = False w_level.max = i w_level.value = i setlevel(i, (resolution, bounds_)) w_level.active = True def show_running(b): w_running.icon = 'pause' if b else 'play' def show_precision(p): w_precision.value = p self.select = select self.show_precision = show_precision self.show_running = show_running def setlevel(i, new=None): self.level = i w_precision.value = display(i, new) board.canvas.draw_idle() # global design and widget definitions w_running = SimpleButton(icon='') w_level = BoundedIntText(0, min=0, max=0, layout=dict(width='1.6cm', padding='0cm')) w_level.active = True w_precision = IntText(0, disabled=True, layout=dict(width='1.6cm', padding='0cm')) super().__init__(children, toolbar=(w_running, Label('level:'), w_level, Label('precision:'), w_precision, *toolbar)) self.board = board = self.mpl_figure(**fig_kw) display = displayer(board, select) # callbacks w_running.on_click(lambda b: self.setrunning()) w_level.observe( (lambda c: (setlevel(c.new) if w_level.active else None)), 'value') super(app, self).__init__(display, **ka)
def __init__(self): micron_units = Label( 'micron') # use "option m" (Mac, for micro symbol) constWidth = '180px' tab_height = '500px' stepsize = 10 style = {'description_width': '250px'} layout = {'width': '400px'} self.tumor_radius = FloatText(description='tumor_radius', step=0.02, style=style, layout=layout) self.oncoprotein_mean = FloatText(description='oncoprotein_mean', step=0.02, style=style, layout=layout) self.oncoprotein_sd = FloatText(description='oncoprotein_sd', step=0.02, style=style, layout=layout) self.oncoprotein_min = FloatText(description='oncoprotein_min', step=0.02, style=style, layout=layout) self.oncoprotein_max = FloatText(description='oncoprotein_max', step=0.02, style=style, layout=layout) self.random_seed = IntText(description='random_seed', step=1, style=style, layout=layout) self.tab = VBox([ HBox([self.tumor_radius, Label('micron')]), HBox([self.oncoprotein_mean, Label('')]), HBox([self.oncoprotein_sd, Label('')]), HBox([self.oncoprotein_min, Label('')]), HBox([self.oncoprotein_max, Label('')]), HBox([self.random_seed, Label('')]), ])
def __init__(self, net, width="95%", height="550px", play_rate=0.5): self._ignore_layer_updates = False self.player = _Player(self, play_rate) self.player.start() self.net = net r = random.randint(1, 1000000) self.class_id = "picture-dashboard-%s-%s" % (self.net.name, r) self._width = width self._height = height ## Global widgets: style = {"description_width": "initial"} self.feature_columns = IntText( description="Detail columns:", value=self.net.config["dashboard.features.columns"], min=0, max=1024, style=style) self.feature_scale = FloatText( description="Detail scale:", value=self.net.config["dashboard.features.scale"], min=0.1, max=10, style=style) self.feature_columns.observe(self.regenerate, names='value') self.feature_scale.observe(self.regenerate, names='value') ## Hack to center SVG as justify-content is broken: self.net_svg = HTML(value="""<p style="text-align:center">%s</p>""" % ("", ), layout=Layout(width=self._width, overflow_x='auto', overflow_y="auto", justify_content="center")) # Make controls first: self.output = Output() controls = self.make_controls() config = self.make_config() super().__init__([config, controls, self.net_svg, self.output])
def __init__(self, candidate_labels, propositions): # internal vars self.header = '<p style="font-size: 150%;font-weight: 300;line-height: 1.39;margin: 0 0 12.5px;">{} <a target="_blank" href="{}">source</a></p>' self.candidate_labels = candidate_labels self.propositions = propositions self.choice = None self.clicked = False self.confusion_matrix = np.zeros((len(candidate_labels), len(candidate_labels)), dtype=np.int) # candidate buttons buttons = [Button(description=label) for label in self.candidate_labels] for b in buttons: b.on_click(self.on_button_clicked) hbox1 = HBox() hbox1.children = buttons self.buttons = buttons # scorebox and new_question button and confusion matrix self.scorebox = IntText(description='score', value=0, disabled=True) self.number = IntText(description='questions', value=0, disabled=True) new_question = Button(description='nouvelle question !') new_question.on_click(self.create_new_question) confusion_matrix_button = Button(description='afficher matrice de confusion') confusion_matrix_button.on_click(self.show_confusion_matrix) hbox2 = HBox() hbox2.children = [self.scorebox, self.number, new_question, confusion_matrix_button] # proposition box self.html = HTML() # general layout vbox = VBox() vbox.children = [hbox1, hbox2, self.html] self.box = vbox # generate first question self.create_new_question()
def __init__(self, data, dimensions, **kwargs): GluePlotly.__init__(self, data, dimensions, **kwargs) self.DefaultLayoutTitles("", self.dimensions[0], self.dimensions[1]) z_id = self.dimensions[2] self.max_color = max(self.data[z_id].flatten()) self.min_color = min(self.data[z_id].flatten()) color_options = [ 'Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis', 'Cividis' ] self.options['line_width'] = IntText(description='Lines width:', value=1) self.options['line_width'].observe( lambda v: self.UpdateTraces({'line.width': v['new']}), names='value') self.options['marker_size'] = IntText(description='Markers size:', value=3) self.options['marker_size'].observe( lambda v: self.UpdateTraces({'marker.size': v['new']}), names='value') self.options['color_range_min'] = FloatText(description='Color min:', value=self.min_color) self.options['color_range_min'].observe( lambda v: self.UpdateTraces({'zmin': v['new']}), names='value') self.options['color_range_max'] = FloatText(description='Color max:', value=self.max_color) self.options['color_range_max'].observe( lambda v: self.UpdateTraces({'zmax': v['new']}), names='value') self.options['color_scale'] = Dropdown(description='Color scale:', value='Greys', options=color_options) self.options['color_scale'].observe( lambda v: self.UpdateTraces({'colorscale': v['new']}), names='value') self.updateRender()
def _widget(self): """ Create IPython widget for display within a notebook """ try: return self._cached_widget except AttributeError: pass if self._gateway.asynchronous: return None try: from ipywidgets import Layout, VBox, HBox, IntText, Button, HTML except ImportError: self._cached_widget = None return None try: self._internal_client = self.get_client(set_as_default=False) except Exception: return None layout = Layout(width="150px") title = HTML("<h2>GatewayCluster</h2>") status = HTML(self._widget_status(), layout=Layout(min_width="150px")) request = IntText(0, description="Workers", layout=layout) scale = Button(description="Scale", layout=layout) @scale.on_click def scale_cb(b): with log_errors(): self.scale(request.value) elements = [title, HBox([status, request, scale])] if self.dashboard_link is not None: link = HTML( '<p><b>Dashboard: </b><a href="{0}" target="_blank">{0}' "</a></p>\n".format(self.dashboard_link)) elements.append(link) self._cached_widget = box = VBox(elements) self._internal_client.loop.add_callback(self._widget_updater, status) return box
def __init__(self, image_width=150, image_height=150, n_rows=3, n_cols=3): self._screen_im_number = IntText(value=n_rows * n_cols, description='screen_image_number', disabled=False) self.image_width = image_width self.image_height = image_height self.n_rows = n_rows self.n_cols = n_cols self._navi = Navi() self._save_btn = Button(description="Save", layout=Layout(width='auto')) self._none_checkbox = Checkbox(description="Select none", indent=False, layout=Layout(width='100px')) self._controls_box = HBox( [self._navi, self._save_btn, self._none_checkbox], layout=Layout(display='flex', justify_content='center', flex_flow='wrap', align_items='center')) self._grid_box = CaptureGrid(image_width=image_width, image_height=image_height, n_rows=n_rows, n_cols=n_cols, display_label=False) self._grid_label = HTML() self._labels_box = VBox(children=[self._grid_label, self._grid_box], layout=Layout(display='flex', justify_content='center', flex_wrap='wrap', align_items='center')) super().__init__(header=None, left_sidebar=None, center=self._labels_box, right_sidebar=None, footer=self._controls_box, pane_widths=(2, 8, 0), pane_heights=(1, 4, 1))
def __init__(self, grid_item=ImageButton, image_width=150, image_height=150, n_rows=3, n_cols=3, display_label=False): self.image_width = image_width self.image_height = image_height self.n_rows = n_rows self.n_cols = n_cols self._screen_im_number = IntText(value=n_rows * n_cols, description='screen_image_number', disabled=False) self._labels = [ grid_item(display_label=display_label, image_width='%dpx' % self.image_width, image_height='%dpx' % self.image_height) for _ in range(self._screen_im_number.value) ] self.callback = None self.observe(self.on_state_change, 'current_state') gap = 40 if display_label else 15 centered_settings = { 'grid_template_columns': " ".join([ "%dpx" % (self.image_width + gap) for i in range(self.n_cols) ]), 'grid_template_rows': " ".join([ "%dpx" % (self.image_height + gap) for i in range(self.n_rows) ]), 'justify_content': 'center', 'align_content': 'space-around' } super().__init__(children=self._labels, layout=Layout(**centered_settings))
def interact_with_plot_all_outputs(sa_dict, demo=False, manual=True): """ This function adds the ability to interactively adjust all of the plotting.make_plot() arguments. Parameters ---------- sa_dict : dict a dictionary with all the sensitivity analysis results. demo : bool, optional plot only few outcomes for demo purpose. Returns ------- Interactive widgets to control plot """ min_val_box = BoundedFloatText(value=0.01, min=0, max=1, description='Min value:') top_box = IntText(value=20, description='Show top:') stacks = Checkbox( description='Show stacked plots:', value=True, ) error_bars = Checkbox(description='Show error bars:', value=True) log_axis = Checkbox(description='Use log axis:', value=True) # get a list of all the parameter options key = sa_dict.keys()[0] param_options = list(sa_dict[key][0].Parameter.values) highlighted = SelectMultiple(description="Choose parameters to highlight", options=param_options, value=[]) return interact(plot_all_outputs, sa_dict=fixed(sa_dict), demo=fixed(demo), min_val=min_val_box, top=top_box, stacked=stacks, error_bars=error_bars, log_axis=log_axis, highlighted_parameters=highlighted, __manual=manual)
def test_player_link_to_ipywidgets(): traj = pt.datafiles.load_tz2() view = nv.show_pytraj(traj) int_text = IntText(2) float_text = BoundedFloatText(40, min=10) HBox([int_text, float_text]) link((int_text, 'value'), (view.player, 'step')) link((float_text, 'value'), (view.player, 'delay')) nt.assert_equal(view.player.step, 2) nt.assert_equal(view.player.delay, 40) float_text.value = 100 nt.assert_equal(view.player.delay, 100) float_text.value = 0.00 # we set min=10 nt.assert_equal(view.player.delay, 10)
def _widget(self): """ Create IPython widget for display within a notebook """ try: return self._cached_widget except AttributeError: pass from ipywidgets import Layout, VBox, HBox, IntText, Button, HTML client = self._dask_client() layout = Layout(width='150px') title = HTML('<h2>YarnCluster</h2>') status = HTML(self._widget_status(), layout=Layout(min_width='150px')) request = IntText(0, description='Workers', layout=layout) scale = Button(description='Scale', layout=layout) @scale.on_click def scale_cb(b): with log_errors(): self.scale(request.value) elements = [title, HBox([status, request, scale])] if self.dashboard_link is not None: link = HTML('<p><b>Dashboard: </b><a href="%s" target="_blank">%s' '</a></p>\n' % (self.dashboard_link, self.dashboard_link)) elements.append(link) self._cached_widget = box = VBox(elements) def update(): status.value = self._widget_status() pc = PeriodicCallback(update, 500, io_loop=client.loop) pc.start() return box
def interact_plot_inversion(self, maxIter=30): interact( self.plot_inversion, mode=RadioButtons(description="mode", options=["Run", "Explore"], value="Run"), maxIter=IntText(value=maxIter), m0=FloatSlider(min=-2, max=2, step=0.05, value=0.0, continuous_update=False), mref=FloatSlider(min=-2, max=2, step=0.05, value=0.0, continuous_update=False), percentage=FloatText(value=self.percentage), floor=FloatText(value=self.floor), chifact=FloatText(value=1.0), beta0_ratio=FloatText(value=100), coolingFactor=FloatSlider(min=0.1, max=10, step=1, value=2, continuous_update=False), coolingRate=IntSlider(min=1, max=10, step=1, value=1, continuous_update=False), alpha_s=FloatText(value=1e-10), alpha_x=FloatText(value=0), target=False, option=ToggleButtons(options=["misfit", "tikhonov"], value="misfit"), i_iteration=IntSlider(min=0, max=maxIter, step=1, value=0, continuous_update=False), )
def test_widget_utils(): box = HBox() i0 = IntText() i0._ngl_name = 'i0' i1 = IntText() i1._ngl_name = 'i1' box.children = [i0, i1] assert i0 is widget_utils.get_widget_by_name(box, 'i0') assert i1 is widget_utils.get_widget_by_name(box, 'i1') box.children = [i1, i0] assert i0 is widget_utils.get_widget_by_name(box, 'i0') assert i1 is widget_utils.get_widget_by_name(box, 'i1') nt.assert_equal(widget_utils.get_widget_by_name(box, 'i100'), None)
def __init__(self): # Add the required widgets self.wt_url = Text(placeholder='Add Database Host', description='Host:', disabled=False) self.wt_port = IntText(value=5432, description='Port:', disabled=False) self.wt_name = Text(placeholder='Add Database Name', description='DB Name:', disabled=False) self.wt_user = Text(placeholder='Username', description='DB User:'******'******', description='DB Password:'******'Schema', description='DB Schema:', disabled=False) self.wt_table = Text(placeholder='Table', description='Parcel Table:', disabled=False) self.wt_foiid = Text(placeholder='Attribute', description='FOI Attribute:', disabled=False) self.wa_sql = Textarea(placeholder='SQL Additional Conditions', description='SQL Additional Conditions:', disabled=False) super().__init__([self.wt_url, self.wt_port, self.wt_name, self.wt_user,\ self.wt_pass, self.wt_schema, self.wt_table, self.wt_foiid,\ self.wa_sql])
def render_image_input_form(): form_item_layout = Layout(display='flex', flex_flow='row', justify_content='space-between') FOLIO_SIDES = ('r', 'v') input_dir, out_dir, first_fol_ind, first_fol_side, start_fol, siglum = \ Text(value='images/input_N'), Text(value='images/output_N'), IntText(value=0), Dropdown(options=FOLIO_SIDES), IntText(value=1), Text() submit_button = Button(description='Submit', disabled=False, button_style='success', layout=form_item_layout) form_items = [ Box([Label(value='Image Directory'), input_dir], layout=form_item_layout), Box([Label(value='Output Directory'), out_dir], layout=form_item_layout), Box([Label(value='Index of first folio'), first_fol_ind], layout=form_item_layout), Box([Label(value='Side of first folio'), first_fol_side], layout=form_item_layout), Box([Label(value='Start of foliation'), start_fol], layout=form_item_layout), Box([Label(value='MS siglum'), siglum], layout=form_item_layout), submit_button ] image_input_form = Box(form_items, layout=Layout(display='flex', flex_flow='column', border='solid 2px', align_items='stretch', width='50%')) submit_button.on_click(handle_submit) return image_input_form
def __init__(self, layer_state): self.state = layer_state self.widget_visible = Checkbox(description='visible', value=self.state.visible) link((self.state, 'visible'), (self.widget_visible, 'value')) self.widget_color = ColorPicker(description='color') link((self.state, 'color'), (self.widget_color, 'value')) self.widget_linewidth = IntText(description='line width') link((self.state, 'linewidth'), (self.widget_linewidth, 'value')) self.widget_attribute = LinkedDropdown(self.state, 'attribute', label='attribute') if self.state.v_min is None: self.state.v_min = 0 self.widget_v_min = FloatText(description='vmin') link((self.state, 'v_min'), (self.widget_v_min, 'value')) if self.state.v_max is None: self.state.v_max = 1 self.widget_v_max = FloatText(description='vmax') link((self.state, 'v_max'), (self.widget_v_max, 'value')) self.widget_percentile = LinkedDropdown(self.state, 'percentile', label='percentile') super().__init__([ self.widget_visible, self.widget_color, self.widget_linewidth, self.widget_attribute, self.widget_v_min, self.widget_v_max, self.widget_percentile ])
def _widget(self): """ Create IPython widget for display within a notebook """ try: return self._cached_widget except AttributeError: pass from ipywidgets import Layout, VBox, HBox, IntText, Button, HTML client = self._dask_client() layout = Layout(width='150px') title = HTML('<h2>YarnCluster</h2>') status = HTML(self._widget_status(), layout=Layout(min_width='150px')) request = IntText(0, description='Workers', layout=layout) scale = Button(description='Scale', layout=layout) @scale.on_click def scale_cb(b): with log_errors(): self.scale(request.value) box = VBox([title, HBox([status, request, scale])]) self._cached_widget = box def update(): status.value = self._widget_status() pc = PeriodicCallback(update, 500, io_loop=client.loop) pc.start() return box
def _widget(self): """ Create IPython widget for display within a notebook """ try: return self._cached_widget except AttributeError: pass from ipywidgets import Layout, VBox, HBox, IntText, Button, HTML, Accordion layout = Layout(width='150px') if 'bokeh' in self.scheduler.services: template = config.get('diagnostics-link', 'http://{host}:{port}/status') host = self.scheduler.address.split('://')[1].split(':')[0] port = self.scheduler.services['bokeh'].port link = template.format(host=host, port=port, **os.environ) link = '<p><b>Dashboard: </b><a href="%s" target="_blank">%s</a></p>\n' % (link, link) else: link = '' title = '<h2>%s</h2>' % type(self).__name__ title = HTML(title) dashboard = HTML(link) status = HTML(self._widget_status(), layout=Layout(min_width='150px')) request = IntText(0, description='Workers', layout=layout) scale = Button(description='Scale', layout=layout) minimum = IntText(0, description='Minimum', layout=layout) maximum = IntText(0, description='Maximum', layout=layout) adapt = Button(description='Adapt', layout=layout) accordion = Accordion([HBox([request, scale]), HBox([minimum, maximum, adapt])], layout=Layout(min_width='500px')) accordion.selected_index = None accordion.set_title(0, 'Manual Scaling') accordion.set_title(1, 'Adaptive Scaling') box = VBox([title, HBox([status, accordion]), dashboard]) self._cached_widget = box def adapt_cb(b): self.adapt(minimum=minimum.value, maximum=maximum.value) adapt.on_click(adapt_cb) def scale_cb(b): with log_errors(): n = request.value with ignoring(AttributeError): self._adaptive.stop() self.scale(n) scale.on_click(scale_cb) scheduler_ref = ref(self.scheduler) def update(): status.value = self._widget_status() pc = PeriodicCallback(update, 500, io_loop=self.scheduler.loop) self.scheduler.periodic_callbacks['cluster-repr'] = pc pc.start() return box
def _widget(self): """ Create IPython widget for display within a notebook """ try: return self._cached_widget except AttributeError: pass if self.asynchronous: return None try: from ipywidgets import Layout, VBox, HBox, IntText, Button, HTML, Accordion except ImportError: self._cached_widget = None return None layout = Layout(width="150px") title = HTML("<h2>YarnCluster</h2>") status = HTML(self._widget_status(), layout=Layout(min_width="150px")) request = IntText(0, description="Workers", layout=layout) scale = Button(description="Scale", layout=layout) minimum = IntText(0, description="Minimum", layout=layout) maximum = IntText(0, description="Maximum", layout=layout) adapt = Button(description="Adapt", layout=layout) accordion = Accordion( [HBox([request, scale]), HBox([minimum, maximum, adapt])], layout=Layout(min_width="500px"), ) accordion.selected_index = None accordion.set_title(0, "Manual Scaling") accordion.set_title(1, "Adaptive Scaling") @adapt.on_click def adapt_cb(b): self.adapt(minimum=minimum.value, maximum=maximum.value) @scale.on_click def scale_cb(b): with log_errors(): self.scale(request.value) app_id = HTML("<p><b>Application ID: </b>{0}</p>".format(self.app_id)) elements = [title, HBox([status, accordion]), app_id] if self.dashboard_link is not None: link = HTML( '<p><b>Dashboard: </b><a href="{0}" target="_blank">{0}' "</a></p>\n".format(self.dashboard_link)) elements.append(link) self._cached_widget = box = VBox(elements) self._status_widget = status return box
def __init__(self): micron_units = Label( 'micron') # use "option m" (Mac, for micro symbol) constWidth = '180px' tab_height = '500px' stepsize = 10 #style = {'description_width': '250px'} style = {'description_width': '25%'} layout = {'width': '400px'} name_button_layout = {'width': '25%'} widget_layout = {'width': '15%'} units_button_layout = {'width': '15%'} desc_button_layout = {'width': '45%'} param_name1 = Button(description='number_of_invaders', disabled=True, layout=name_button_layout) param_name1.style.button_color = 'lightgreen' self.number_of_invaders = IntText(value=15, step=1, style=style, layout=widget_layout) param_name2 = Button(description='number_of_suppliers', disabled=True, layout=name_button_layout) param_name2.style.button_color = 'tan' self.number_of_suppliers = IntText(value=50, step=1, style=style, layout=widget_layout) param_name3 = Button(description='number_of_scouts', disabled=True, layout=name_button_layout) param_name3.style.button_color = 'lightgreen' self.number_of_scouts = IntText(value=10, step=1, style=style, layout=widget_layout) param_name4 = Button(description='number_of_attackers', disabled=True, layout=name_button_layout) param_name4.style.button_color = 'tan' self.number_of_attackers = IntText(value=50, step=1, style=style, layout=widget_layout) param_name5 = Button(description='invader_max_birth_rate', disabled=True, layout=name_button_layout) param_name5.style.button_color = 'lightgreen' self.invader_max_birth_rate = FloatText(value=0.0028, step=0.0001, style=style, layout=widget_layout) param_name6 = Button(description='invader_max_death_rate', disabled=True, layout=name_button_layout) param_name6.style.button_color = 'tan' self.invader_max_death_rate = FloatText(value=0.001, step=0.0001, style=style, layout=widget_layout) param_name7 = Button(description='invader_persistence_time', disabled=True, layout=name_button_layout) param_name7.style.button_color = 'lightgreen' self.invader_persistence_time = FloatText(value=15, step=1, style=style, layout=widget_layout) param_name8 = Button(description='invader_migration_speed', disabled=True, layout=name_button_layout) param_name8.style.button_color = 'tan' self.invader_migration_speed = FloatText(value=0.25, step=0.01, style=style, layout=widget_layout) param_name9 = Button(description='invader_migration_bias', disabled=True, layout=name_button_layout) param_name9.style.button_color = 'lightgreen' self.invader_migration_bias = FloatText(value=0.5, step=0.1, style=style, layout=widget_layout) param_name10 = Button(description='invader_secretion_rate', disabled=True, layout=name_button_layout) param_name10.style.button_color = 'tan' self.invader_secretion_rate = FloatText(value=100, step=10, style=style, layout=widget_layout) param_name11 = Button(description='invader_quorum_weight', disabled=True, layout=name_button_layout) param_name11.style.button_color = 'lightgreen' self.invader_quorum_weight = FloatText(value=.1, step=0.01, style=style, layout=widget_layout) param_name12 = Button(description='scout_persistence_time', disabled=True, layout=name_button_layout) param_name12.style.button_color = 'tan' self.scout_persistence_time = FloatText(value=15, step=1, style=style, layout=widget_layout) param_name13 = Button(description='scout_migration_speed', disabled=True, layout=name_button_layout) param_name13.style.button_color = 'lightgreen' self.scout_migration_speed = FloatText(value=.5, step=0.1, style=style, layout=widget_layout) param_name14 = Button(description='scout_migration_bias', disabled=True, layout=name_button_layout) param_name14.style.button_color = 'tan' self.scout_migration_bias = FloatText(value=0.125, step=0.01, style=style, layout=widget_layout) param_name15 = Button(description='scout_secretion_rate', disabled=True, layout=name_button_layout) param_name15.style.button_color = 'lightgreen' self.scout_secretion_rate = FloatText(value=100, step=10, style=style, layout=widget_layout) param_name16 = Button(description='scout_signal_threshold', disabled=True, layout=name_button_layout) param_name16.style.button_color = 'tan' self.scout_signal_threshold = FloatText(value=0.1, step=0.01, style=style, layout=widget_layout) param_name17 = Button(description='attacker_max_birth_rate', disabled=True, layout=name_button_layout) param_name17.style.button_color = 'lightgreen' self.attacker_max_birth_rate = FloatText(value=0.0005, step=0.0001, style=style, layout=widget_layout) param_name18 = Button(description='attacker_max_death_rate', disabled=True, layout=name_button_layout) param_name18.style.button_color = 'tan' self.attacker_max_death_rate = FloatText(value=0.0001, step=1e-05, style=style, layout=widget_layout) param_name19 = Button(description='attacker_persistence_time', disabled=True, layout=name_button_layout) param_name19.style.button_color = 'lightgreen' self.attacker_persistence_time = FloatText(value=15, step=1, style=style, layout=widget_layout) param_name20 = Button(description='attacker_migration_speed', disabled=True, layout=name_button_layout) param_name20.style.button_color = 'tan' self.attacker_migration_speed = FloatText(value=1, step=0.1, style=style, layout=widget_layout) param_name21 = Button(description='attacker_migration_bias', disabled=True, layout=name_button_layout) param_name21.style.button_color = 'lightgreen' self.attacker_migration_bias = FloatText(value=0.25, step=0.01, style=style, layout=widget_layout) param_name22 = Button(description='attacker_secretion_rate', disabled=True, layout=name_button_layout) param_name22.style.button_color = 'tan' self.attacker_secretion_rate = FloatText(value=100, step=10, style=style, layout=widget_layout) param_name23 = Button(description='attacker_signal_threshold', disabled=True, layout=name_button_layout) param_name23.style.button_color = 'lightgreen' self.attacker_signal_threshold = FloatText(value=0.1, step=0.01, style=style, layout=widget_layout) param_name24 = Button(description='supplier_secretion_rate', disabled=True, layout=name_button_layout) param_name24.style.button_color = 'tan' self.supplier_secretion_rate = FloatText(value=100, step=10, style=style, layout=widget_layout) units_button1 = Button(description='', disabled=True, layout=units_button_layout) units_button1.style.button_color = 'lightgreen' units_button2 = Button(description='', disabled=True, layout=units_button_layout) units_button2.style.button_color = 'tan' units_button3 = Button(description='', disabled=True, layout=units_button_layout) units_button3.style.button_color = 'lightgreen' units_button4 = Button(description='', disabled=True, layout=units_button_layout) units_button4.style.button_color = 'tan' units_button5 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button5.style.button_color = 'lightgreen' units_button6 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button6.style.button_color = 'tan' units_button7 = Button(description='min', disabled=True, layout=units_button_layout) units_button7.style.button_color = 'lightgreen' units_button8 = Button(description='micron/min', disabled=True, layout=units_button_layout) units_button8.style.button_color = 'tan' units_button9 = Button(description='', disabled=True, layout=units_button_layout) units_button9.style.button_color = 'lightgreen' units_button10 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button10.style.button_color = 'tan' units_button11 = Button(description='', disabled=True, layout=units_button_layout) units_button11.style.button_color = 'lightgreen' units_button12 = Button(description='min', disabled=True, layout=units_button_layout) units_button12.style.button_color = 'tan' units_button13 = Button(description='micron/min', disabled=True, layout=units_button_layout) units_button13.style.button_color = 'lightgreen' units_button14 = Button(description='', disabled=True, layout=units_button_layout) units_button14.style.button_color = 'tan' units_button15 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button15.style.button_color = 'lightgreen' units_button16 = Button(description='', disabled=True, layout=units_button_layout) units_button16.style.button_color = 'tan' units_button17 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button17.style.button_color = 'lightgreen' units_button18 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button18.style.button_color = 'tan' units_button19 = Button(description='min', disabled=True, layout=units_button_layout) units_button19.style.button_color = 'lightgreen' units_button20 = Button(description='micron/min', disabled=True, layout=units_button_layout) units_button20.style.button_color = 'tan' units_button21 = Button(description='', disabled=True, layout=units_button_layout) units_button21.style.button_color = 'lightgreen' units_button22 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button22.style.button_color = 'tan' units_button23 = Button(description='', disabled=True, layout=units_button_layout) units_button23.style.button_color = 'lightgreen' units_button24 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button24.style.button_color = 'tan' desc_button1 = Button(description='number of randomly placed invaders', disabled=True, layout=desc_button_layout) desc_button1.style.button_color = 'lightgreen' desc_button2 = Button( description='number of randomly placed suppliers', disabled=True, layout=desc_button_layout) desc_button2.style.button_color = 'tan' desc_button3 = Button(description='number of randomly placed scouts', disabled=True, layout=desc_button_layout) desc_button3.style.button_color = 'lightgreen' desc_button4 = Button( description='number of randomly placed attackers', disabled=True, layout=desc_button_layout) desc_button4.style.button_color = 'tan' desc_button5 = Button(description='max birth rate for invaders', disabled=True, layout=desc_button_layout) desc_button5.style.button_color = 'lightgreen' desc_button6 = Button(description='max death rate for invaders', disabled=True, layout=desc_button_layout) desc_button6.style.button_color = 'tan' desc_button7 = Button( description='persistence time for invader migration', disabled=True, layout=desc_button_layout) desc_button7.style.button_color = 'lightgreen' desc_button8 = Button(description='speed of invader cells', disabled=True, layout=desc_button_layout) desc_button8.style.button_color = 'tan' desc_button9 = Button(description='invader migration bias', disabled=True, layout=desc_button_layout) desc_button9.style.button_color = 'lightgreen' desc_button10 = Button( description='rate invaders secrete their signals', disabled=True, layout=desc_button_layout) desc_button10.style.button_color = 'tan' desc_button11 = Button( description='motile direction = w*grad(Q) - (1-w)*grad(D)', disabled=True, layout=desc_button_layout) desc_button11.style.button_color = 'lightgreen' desc_button12 = Button( description='persistence time for scout migration', disabled=True, layout=desc_button_layout) desc_button12.style.button_color = 'tan' desc_button13 = Button(description='speed of scout cells', disabled=True, layout=desc_button_layout) desc_button13.style.button_color = 'lightgreen' desc_button14 = Button(description='scout migration bias', disabled=True, layout=desc_button_layout) desc_button14.style.button_color = 'tan' desc_button15 = Button(description='rate scouts secrete their signals', disabled=True, layout=desc_button_layout) desc_button15.style.button_color = 'lightgreen' desc_button16 = Button(description='scouts release S if Q > threshold', disabled=True, layout=desc_button_layout) desc_button16.style.button_color = 'tan' desc_button17 = Button(description='max birth rate for attackers', disabled=True, layout=desc_button_layout) desc_button17.style.button_color = 'lightgreen' desc_button18 = Button(description='max death rate for attackers', disabled=True, layout=desc_button_layout) desc_button18.style.button_color = 'tan' desc_button19 = Button( description='persistence time for attacker migration', disabled=True, layout=desc_button_layout) desc_button19.style.button_color = 'lightgreen' desc_button20 = Button(description='speed of attacker cells', disabled=True, layout=desc_button_layout) desc_button20.style.button_color = 'tan' desc_button21 = Button(description='attacker migration bias', disabled=True, layout=desc_button_layout) desc_button21.style.button_color = 'lightgreen' desc_button22 = Button( description='rate attackers secrete their signals', disabled=True, layout=desc_button_layout) desc_button22.style.button_color = 'tan' desc_button23 = Button( description='attackers release P if S > threshold', disabled=True, layout=desc_button_layout) desc_button23.style.button_color = 'lightgreen' desc_button24 = Button(description='rate suppliers release resource', disabled=True, layout=desc_button_layout) desc_button24.style.button_color = 'tan' row1 = [ param_name1, self.number_of_invaders, units_button1, desc_button1 ] row2 = [ param_name2, self.number_of_suppliers, units_button2, desc_button2 ] row3 = [ param_name3, self.number_of_scouts, units_button3, desc_button3 ] row4 = [ param_name4, self.number_of_attackers, units_button4, desc_button4 ] row5 = [ param_name5, self.invader_max_birth_rate, units_button5, desc_button5 ] row6 = [ param_name6, self.invader_max_death_rate, units_button6, desc_button6 ] row7 = [ param_name7, self.invader_persistence_time, units_button7, desc_button7 ] row8 = [ param_name8, self.invader_migration_speed, units_button8, desc_button8 ] row9 = [ param_name9, self.invader_migration_bias, units_button9, desc_button9 ] row10 = [ param_name10, self.invader_secretion_rate, units_button10, desc_button10 ] row11 = [ param_name11, self.invader_quorum_weight, units_button11, desc_button11 ] row12 = [ param_name12, self.scout_persistence_time, units_button12, desc_button12 ] row13 = [ param_name13, self.scout_migration_speed, units_button13, desc_button13 ] row14 = [ param_name14, self.scout_migration_bias, units_button14, desc_button14 ] row15 = [ param_name15, self.scout_secretion_rate, units_button15, desc_button15 ] row16 = [ param_name16, self.scout_signal_threshold, units_button16, desc_button16 ] row17 = [ param_name17, self.attacker_max_birth_rate, units_button17, desc_button17 ] row18 = [ param_name18, self.attacker_max_death_rate, units_button18, desc_button18 ] row19 = [ param_name19, self.attacker_persistence_time, units_button19, desc_button19 ] row20 = [ param_name20, self.attacker_migration_speed, units_button20, desc_button20 ] row21 = [ param_name21, self.attacker_migration_bias, units_button21, desc_button21 ] row22 = [ param_name22, self.attacker_secretion_rate, units_button22, desc_button22 ] row23 = [ param_name23, self.attacker_signal_threshold, units_button23, desc_button23 ] row24 = [ param_name24, self.supplier_secretion_rate, units_button24, desc_button24 ] box_layout = Layout(display='flex', flex_flow='row', align_items='stretch', width='100%') box1 = Box(children=row1, layout=box_layout) box2 = Box(children=row2, layout=box_layout) box3 = Box(children=row3, layout=box_layout) box4 = Box(children=row4, layout=box_layout) box5 = Box(children=row5, layout=box_layout) box6 = Box(children=row6, layout=box_layout) box7 = Box(children=row7, layout=box_layout) box8 = Box(children=row8, layout=box_layout) box9 = Box(children=row9, layout=box_layout) box10 = Box(children=row10, layout=box_layout) box11 = Box(children=row11, layout=box_layout) box12 = Box(children=row12, layout=box_layout) box13 = Box(children=row13, layout=box_layout) box14 = Box(children=row14, layout=box_layout) box15 = Box(children=row15, layout=box_layout) box16 = Box(children=row16, layout=box_layout) box17 = Box(children=row17, layout=box_layout) box18 = Box(children=row18, layout=box_layout) box19 = Box(children=row19, layout=box_layout) box20 = Box(children=row20, layout=box_layout) box21 = Box(children=row21, layout=box_layout) box22 = Box(children=row22, layout=box_layout) box23 = Box(children=row23, layout=box_layout) box24 = Box(children=row24, layout=box_layout) self.tab = VBox([ box1, box2, box3, box4, box5, box6, box7, box8, box9, box10, box11, box12, box13, box14, box15, box16, box17, box18, box19, box20, box21, box22, box23, box24, ])
def _widget(self): """ Create IPython widget for display within a notebook """ try: return self._cached_widget except AttributeError: pass try: from ipywidgets import Layout, VBox, HBox, IntText, Button, HTML, Accordion except ImportError: self._cached_widget = None return None layout = Layout(width="150px") if self.dashboard_link: dashboard_link = ( '<p><b>Dashboard: </b><a href="%s" target="_blank">%s</a></p>\n' % (self.dashboard_link, self.dashboard_link) ) else: dashboard_link = "" if self.jupyter_link: jupyter_link = ( '<p><b>Jupyter: </b><a href="%s" target="_blank">%s</a></p>\n' % (self.jupyter_link, self.jupyter_link) ) else: jupyter_link = "" title = "<h2>%s</h2>" % self._cluster_class_name title = HTML(title) dashboard = HTML(dashboard_link) jupyter = HTML(jupyter_link) status = HTML(self._widget_status(), layout=Layout(min_width="150px")) if self._supports_scaling: request = IntText( self.initial_node_count, description="Nodes", layout=layout ) scale = Button(description="Scale", layout=layout) minimum = IntText(0, description="Minimum", layout=layout) maximum = IntText(0, description="Maximum", layout=layout) adapt = Button(description="Adapt", layout=layout) accordion = Accordion( [HBox([request, scale]), HBox([minimum, maximum, adapt])], layout=Layout(min_width="500px"), ) accordion.selected_index = None accordion.set_title(0, "Manual Scaling") accordion.set_title(1, "Adaptive Scaling") def adapt_cb(b): self.adapt(minimum=minimum.value, maximum=maximum.value) update() adapt.on_click(adapt_cb) def scale_cb(b): with log_errors(): n = request.value with suppress(AttributeError): self._adaptive.stop() self.scale(n) update() scale.on_click(scale_cb) else: accordion = HTML("") box = VBox([title, HBox([status, accordion]), jupyter, dashboard]) self._cached_widget = box def update(): self.close_when_disconnect() status.value = self._widget_status() pc = PeriodicCallback(update, 500) # , io_loop=self.loop) self.periodic_callbacks["cluster-repr"] = pc pc.start() return box
class Dashboard(VBox): """ Build the dashboard for Jupyter widgets. Requires running in a notebook/jupyterlab. """ def __init__(self, net, width="95%", height="550px", play_rate=0.5): self._ignore_layer_updates = False self.player = _Player(self, play_rate) self.player.start() self.net = net r = random.randint(1, 1000000) self.class_id = "picture-dashboard-%s-%s" % (self.net.name, r) self._width = width self._height = height ## Global widgets: style = {"description_width": "initial"} self.feature_columns = IntText(description="Detail columns:", value=self.net.config["dashboard.features.columns"], min=0, max=1024, style=style) self.feature_scale = FloatText(description="Detail scale:", value=self.net.config["dashboard.features.scale"], min=0.1, max=10, style=style) self.feature_columns.observe(self.regenerate, names='value') self.feature_scale.observe(self.regenerate, names='value') ## Hack to center SVG as justify-content is broken: self.net_svg = HTML(value="""<p style="text-align:center">%s</p>""" % ("",), layout=Layout( width=self._width, overflow_x='auto', overflow_y="auto", justify_content="center")) # Make controls first: self.output = Output() controls = self.make_controls() config = self.make_config() super().__init__([config, controls, self.net_svg, self.output]) def propagate(self, inputs): """ Propagate inputs through the dashboard view of the network. """ if dynamic_pictures_check(): return self.net.propagate(inputs, class_id=self.class_id, update_pictures=True) else: self.regenerate(inputs=input) def goto(self, position): if len(self.net.dataset.inputs) == 0 or len(self.net.dataset.targets) == 0: return if self.control_select.value == "Train": length = len(self.net.dataset.train_inputs) elif self.control_select.value == "Test": length = len(self.net.dataset.test_inputs) #### Position it: if position == "begin": self.control_slider.value = 0 elif position == "end": self.control_slider.value = length - 1 elif position == "prev": if self.control_slider.value - 1 < 0: self.control_slider.value = length - 1 # wrap around else: self.control_slider.value = max(self.control_slider.value - 1, 0) elif position == "next": if self.control_slider.value + 1 > length - 1: self.control_slider.value = 0 # wrap around else: self.control_slider.value = min(self.control_slider.value + 1, length - 1) self.position_text.value = self.control_slider.value def change_select(self, change=None): """ """ self.update_control_slider(change) self.regenerate() def update_control_slider(self, change=None): self.net.config["dashboard.dataset"] = self.control_select.value if len(self.net.dataset.inputs) == 0 or len(self.net.dataset.targets) == 0: self.total_text.value = "of 0" self.control_slider.value = 0 self.position_text.value = 0 self.control_slider.disabled = True self.position_text.disabled = True for child in self.control_buttons.children: if not hasattr(child, "icon") or child.icon != "refresh": child.disabled = True return if self.control_select.value == "Test": self.total_text.value = "of %s" % len(self.net.dataset.test_inputs) minmax = (0, max(len(self.net.dataset.test_inputs) - 1, 0)) if minmax[0] <= self.control_slider.value <= minmax[1]: pass # ok else: self.control_slider.value = 0 self.control_slider.min = minmax[0] self.control_slider.max = minmax[1] if len(self.net.dataset.test_inputs) == 0: disabled = True else: disabled = False elif self.control_select.value == "Train": self.total_text.value = "of %s" % len(self.net.dataset.train_inputs) minmax = (0, max(len(self.net.dataset.train_inputs) - 1, 0)) if minmax[0] <= self.control_slider.value <= minmax[1]: pass # ok else: self.control_slider.value = 0 self.control_slider.min = minmax[0] self.control_slider.max = minmax[1] if len(self.net.dataset.train_inputs) == 0: disabled = True else: disabled = False self.control_slider.disabled = disabled self.position_text.disbaled = disabled self.position_text.value = self.control_slider.value for child in self.control_buttons.children: if not hasattr(child, "icon") or child.icon != "refresh": child.disabled = disabled def update_zoom_slider(self, change): if change["name"] == "value": self.net.config["svg_scale"] = self.zoom_slider.value self.regenerate() def update_position_text(self, change): # {'name': 'value', 'old': 2, 'new': 3, 'owner': IntText(value=3, layout=Layout(width='100%')), 'type': 'change'} self.control_slider.value = change["new"] def get_current_input(self): if self.control_select.value == "Train" and len(self.net.dataset.train_targets) > 0: return self.net.dataset.train_inputs[self.control_slider.value] elif self.control_select.value == "Test" and len(self.net.dataset.test_targets) > 0: return self.net.dataset.test_inputs[self.control_slider.value] def get_current_targets(self): if self.control_select.value == "Train" and len(self.net.dataset.train_targets) > 0: return self.net.dataset.train_targets[self.control_slider.value] elif self.control_select.value == "Test" and len(self.net.dataset.test_targets) > 0: return self.net.dataset.test_targets[self.control_slider.value] def update_slider_control(self, change): if len(self.net.dataset.inputs) == 0 or len(self.net.dataset.targets) == 0: self.total_text.value = "of 0" return if change["name"] == "value": self.position_text.value = self.control_slider.value if self.control_select.value == "Train" and len(self.net.dataset.train_targets) > 0: self.total_text.value = "of %s" % len(self.net.dataset.train_inputs) if self.net.model is None: return if not dynamic_pictures_check(): self.regenerate(inputs=self.net.dataset.train_inputs[self.control_slider.value], targets=self.net.dataset.train_targets[self.control_slider.value]) return output = self.net.propagate(self.net.dataset.train_inputs[self.control_slider.value], class_id=self.class_id, update_pictures=True) if self.feature_bank.value in self.net.layer_dict.keys(): self.net.propagate_to_features(self.feature_bank.value, self.net.dataset.train_inputs[self.control_slider.value], cols=self.feature_columns.value, scale=self.feature_scale.value, html=False) if self.net.config["show_targets"]: if len(self.net.output_bank_order) == 1: ## FIXME: use minmax of output bank self.net.display_component([self.net.dataset.train_targets[self.control_slider.value]], "targets", class_id=self.class_id, minmax=(-1, 1)) else: self.net.display_component(self.net.dataset.train_targets[self.control_slider.value], "targets", class_id=self.class_id, minmax=(-1, 1)) if self.net.config["show_errors"]: ## minmax is error if len(self.net.output_bank_order) == 1: errors = np.array(output) - np.array(self.net.dataset.train_targets[self.control_slider.value]) self.net.display_component([errors.tolist()], "errors", class_id=self.class_id, minmax=(-1, 1)) else: errors = [] for bank in range(len(self.net.output_bank_order)): errors.append( np.array(output[bank]) - np.array(self.net.dataset.train_targets[self.control_slider.value][bank])) self.net.display_component(errors, "errors", class_id=self.class_id, minmax=(-1, 1)) elif self.control_select.value == "Test" and len(self.net.dataset.test_targets) > 0: self.total_text.value = "of %s" % len(self.net.dataset.test_inputs) if self.net.model is None: return if not dynamic_pictures_check(): self.regenerate(inputs=self.net.dataset.test_inputs[self.control_slider.value], targets=self.net.dataset.test_targets[self.control_slider.value]) return output = self.net.propagate(self.net.dataset.test_inputs[self.control_slider.value], class_id=self.class_id, update_pictures=True) if self.feature_bank.value in self.net.layer_dict.keys(): self.net.propagate_to_features(self.feature_bank.value, self.net.dataset.test_inputs[self.control_slider.value], cols=self.feature_columns.value, scale=self.feature_scale.value, html=False) if self.net.config["show_targets"]: ## FIXME: use minmax of output bank self.net.display_component([self.net.dataset.test_targets[self.control_slider.value]], "targets", class_id=self.class_id, minmax=(-1, 1)) if self.net.config["show_errors"]: ## minmax is error if len(self.net.output_bank_order) == 1: errors = np.array(output) - np.array(self.net.dataset.test_targets[self.control_slider.value]) self.net.display_component([errors.tolist()], "errors", class_id=self.class_id, minmax=(-1, 1)) else: errors = [] for bank in range(len(self.net.output_bank_order)): errors.append( np.array(output[bank]) - np.array(self.net.dataset.test_targets[self.control_slider.value][bank])) self.net.display_component(errors, "errors", class_id=self.class_id, minmax=(-1, 1)) def toggle_play(self, button): ## toggle if self.button_play.description == "Play": self.button_play.description = "Stop" self.button_play.icon = "pause" self.player.resume() else: self.button_play.description = "Play" self.button_play.icon = "play" self.player.pause() def prop_one(self, button=None): self.update_slider_control({"name": "value"}) def regenerate(self, button=None, inputs=None, targets=None): ## Protection when deleting object on shutdown: if isinstance(button, dict) and 'new' in button and button['new'] is None: return ## Update the config: self.net.config["dashboard.features.bank"] = self.feature_bank.value self.net.config["dashboard.features.columns"] = self.feature_columns.value self.net.config["dashboard.features.scale"] = self.feature_scale.value inputs = inputs if inputs is not None else self.get_current_input() targets = targets if targets is not None else self.get_current_targets() features = None if self.feature_bank.value in self.net.layer_dict.keys() and inputs is not None: if self.net.model is not None: features = self.net.propagate_to_features(self.feature_bank.value, inputs, cols=self.feature_columns.value, scale=self.feature_scale.value, display=False) svg = """<p style="text-align:center">%s</p>""" % (self.net.to_svg( inputs=inputs, targets=targets, class_id=self.class_id, highlights={self.feature_bank.value: { "border_color": "orange", "border_width": 30, }})) if inputs is not None and features is not None: html_horizontal = """ <table align="center" style="width: 100%%;"> <tr> <td valign="top" style="width: 50%%;">%s</td> <td valign="top" align="center" style="width: 50%%;"><p style="text-align:center"><b>%s</b></p>%s</td> </tr> </table>""" html_vertical = """ <table align="center" style="width: 100%%;"> <tr> <td valign="top">%s</td> </tr> <tr> <td valign="top" align="center"><p style="text-align:center"><b>%s</b></p>%s</td> </tr> </table>""" self.net_svg.value = (html_vertical if self.net.config["svg_rotate"] else html_horizontal) % ( svg, "%s details" % self.feature_bank.value, features) else: self.net_svg.value = svg def make_colormap_image(self, colormap_name): from .layers import Layer if not colormap_name: colormap_name = get_colormap() layer = Layer("Colormap", 100) minmax = layer.get_act_minmax() image = layer.make_image(np.arange(minmax[0], minmax[1], .01), colormap_name, {"pixels_per_unit": 1, "svg_rotate": self.net.config["svg_rotate"]}).resize((300, 25)) return image def set_attr(self, obj, attr, value): if value not in [{}, None]: ## value is None when shutting down if isinstance(value, dict): value = value["value"] if isinstance(obj, dict): obj[attr] = value else: setattr(obj, attr, value) ## was crashing on Widgets.__del__, if get_ipython() no longer existed self.regenerate() def make_controls(self): layout = Layout(width='100%', height="100%") button_begin = Button(icon="fast-backward", layout=layout) button_prev = Button(icon="backward", layout=layout) button_next = Button(icon="forward", layout=layout) button_end = Button(icon="fast-forward", layout=layout) #button_prop = Button(description="Propagate", layout=Layout(width='100%')) #button_train = Button(description="Train", layout=Layout(width='100%')) self.button_play = Button(icon="play", description="Play", layout=layout) step_down = Button(icon="sort-down", layout=Layout(width="95%", height="100%")) step_up = Button(icon="sort-up", layout=Layout(width="95%", height="100%")) up_down = HBox([step_down, step_up], layout=Layout(width="100%", height="100%")) refresh_button = Button(icon="refresh", layout=Layout(width="25%", height="100%")) self.position_text = IntText(value=0, layout=layout) self.control_buttons = HBox([ button_begin, button_prev, #button_train, self.position_text, button_next, button_end, self.button_play, up_down, refresh_button ], layout=Layout(width='100%', height="100%")) length = (len(self.net.dataset.train_inputs) - 1) if len(self.net.dataset.train_inputs) > 0 else 0 self.control_slider = IntSlider(description="Dataset index", continuous_update=False, min=0, max=max(length, 0), value=0, layout=Layout(width='100%')) if self.net.config["dashboard.dataset"] == "Train": length = len(self.net.dataset.train_inputs) else: length = len(self.net.dataset.test_inputs) self.total_text = Label(value="of %s" % length, layout=Layout(width="100px")) self.zoom_slider = FloatSlider(description="Zoom", continuous_update=False, min=0, max=1.0, style={"description_width": 'initial'}, layout=Layout(width="65%"), value=self.net.config["svg_scale"] if self.net.config["svg_scale"] is not None else 0.5) ## Hook them up: button_begin.on_click(lambda button: self.goto("begin")) button_end.on_click(lambda button: self.goto("end")) button_next.on_click(lambda button: self.goto("next")) button_prev.on_click(lambda button: self.goto("prev")) self.button_play.on_click(self.toggle_play) self.control_slider.observe(self.update_slider_control, names='value') refresh_button.on_click(lambda widget: (self.update_control_slider(), self.output.clear_output(), self.regenerate())) step_down.on_click(lambda widget: self.move_step("down")) step_up.on_click(lambda widget: self.move_step("up")) self.zoom_slider.observe(self.update_zoom_slider, names='value') self.position_text.observe(self.update_position_text, names='value') # Put them together: controls = VBox([HBox([self.control_slider, self.total_text], layout=Layout(height="40px")), self.control_buttons], layout=Layout(width='100%')) #net_page = VBox([control, self.net_svg], layout=Layout(width='95%')) controls.on_displayed(lambda widget: self.regenerate()) return controls def move_step(self, direction): """ Move the layer stepper up/down through network """ options = [""] + [layer.name for layer in self.net.layers] index = options.index(self.feature_bank.value) if direction == "up": new_index = (index + 1) % len(options) else: ## down new_index = (index - 1) % len(options) self.feature_bank.value = options[new_index] self.regenerate() def make_config(self): layout = Layout() style = {"description_width": "initial"} checkbox1 = Checkbox(description="Show Targets", value=self.net.config["show_targets"], layout=layout, style=style) checkbox1.observe(lambda change: self.set_attr(self.net.config, "show_targets", change["new"]), names='value') checkbox2 = Checkbox(description="Errors", value=self.net.config["show_errors"], layout=layout, style=style) checkbox2.observe(lambda change: self.set_attr(self.net.config, "show_errors", change["new"]), names='value') hspace = IntText(value=self.net.config["hspace"], description="Horizontal space between banks:", style=style, layout=layout) hspace.observe(lambda change: self.set_attr(self.net.config, "hspace", change["new"]), names='value') vspace = IntText(value=self.net.config["vspace"], description="Vertical space between layers:", style=style, layout=layout) vspace.observe(lambda change: self.set_attr(self.net.config, "vspace", change["new"]), names='value') self.feature_bank = Select(description="Details:", value=self.net.config["dashboard.features.bank"], options=[""] + [layer.name for layer in self.net.layers], rows=1) self.feature_bank.observe(self.regenerate, names='value') self.control_select = Select( options=['Test', 'Train'], value=self.net.config["dashboard.dataset"], description='Dataset:', rows=1 ) self.control_select.observe(self.change_select, names='value') column1 = [self.control_select, self.zoom_slider, hspace, vspace, HBox([checkbox1, checkbox2]), self.feature_bank, self.feature_columns, self.feature_scale ] ## Make layer selectable, and update-able: column2 = [] layer = self.net.layers[-1] self.layer_select = Select(description="Layer:", value=layer.name, options=[layer.name for layer in self.net.layers], rows=1) self.layer_select.observe(self.update_layer_selection, names='value') column2.append(self.layer_select) self.layer_visible_checkbox = Checkbox(description="Visible", value=layer.visible, layout=layout) self.layer_visible_checkbox.observe(self.update_layer, names='value') column2.append(self.layer_visible_checkbox) self.layer_colormap = Select(description="Colormap:", options=[""] + AVAILABLE_COLORMAPS, value=layer.colormap if layer.colormap is not None else "", layout=layout, rows=1) self.layer_colormap_image = HTML(value="""<img src="%s"/>""" % self.net._image_to_uri(self.make_colormap_image(layer.colormap))) self.layer_colormap.observe(self.update_layer, names='value') column2.append(self.layer_colormap) column2.append(self.layer_colormap_image) ## get dynamic minmax; if you change it it will set it in layer as override: minmax = layer.get_act_minmax() self.layer_mindim = FloatText(description="Leftmost color maps to:", value=minmax[0], style=style) self.layer_maxdim = FloatText(description="Rightmost color maps to:", value=minmax[1], style=style) self.layer_mindim.observe(self.update_layer, names='value') self.layer_maxdim.observe(self.update_layer, names='value') column2.append(self.layer_mindim) column2.append(self.layer_maxdim) output_shape = layer.get_output_shape() self.layer_feature = IntText(value=layer.feature, description="Feature to show:", style=style) self.svg_rotate = Checkbox(description="Rotate", value=layer.visible, layout=layout) self.layer_feature.observe(self.update_layer, names='value') column2.append(self.layer_feature) self.svg_rotate = Checkbox(description="Rotate network", value=self.net.config["svg_rotate"], style={"description_width": 'initial'}, layout=Layout(width="52%")) self.svg_rotate.observe(lambda change: self.set_attr(self.net.config, "svg_rotate", change["new"]), names='value') self.save_config_button = Button(icon="save", layout=Layout(width="10%")) self.save_config_button.on_click(self.save_config) column2.append(HBox([self.svg_rotate, self.save_config_button])) config_children = HBox([VBox(column1, layout=Layout(width="100%")), VBox(column2, layout=Layout(width="100%"))]) accordion = Accordion(children=[config_children]) accordion.set_title(0, self.net.name) accordion.selected_index = None return accordion def save_config(self, widget=None): self.net.save_config() def update_layer(self, change): """ Update the layer object, and redisplay. """ if self._ignore_layer_updates: return ## The rest indicates a change to a display variable. ## We need to save the value in the layer, and regenerate ## the display. # Get the layer: layer = self.net[self.layer_select.value] # Save the changed value in the layer: layer.feature = self.layer_feature.value layer.visible = self.layer_visible_checkbox.value ## These three, dealing with colors of activations, ## can be done with a prop_one(): if "color" in change["owner"].description.lower(): ## Matches: Colormap, lefmost color, rightmost color ## overriding dynamic minmax! layer.minmax = (self.layer_mindim.value, self.layer_maxdim.value) layer.minmax = (self.layer_mindim.value, self.layer_maxdim.value) layer.colormap = self.layer_colormap.value if self.layer_colormap.value else None self.layer_colormap_image.value = """<img src="%s"/>""" % self.net._image_to_uri(self.make_colormap_image(layer.colormap)) self.prop_one() else: self.regenerate() def update_layer_selection(self, change): """ Just update the widgets; don't redraw anything. """ ## No need to redisplay anything self._ignore_layer_updates = True ## First, get the new layer selected: layer = self.net[self.layer_select.value] ## Now, let's update all of the values without updating: self.layer_visible_checkbox.value = layer.visible self.layer_colormap.value = layer.colormap if layer.colormap != "" else "" self.layer_colormap_image.value = """<img src="%s"/>""" % self.net._image_to_uri(self.make_colormap_image(layer.colormap)) minmax = layer.get_act_minmax() self.layer_mindim.value = minmax[0] self.layer_maxdim.value = minmax[1] self.layer_feature.value = layer.feature self._ignore_layer_updates = False
def __init__(self): micron_units = Label( 'micron') # use "option m" (Mac, for micro symbol) constWidth = '180px' tab_height = '500px' stepsize = 10 #style = {'description_width': '250px'} style = {'description_width': '25%'} layout = {'width': '400px'} name_button_layout = {'width': '25%'} widget_layout = {'width': '15%'} units_button_layout = {'width': '15%'} desc_button_layout = {'width': '45%'} param_name1 = Button(description='random_seed', disabled=True, layout=name_button_layout) param_name1.style.button_color = 'lightgreen' self.random_seed = IntText(value=0, step=1, style=style, layout=widget_layout) param_name2 = Button(description='cargo_signal_D', disabled=True, layout=name_button_layout) param_name2.style.button_color = 'tan' self.cargo_signal_D = FloatText(value=1e3, step=100, style=style, layout=widget_layout) param_name3 = Button(description='cargo_signal_decay', disabled=True, layout=name_button_layout) param_name3.style.button_color = 'lightgreen' self.cargo_signal_decay = FloatText(value=.4, step=0.1, style=style, layout=widget_layout) param_name4 = Button(description='director_signal_D', disabled=True, layout=name_button_layout) param_name4.style.button_color = 'tan' self.director_signal_D = FloatText(value=1e3, step=100, style=style, layout=widget_layout) param_name5 = Button(description='director_signal_decay', disabled=True, layout=name_button_layout) param_name5.style.button_color = 'lightgreen' self.director_signal_decay = FloatText(value=.1, step=0.01, style=style, layout=widget_layout) param_name6 = Button(description='elastic_coefficient', disabled=True, layout=name_button_layout) param_name6.style.button_color = 'tan' self.elastic_coefficient = FloatText(value=0.05, step=0.01, style=style, layout=widget_layout) param_name7 = Button(description='worker_motility_persistence_time', disabled=True, layout=name_button_layout) param_name7.style.button_color = 'lightgreen' self.worker_motility_persistence_time = FloatText(value=5.0, step=0.1, style=style, layout=widget_layout) param_name8 = Button(description='worker_migration_speed', disabled=True, layout=name_button_layout) param_name8.style.button_color = 'tan' self.worker_migration_speed = FloatText(value=5.0, step=0.1, style=style, layout=widget_layout) param_name9 = Button(description='attached_worker_migration_bias', disabled=True, layout=name_button_layout) param_name9.style.button_color = 'lightgreen' self.attached_worker_migration_bias = FloatText(value=1.0, step=0.1, style=style, layout=widget_layout) param_name10 = Button(description='unattached_worker_migration_bias', disabled=True, layout=name_button_layout) param_name10.style.button_color = 'tan' self.unattached_worker_migration_bias = FloatText(value=0.5, step=0.1, style=style, layout=widget_layout) param_name11 = Button(description='number_of_directors', disabled=True, layout=name_button_layout) param_name11.style.button_color = 'lightgreen' self.number_of_directors = IntText(value=15, step=1, style=style, layout=widget_layout) param_name12 = Button(description='number_of_cargo_clusters', disabled=True, layout=name_button_layout) param_name12.style.button_color = 'tan' self.number_of_cargo_clusters = IntText(value=100, step=10, style=style, layout=widget_layout) param_name13 = Button(description='number_of_workers', disabled=True, layout=name_button_layout) param_name13.style.button_color = 'lightgreen' self.number_of_workers = IntText(value=50, step=1, style=style, layout=widget_layout) param_name14 = Button(description='drop_threshold', disabled=True, layout=name_button_layout) param_name14.style.button_color = 'tan' self.drop_threshold = FloatText(value=0.4, step=0.1, style=style, layout=widget_layout) param_name15 = Button(description='worker_color', disabled=True, layout=name_button_layout) param_name15.style.button_color = 'lightgreen' self.worker_color = Text(value='red', style=style, layout=widget_layout) param_name16 = Button(description='cargo_color', disabled=True, layout=name_button_layout) param_name16.style.button_color = 'tan' self.cargo_color = Text(value='blue', style=style, layout=widget_layout) param_name17 = Button(description='director_color', disabled=True, layout=name_button_layout) param_name17.style.button_color = 'lightgreen' self.director_color = Text(value='limegreen', style=style, layout=widget_layout) units_button1 = Button(description='', disabled=True, layout=units_button_layout) units_button1.style.button_color = 'lightgreen' units_button2 = Button(description='micron/min^2', disabled=True, layout=units_button_layout) units_button2.style.button_color = 'tan' units_button3 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button3.style.button_color = 'lightgreen' units_button4 = Button(description='micron/min^2', disabled=True, layout=units_button_layout) units_button4.style.button_color = 'tan' units_button5 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button5.style.button_color = 'lightgreen' units_button6 = Button(description='1/min', disabled=True, layout=units_button_layout) units_button6.style.button_color = 'tan' units_button7 = Button(description='min', disabled=True, layout=units_button_layout) units_button7.style.button_color = 'lightgreen' units_button8 = Button(description='micron/min', disabled=True, layout=units_button_layout) units_button8.style.button_color = 'tan' units_button9 = Button(description='', disabled=True, layout=units_button_layout) units_button9.style.button_color = 'lightgreen' units_button10 = Button(description='', disabled=True, layout=units_button_layout) units_button10.style.button_color = 'tan' units_button11 = Button(description='', disabled=True, layout=units_button_layout) units_button11.style.button_color = 'lightgreen' units_button12 = Button(description='', disabled=True, layout=units_button_layout) units_button12.style.button_color = 'tan' units_button13 = Button(description='', disabled=True, layout=units_button_layout) units_button13.style.button_color = 'lightgreen' units_button14 = Button(description='', disabled=True, layout=units_button_layout) units_button14.style.button_color = 'tan' units_button15 = Button(description='', disabled=True, layout=units_button_layout) units_button15.style.button_color = 'lightgreen' units_button16 = Button(description='', disabled=True, layout=units_button_layout) units_button16.style.button_color = 'tan' units_button17 = Button(description='', disabled=True, layout=units_button_layout) units_button17.style.button_color = 'lightgreen' desc_button1 = Button(description='', disabled=True, layout=desc_button_layout) desc_button1.style.button_color = 'lightgreen' desc_button2 = Button(description='', disabled=True, layout=desc_button_layout) desc_button2.style.button_color = 'tan' desc_button3 = Button(description='', disabled=True, layout=desc_button_layout) desc_button3.style.button_color = 'lightgreen' desc_button4 = Button(description='', disabled=True, layout=desc_button_layout) desc_button4.style.button_color = 'tan' desc_button5 = Button(description='', disabled=True, layout=desc_button_layout) desc_button5.style.button_color = 'lightgreen' desc_button6 = Button(description='', disabled=True, layout=desc_button_layout) desc_button6.style.button_color = 'tan' desc_button7 = Button(description='', disabled=True, layout=desc_button_layout) desc_button7.style.button_color = 'lightgreen' desc_button8 = Button(description='', disabled=True, layout=desc_button_layout) desc_button8.style.button_color = 'tan' desc_button9 = Button(description='', disabled=True, layout=desc_button_layout) desc_button9.style.button_color = 'lightgreen' desc_button10 = Button(description='', disabled=True, layout=desc_button_layout) desc_button10.style.button_color = 'tan' desc_button11 = Button(description='', disabled=True, layout=desc_button_layout) desc_button11.style.button_color = 'lightgreen' desc_button12 = Button(description='', disabled=True, layout=desc_button_layout) desc_button12.style.button_color = 'tan' desc_button13 = Button(description='', disabled=True, layout=desc_button_layout) desc_button13.style.button_color = 'lightgreen' desc_button14 = Button(description='', disabled=True, layout=desc_button_layout) desc_button14.style.button_color = 'tan' desc_button15 = Button(description='', disabled=True, layout=desc_button_layout) desc_button15.style.button_color = 'lightgreen' desc_button16 = Button(description='', disabled=True, layout=desc_button_layout) desc_button16.style.button_color = 'tan' desc_button17 = Button(description='', disabled=True, layout=desc_button_layout) desc_button17.style.button_color = 'lightgreen' row1 = [param_name1, self.random_seed, units_button1, desc_button1] row2 = [param_name2, self.cargo_signal_D, units_button2, desc_button2] row3 = [ param_name3, self.cargo_signal_decay, units_button3, desc_button3 ] row4 = [ param_name4, self.director_signal_D, units_button4, desc_button4 ] row5 = [ param_name5, self.director_signal_decay, units_button5, desc_button5 ] row6 = [ param_name6, self.elastic_coefficient, units_button6, desc_button6 ] row7 = [ param_name7, self.worker_motility_persistence_time, units_button7, desc_button7 ] row8 = [ param_name8, self.worker_migration_speed, units_button8, desc_button8 ] row9 = [ param_name9, self.attached_worker_migration_bias, units_button9, desc_button9 ] row10 = [ param_name10, self.unattached_worker_migration_bias, units_button10, desc_button10 ] row11 = [ param_name11, self.number_of_directors, units_button11, desc_button11 ] row12 = [ param_name12, self.number_of_cargo_clusters, units_button12, desc_button12 ] row13 = [ param_name13, self.number_of_workers, units_button13, desc_button13 ] row14 = [ param_name14, self.drop_threshold, units_button14, desc_button14 ] row15 = [ param_name15, self.worker_color, units_button15, desc_button15 ] row16 = [param_name16, self.cargo_color, units_button16, desc_button16] row17 = [ param_name17, self.director_color, units_button17, desc_button17 ] box_layout = Layout(display='flex', flex_flow='row', align_items='stretch', width='100%') box1 = Box(children=row1, layout=box_layout) box2 = Box(children=row2, layout=box_layout) box3 = Box(children=row3, layout=box_layout) box4 = Box(children=row4, layout=box_layout) box5 = Box(children=row5, layout=box_layout) box6 = Box(children=row6, layout=box_layout) box7 = Box(children=row7, layout=box_layout) box8 = Box(children=row8, layout=box_layout) box9 = Box(children=row9, layout=box_layout) box10 = Box(children=row10, layout=box_layout) box11 = Box(children=row11, layout=box_layout) box12 = Box(children=row12, layout=box_layout) box13 = Box(children=row13, layout=box_layout) box14 = Box(children=row14, layout=box_layout) box15 = Box(children=row15, layout=box_layout) box16 = Box(children=row16, layout=box_layout) box17 = Box(children=row17, layout=box_layout) self.tab = VBox([ box1, box2, box3, box4, box5, box6, box7, box8, box9, box10, box11, box12, box13, box14, box15, box16, box17, ])
def make_controls(self): layout = Layout(width='100%', height="100%") button_begin = Button(icon="fast-backward", layout=layout) button_prev = Button(icon="backward", layout=layout) button_next = Button(icon="forward", layout=layout) button_end = Button(icon="fast-forward", layout=layout) #button_prop = Button(description="Propagate", layout=Layout(width='100%')) #button_train = Button(description="Train", layout=Layout(width='100%')) self.button_play = Button(icon="play", description="Play", layout=layout) step_down = Button(icon="sort-down", layout=Layout(width="95%", height="100%")) step_up = Button(icon="sort-up", layout=Layout(width="95%", height="100%")) up_down = HBox([step_down, step_up], layout=Layout(width="100%", height="100%")) refresh_button = Button(icon="refresh", layout=Layout(width="25%", height="100%")) self.position_text = IntText(value=0, layout=layout) self.control_buttons = HBox([ button_begin, button_prev, #button_train, self.position_text, button_next, button_end, self.button_play, up_down, refresh_button ], layout=Layout(width='100%', height="100%")) length = (len(self.net.dataset.train_inputs) - 1) if len(self.net.dataset.train_inputs) > 0 else 0 self.control_slider = IntSlider(description="Dataset index", continuous_update=False, min=0, max=max(length, 0), value=0, layout=Layout(width='100%')) if self.net.config["dashboard.dataset"] == "Train": length = len(self.net.dataset.train_inputs) else: length = len(self.net.dataset.test_inputs) self.total_text = Label(value="of %s" % length, layout=Layout(width="100px")) self.zoom_slider = FloatSlider(description="Zoom", continuous_update=False, min=0, max=1.0, style={"description_width": 'initial'}, layout=Layout(width="65%"), value=self.net.config["svg_scale"] if self.net.config["svg_scale"] is not None else 0.5) ## Hook them up: button_begin.on_click(lambda button: self.goto("begin")) button_end.on_click(lambda button: self.goto("end")) button_next.on_click(lambda button: self.goto("next")) button_prev.on_click(lambda button: self.goto("prev")) self.button_play.on_click(self.toggle_play) self.control_slider.observe(self.update_slider_control, names='value') refresh_button.on_click(lambda widget: (self.update_control_slider(), self.output.clear_output(), self.regenerate())) step_down.on_click(lambda widget: self.move_step("down")) step_up.on_click(lambda widget: self.move_step("up")) self.zoom_slider.observe(self.update_zoom_slider, names='value') self.position_text.observe(self.update_position_text, names='value') # Put them together: controls = VBox([HBox([self.control_slider, self.total_text], layout=Layout(height="40px")), self.control_buttons], layout=Layout(width='100%')) #net_page = VBox([control, self.net_svg], layout=Layout(width='95%')) controls.on_displayed(lambda widget: self.regenerate()) return controls
def make_config(self): layout = Layout() style = {"description_width": "initial"} checkbox1 = Checkbox(description="Show Targets", value=self.net.config["show_targets"], layout=layout, style=style) checkbox1.observe(lambda change: self.set_attr(self.net.config, "show_targets", change["new"]), names='value') checkbox2 = Checkbox(description="Errors", value=self.net.config["show_errors"], layout=layout, style=style) checkbox2.observe(lambda change: self.set_attr(self.net.config, "show_errors", change["new"]), names='value') hspace = IntText(value=self.net.config["hspace"], description="Horizontal space between banks:", style=style, layout=layout) hspace.observe(lambda change: self.set_attr(self.net.config, "hspace", change["new"]), names='value') vspace = IntText(value=self.net.config["vspace"], description="Vertical space between layers:", style=style, layout=layout) vspace.observe(lambda change: self.set_attr(self.net.config, "vspace", change["new"]), names='value') self.feature_bank = Select(description="Details:", value=self.net.config["dashboard.features.bank"], options=[""] + [layer.name for layer in self.net.layers], rows=1) self.feature_bank.observe(self.regenerate, names='value') self.control_select = Select( options=['Test', 'Train'], value=self.net.config["dashboard.dataset"], description='Dataset:', rows=1 ) self.control_select.observe(self.change_select, names='value') column1 = [self.control_select, self.zoom_slider, hspace, vspace, HBox([checkbox1, checkbox2]), self.feature_bank, self.feature_columns, self.feature_scale ] ## Make layer selectable, and update-able: column2 = [] layer = self.net.layers[-1] self.layer_select = Select(description="Layer:", value=layer.name, options=[layer.name for layer in self.net.layers], rows=1) self.layer_select.observe(self.update_layer_selection, names='value') column2.append(self.layer_select) self.layer_visible_checkbox = Checkbox(description="Visible", value=layer.visible, layout=layout) self.layer_visible_checkbox.observe(self.update_layer, names='value') column2.append(self.layer_visible_checkbox) self.layer_colormap = Select(description="Colormap:", options=[""] + AVAILABLE_COLORMAPS, value=layer.colormap if layer.colormap is not None else "", layout=layout, rows=1) self.layer_colormap_image = HTML(value="""<img src="%s"/>""" % self.net._image_to_uri(self.make_colormap_image(layer.colormap))) self.layer_colormap.observe(self.update_layer, names='value') column2.append(self.layer_colormap) column2.append(self.layer_colormap_image) ## get dynamic minmax; if you change it it will set it in layer as override: minmax = layer.get_act_minmax() self.layer_mindim = FloatText(description="Leftmost color maps to:", value=minmax[0], style=style) self.layer_maxdim = FloatText(description="Rightmost color maps to:", value=minmax[1], style=style) self.layer_mindim.observe(self.update_layer, names='value') self.layer_maxdim.observe(self.update_layer, names='value') column2.append(self.layer_mindim) column2.append(self.layer_maxdim) output_shape = layer.get_output_shape() self.layer_feature = IntText(value=layer.feature, description="Feature to show:", style=style) self.svg_rotate = Checkbox(description="Rotate", value=layer.visible, layout=layout) self.layer_feature.observe(self.update_layer, names='value') column2.append(self.layer_feature) self.svg_rotate = Checkbox(description="Rotate network", value=self.net.config["svg_rotate"], style={"description_width": 'initial'}, layout=Layout(width="52%")) self.svg_rotate.observe(lambda change: self.set_attr(self.net.config, "svg_rotate", change["new"]), names='value') self.save_config_button = Button(icon="save", layout=Layout(width="10%")) self.save_config_button.on_click(self.save_config) column2.append(HBox([self.svg_rotate, self.save_config_button])) config_children = HBox([VBox(column1, layout=Layout(width="100%")), VBox(column2, layout=Layout(width="100%"))]) accordion = Accordion(children=[config_children]) accordion.set_title(0, self.net.name) accordion.selected_index = None return accordion
def __init__(self): micron_units = Label( 'micron') # use "option m" (Mac, for micro symbol) constWidth = '180px' tab_height = '500px' stepsize = 10 style = {'description_width': '250px'} layout = {'width': '400px'} self.resource_D = FloatText(description='resource_D', value=100000, step=10000, style=style, layout=layout) self.resource_lambda = FloatText(description='resource_lambda', value=0.1, step=0.01, style=style, layout=layout) self.quorum_D = FloatText(description='quorum_D', value=100000, step=10000, style=style, layout=layout) self.quorum_lambda = FloatText(description='quorum_lambda', value=10, step=1, style=style, layout=layout) self.death_signal_D = FloatText(description='death_signal_D', value=40000, step=1000, style=style, layout=layout) self.death_signal_lambda = FloatText(description='death_signal_lambda', value=1, step=0.1, style=style, layout=layout) self.signal_D = FloatText(description='signal_D', value=25000, step=1000, style=style, layout=layout) self.signal_lambda = FloatText(description='signal_lambda', value=.1, step=0.01, style=style, layout=layout) self.poison_D = FloatText(description='poison_D', value=50000, step=1000, style=style, layout=layout) self.poison_lambda = FloatText(description='poison_lambda', value=20, step=1, style=style, layout=layout) self.number_of_invaders = IntText(description='number_of_invaders', value=15, step=1, style=style, layout=layout) self.number_of_suppliers = IntText(description='number_of_suppliers', value=50, step=1, style=style, layout=layout) self.number_of_scouts = IntText(description='number_of_scouts', value=10, step=1, style=style, layout=layout) self.number_of_attackers = IntText(description='number_of_attackers', value=50, step=1, style=style, layout=layout) self.invader_max_birth_rate = FloatText( description='invader_max_birth_rate', value=0.0028, step=0.0001, style=style, layout=layout) self.invader_max_death_rate = FloatText( description='invader_max_death_rate', value=0.001, step=0.0001, style=style, layout=layout) self.invader_persistence_time = FloatText( description='invader_persistence_time', value=15, step=1, style=style, layout=layout) self.invader_migration_speed = FloatText( description='invader_migration_speed', value=0.25, step=0.01, style=style, layout=layout) self.invader_migration_bias = FloatText( description='invader_migration_bias', value=0.5, step=0.1, style=style, layout=layout) self.invader_secretion_rate = FloatText( description='invader_secretion_rate', value=100, step=10, style=style, layout=layout) self.invader_quorum_weight = FloatText( description='invader_quorum_weight', value=.1, step=0.01, style=style, layout=layout) self.scout_persistence_time = FloatText( description='scout_persistence_time', value=15, step=1, style=style, layout=layout) self.scout_migration_speed = FloatText( description='scout_migration_speed', value=.5, step=0.1, style=style, layout=layout) self.scout_migration_bias = FloatText( description='scout_migration_bias', value=0.125, step=0.01, style=style, layout=layout) self.scout_secretion_rate = FloatText( description='scout_secretion_rate', value=100, step=10, style=style, layout=layout) self.scout_signal_threshold = FloatText( description='scout_signal_threshold', value=0.1, step=0.01, style=style, layout=layout) self.attacker_max_birth_rate = FloatText( description='attacker_max_birth_rate', value=0.0005, step=0.0001, style=style, layout=layout) self.attacker_max_death_rate = FloatText( description='attacker_max_death_rate', value=0.0001, step=1e-05, style=style, layout=layout) self.attacker_persistence_time = FloatText( description='attacker_persistence_time', value=15, step=1, style=style, layout=layout) self.attacker_migration_speed = FloatText( description='attacker_migration_speed', value=1, step=0.1, style=style, layout=layout) self.attacker_migration_bias = FloatText( description='attacker_migration_bias', value=0.25, step=0.01, style=style, layout=layout) self.attacker_secretion_rate = FloatText( description='attacker_secretion_rate', value=100, step=10, style=style, layout=layout) self.attacker_signal_threshold = FloatText( description='attacker_signal_threshold', value=0.1, step=0.01, style=style, layout=layout) self.supplier_secretion_rate = FloatText( description='supplier_secretion_rate', value=100, step=10, style=style, layout=layout) self.tab = VBox([ HBox([ self.resource_D, Label('micron^2/min (resource diffusion coefficient)') ]), HBox([self.resource_lambda, Label('1/min (resource decay rate)')]), HBox([ self.quorum_D, Label('micron^2/min (quorum diffusion coefficient)') ]), HBox([self.quorum_lambda, Label('1/min (quorum decay rate)')]), HBox([ self.death_signal_D, Label('micron^2/min (death signal diffusion coefficient)') ]), HBox([ self.death_signal_lambda, Label('1/min (death signal decay rate)') ]), HBox([ self.signal_D, Label('micron^2/min (attack signal diffusion coefficient)') ]), HBox([ self.signal_lambda, Label('1/min (attack signal decay rate)') ]), HBox([ self.poison_D, Label('micron^2/min (poison diffusion coefficient)') ]), HBox([self.poison_lambda, Label('1/min (poison decay rate)')]), HBox([ self.number_of_invaders, Label(' (number of randomly placed invaders)') ]), HBox([ self.number_of_suppliers, Label(' (number of randomly placed suppliers)') ]), HBox([ self.number_of_scouts, Label(' (number of randomly placed scouts)') ]), HBox([ self.number_of_attackers, Label(' (number of randomly placed attackers)') ]), HBox([ self.invader_max_birth_rate, Label('1/min (max birth rate for invaders)') ]), HBox([ self.invader_max_death_rate, Label('1/min (max death rate for invaders)') ]), HBox([ self.invader_persistence_time, Label('min (persistence time for invader migration)') ]), HBox([ self.invader_migration_speed, Label('micron/min (speed of invader cells)') ]), HBox([ self.invader_migration_bias, Label(' (invader migration bias)') ]), HBox([ self.invader_secretion_rate, Label('1/min (rate invaders secrete their signals)') ]), HBox([ self.invader_quorum_weight, Label(' (motile direction = w*grad(Q) - (1-w)*grad(D))') ]), HBox([ self.scout_persistence_time, Label('min (persistence time for scout migration)') ]), HBox([ self.scout_migration_speed, Label('micron/min (speed of scout cells)') ]), HBox([self.scout_migration_bias, Label(' (scout migration bias)')]), HBox([ self.scout_secretion_rate, Label('1/min (rate scouts secrete their signals)') ]), HBox([ self.scout_signal_threshold, Label(' (scouts release S if Q > threshold)') ]), HBox([ self.attacker_max_birth_rate, Label('1/min (max birth rate for attackers)') ]), HBox([ self.attacker_max_death_rate, Label('1/min (max death rate for attackers)') ]), HBox([ self.attacker_persistence_time, Label('min (persistence time for attacker migration)') ]), HBox([ self.attacker_migration_speed, Label('micron/min (speed of attacker cells)') ]), HBox([ self.attacker_migration_bias, Label(' (attacker migration bias)') ]), HBox([ self.attacker_secretion_rate, Label('1/min (rate attackers secrete their signals)') ]), HBox([ self.attacker_signal_threshold, Label(' (attackers release P if S > threshold)') ]), HBox([ self.supplier_secretion_rate, Label('1/min (rate suppliers release resource)') ]), ])