def show_param(self, model, module_name, param_name, model2, uid2): if model2 is not None: layers = dict(list_layers(model2)) layer = layers[module_name] params = dict(layer.named_parameters()) param2 = params[param_name] layers = dict(list_layers(model)) layer = layers[module_name] params = dict(layer.named_parameters()) param = params[param_name] if model2 is not None: param = param - param2 title = param_name if model2 is not None: title = f'{param_name} - {uid2}' return html.div_row( html.div_col( html.header(f'Module {module_name}', level=4), html.pre(str(layer)), html.header('Parameters', level=4), html.ul([ self.parameter_link(k, v, uid2) for k, v in params.items() ])), html.div_col(html.header(title, level=4), self.vizualize_param(param)))
def parameter_selection(self, model, module_name): layers = dict(list_layers(model)) layer = layers[module_name] params = layer.named_parameters() return html.div_row( html.div_col(html.header(f'Module {module_name}', level=4), html.pre(str(layer)), html.header('Parameters', level=4), html.ul( [self.parameter_link(k, v) for k, v in params]), style="height: 100vh;"), html.div_col())
def show_overview(self, queue, group=None, delimiter=None): # Try to show an overview of the entire system if self.aggregate is None: try: self.aggregate = self.client.aggregate_monitor() except Exception as e: print(e) return self.list_namespaces(queue) data = defaultdict(lambda: dict(unread=0, unactioned=0, actioned=0, lost=0, failed=0, agent=0, runtime=0)) insert(data, self.aggregate.unread_count(queue, group, delimiter=delimiter), 'unread') insert(data, self.aggregate.unactioned_count(queue, group, delimiter=delimiter), 'unactioned') insert(data, self.aggregate.actioned_count(queue, group, delimiter=delimiter), 'actioned') insert(data, self.aggregate.lost_count(queue, group, delimiter=delimiter), 'lost') insert(data, self.aggregate.failed_count(queue, group, delimiter=delimiter), 'failed') for group, info in data.items(): print(group, info) name = 'experiment' if delimiter is not None: name = 'study' status, agents = prepare_overview_altair(data) chart = aggregate_overview_altair(status, name) return html.div( html.header('Status', level=3), html.div_row( html.div_col(html.altair_plot(chart), style='height:100vh;', size=5), html.div_col(list_experiment_stats(self.base_path, queue, data.keys(), data, nolink=delimiter is not None)) ) )
def show_namespace(self, name, status, agents): fig = work_status(status) fig.update_layout(template='plotly_dark') return html.div( html.header(f'{name} {agents}', level=5), html.div_col(html.plotly_plot(fig), size=4))
def show_queue(self, queue, namespace, delimiter=None): args = (queue, namespace) if delimiter: args += delimiter, messages = self.client.messages(*args) return html.div(html.header('/'.join([queue, namespace]), level=4), html.show_messages(messages))
def show_state(self, uid): if self.meta is None: self.meta = self.storage.meta.load(self.storage.folder) meta_uid = uid.split('_')[-1] meta = self.meta.get(meta_uid, dict()) state = self.storage.load(uid) display = self.generic_display(uid, state) return html.div( html.header(f'State {uid}', level=4), html.header('Meta', level=5), html.pre(json.dumps(meta, indent=2)), html.header('State', level=5), display )
def main(self): routes = [ html.link(html.chain(html.span(name), ':', html.code(spec)), spec) for spec, name in self.dash.routes ] page = self.env.get_template('routes.html') return page.render(routes=html.div(html.header('Routes', level=4), html.ul(routes)), state=self.app.state)
def module_selection(self, model: nn.Module, uid, keys): layers = [] for k, v in list_layers(model): layers.append(' '.join( [html.link(k, self.module_subroute(k)), html.code(type(v))])) return html.div( html.header( f'Modules of {html.code(".".join(keys))} in {html.code(uid)}', level=4), html.ol(layers))
def show_queue(self, queue, namespace): # unread_messages = self.client.unread_messages(queue, namespace) # unactioned = self.client.unactioned_messages(queue, namespace) unread = self.client.unread_count(queue, namespace) unactioned = self.client.unactioned_count(queue, namespace) finished = self.client.actioned_count(queue, namespace) lost = self.client.lost_messages(queue, namespace) failed = self.client.failed_messages(queue, namespace) agents = self.get_unique_agents(queue, namespace) data = { 'pending': unread, 'running': unactioned, 'finished': finished, 'lost': len(lost), 'failed': len(failed) } fig = work_status(data) fig.update_layout(template='plotly_dark') return html.div( html.header(f'Status', level=3), html.div_row( html.div_col( html.header('Tasks', level=5), html.plotly_plot(fig), size=4), html.div_col( html.header('Agents', level=5), html.show_agent(agents))), html.div_row( html.div_col( html.header('Lost', level=5), html.show_messages(lost[:10])), html.div_col( html.header('Failed', level=5), html.show_messages(failed[:10]))))
def main(self, experiment=None, section=None): if experiment is None: return self.list_namespaces() # call the section render function section_html = self.sections.get(section, self.no_section)(experiment, section) return html.div_col(html.header(experiment), html.div_row( self.sidebar(experiment), html.div_col(section_html, classes='col py-2')), classes="container-fluid")
def select_study(self): def redirect_on_enter(data): if not data: return self.prefix = data redirect(f'/{self.base_path}/{data}') bind('study_prefix', 'change', redirect_on_enter, property='value') return html.div( html.header('Study prefix', level=5), 'A study is a group of experiment, experiment belonging to the same study should' 'start with the same name for example <code>mystudy_exp1</code>, <code>my_study_exp2</code>', html.text_input(id='study_prefix', placeholder='Study prefix'))
def main(self, study=None, section=None): if study is None: return self.select_study() self.title = f'Study {study.capitalize()}' section_html = self.sections.get(section, self.no_section)(study, section) return html.div_col(html.header(f'Study: {study.capitalize()}'), html.div_row( self.sidebar(study), html.div_col(section_html, classes='col py-2')), classes="container-fluid")
def show_key(self, uid, *keys): if self.meta is None: self.meta = self.storage.meta.load(self.storage.folder) state = self.storage.load(uid) for k in keys: t = state.get(k, dict()) if isinstance(t, dict): state = t else: break display = self.generic_display(uid, state, keys) return html.div( html.header(f'State {uid}/{"/".join(keys)}', level=4), display )
def list_namespaces(self, queue): return html.div( html.header(queue, level=4), html.ul( html.link(n, f'/{self.base_path}/{queue}/{n}') for n in self.client.namespaces(queue)))
def show_queue(self, namespace, agent_id, ltype): log = self.client.log(agent_id, ltype=ltype) return html.div( html.header(f'Logs for agent {agent_id[:8]}'), html.pre(log))
def list_agents(self, queue, namespace): return html.div( html.header('Agents', level=4), html.ul( html.link(q, f'/{self.base_path}/{queue}/{namespace}/{q.uid}') for q in self.client.agents(namespace)))
def list_namespaces(self, queue=WORK_QUEUE): return html.div( html.header('Experiments', level=4), html.ul( html.link(n, f'/{self.base_path}/{n}') for n in self.client.namespaces(queue)))
def main(self): routes = [ html.link(html.chain(html.span(name), ':', html.code(spec)), spec) for spec, name in self.dash.routes ] return html.div(html.header('Routes', level=4), html.ul(routes))