def test_stdout_unused_resources_list(breakdown_for_unused_resources_list): # Arrange console = FakeConsole() reporter = StdoutReporter(console) # Act reporter.report_unused_resources_list(breakdown_for_unused_resources_list) # Assert expected_table = Table(show_header=True, header_style="bold magenta") expected_table.pad_edge = True expected_table.add_column(HEADER_RESOURCE_NAME) expected_table.add_column(HEADER_RESOURCE_LOCATION) expected_table.add_column(HEADER_RESOURCE_SIZE) expected_table.add_row( *["R.drawable.name1", "path/to/name1.xml", "1.95 kb"]) expected_table.add_row( *["R.drawable.name3", "path/to/name3.xml", "0.01 kb"]) expected_table.add_row( *["R.color.color1", "path/to/color1.xml", "0.00 kb"]) expected_table.add_row( *["R.color.color_selector", "path/to/color_selector.xml", "0.01 kb"]) expected_table.add_row(*["R.anim.anim1", "path/to/anim1.xml", "0.02 kb"]) expected_stdout = [ "\n[bold green]Unused Resources List[/bold green]", expected_table, ] assert console.calls[0] == expected_stdout[0] assert console.calls[1].columns == expected_stdout[1].columns assert console.calls[1].rows == expected_stdout[1].rows
def test_stdout_report_usage_breakdown(breakdown_for_usage): # Arrange console = FakeConsole() reporter = StdoutReporter(console) # Act reporter.report(breakdown_for_usage) # Assert expected_table = Table(show_header=True, header_style="bold magenta") expected_table.pad_edge = True expected_table.add_column(HEADER_RESOURCE_TYPE) expected_table.add_column(HEADER_NUM_USED_RESOURCES) expected_table.add_column(HEADER_NUM_UNUSED_RESOURCES) expected_table.add_row(*["anim", "0", "1"]) expected_table.add_row(*["color", "1", "0"]) expected_table.add_row(*["dimen", "0", "0"]) expected_table.add_row(*["drawable", "3", "2"]) expected_table.add_row(*["raw", "0", "0"]) expected_table.add_row(*["string", "0", "0"]) expected_table.add_row(*["style", "0", "0"]) expected_stdout = [ "\n[bold green]Resources Usage[/bold green]", expected_table ] assert console.calls[0] == expected_stdout[0] assert console.calls[1].columns == expected_stdout[1].columns assert console.calls[1].rows == expected_stdout[1].rows
def weights(self): r""" Prints an weights to screen. """ console = bittensor.__console__ subtensor = bittensor.subtensor( config = self.config ) metagraph = bittensor.metagraph( subtensor = subtensor ) wallet = bittensor.wallet( config = self.config ) with console.status(":satellite: Syncing with chain: [white]{}[/white] ...".format(self.config.subtensor.network)): metagraph.load() metagraph.sync() metagraph.save() table = Table() rows = [] table.add_column("[bold white]uid", style='white', no_wrap=False) for uid in metagraph.uids.tolist(): table.add_column("[bold white]{}".format(uid), style='white', no_wrap=False) if self.config.all_weights: rows.append(["[bold white]{}".format(uid) ] + ['{:.3f}'.format(v) for v in metagraph.W[uid].tolist()]) else: if metagraph.coldkeys[uid] == wallet.coldkeypub.ss58_address: if not self.config.all_hotkeys: if metagraph.hotkeys[uid] == wallet.hotkey.ss58_address: rows.append(["[bold white]{}".format(uid) ] + ['{:.3f}'.format(v) for v in metagraph.W[uid].tolist()]) else: rows.append(["[bold white]{}".format(uid) ] + ['{:.3f}'.format(v) for v in metagraph.W[uid].tolist()]) for row in rows: table.add_row(*row) table.box = None table.pad_edge = False table.width = None with console.pager(): console.print(table)
def report_unused_resources_list(self, breakdown): printer = self.console printer.print("\n[bold green]Unused Resources List[/bold green]") table = Table(show_header=True, header_style="bold magenta") table.pad_edge = False content = self._resources_unused_resources_report_content(breakdown) for header in content[0]: table.add_column(header) for row in content[1:]: table.add_row(*row) printer.print(table)
def report_breakdown(self, breakdown): printer = self.console printer.print(f"\n[bold green]{breakdown.name}[/bold green]") table = Table(show_header=True, header_style="bold magenta") table.pad_edge = False table.add_column("Name") table.add_column("Builds", justify="right") if self.detailed_builds: table.add_column("Successes", justify="right") table.add_column("Failures", justify="right") table.add_column("Abortions", justify="right") table.add_column("Total time", justify="right") if self.detailed_timing: table.add_column("Queued time", justify="right") table.add_column("Building time", justify="right") if self.emulate_velocity: table.add_column("Credits Estimation", justify="right") sorted_by_total = sorted(breakdown.details.items(), key=lambda kv: kv[1].count, reverse=True) for entry, value in sorted_by_total: rows = [entry.id, f"[bold cyan]{value.count}[/bold cyan]"] if self.detailed_builds: rows.append(f"{value.successes}") rows.append(f"{value.failures}") rows.append(f"{value.abortions}") rows.append(f"[bold cyan]{value.total}[/bold cyan]") if self.detailed_timing: rows.append(f"{value.queued}") rows.append(f"{value.building}") if self.emulate_velocity: rows.append(f"{value.credits}") table.add_row(*rows) printer.print(table)
def format_results(analysis): results = Table(show_header=True, header_style="bold magenta") results.pad_edge = False results.add_column("Metric") results.add_column("Assigned value", justify="right") details = analysis.details results.add_row("Significance", format(details.significance_level, ".3f")) formatted_pvalue = format(details.pvalue, ".3f") if details.pvalue == 0.0: formatted_pvalue = f"~ {formatted_pvalue}" results.add_row("p-value", formatted_pvalue) return results
def format_benchmarks(analysis): h0 = analysis.baseline h1 = analysis.modified benchmarks = Table(show_header=True, header_style="bold magenta") benchmarks.pad_edge = False benchmarks.add_column("Benchmark") benchmarks.add_column("Measured builds", justify="right") benchmarks.add_column("Mean", justify="right") benchmarks.add_column("Standard Deviation", justify="right") benchmarks.add_row("baseline (h0)", f"{len(h0.builds)}", format(h0.mean, ".2f"), format(h0.stddev, ".2f")) benchmarks.add_row("modified (h1)", f"{len(h1.builds)}", format(h1.mean, ".2f"), format(h1.stddev, ".2f")) return benchmarks
table.border_style = "bright_yellow" with beat(10): console.print(table, justify="center") for box in [ box.SQUARE, box.MINIMAL, box.SIMPLE, box.SIMPLE_HEAD, ]: table.box = box with beat(10): console.print(table, justify="center") table.pad_edge = False with beat(10): console.print(table, justify="center") original_width = Measurement.get(console, table).maximum for width in range(original_width, console.width, 2): table.width = width with beat(2): console.print(table, justify="center") for width in range(console.width, original_width, -2): table.width = width with beat(2): console.print(table, justify="center")
def generate_table(): nonlocal config nonlocal manager nonlocal subtensor nonlocal dendrite nonlocal meta total_stake = 0.0 total_incentive = 0.0 total_rank = 0.0 total_success = 0 total_time = 0.0 # Fill row. def get_row(droplet): nonlocal total_stake nonlocal total_incentive nonlocal total_rank nonlocal total_time nonlocal total_success nonlocal config if droplet.name not in config.names: return # Setup asyncio loop. connection = connection_for_droplet(droplet) # Get connection string can_connect_bool = can_connect(connection) connect_str = '[bold green] YES' if can_connect( connection) else '[bold red] NO' # get hotkey if can_connect_bool: try: hotkey = get_hotkey(connection) hotkey_str = hotkey if hotkey != None else '[yellow] None' except Exception as e: hotkey_str = '[yellow] None' logger.error('{}: Failed to pull hotkey error = {}', droplet.name, e) else: hotkey_str = '[yellow] None' # get coldkey if can_connect_bool: try: coldkeypub = get_coldkeypub(connection) coldkeypub_str = coldkeypub if coldkeypub != None else '[yellow] None' except Exception as e: coldkeypub_str = '[yellow] None' logger.error('{}: Failed to pull coldkey error = {}', droplet.name, e) else: coldkeypub_str = '[yellow] None' # get branch if can_connect_bool: try: branch = get_branch(connection) branch_str = branch if branch != None else '[yellow] None' except Exception as e: branch_str = '[yellow] None' logger.error('{}: Failed to pull branch error = {}', droplet.name, e) else: branch_str = '[yellow] None' # get install status if can_connect_bool and branch != None: try: installed = is_installed(connection) is_installed_str = '[bold green] Yes' if installed else '[bold red] No' except Exception as e: installed = False is_installed_str = '[bold red] No' logger.error( '{}: Failed to pull install status error = {}', droplet.name, e) else: installed = False is_installed_str = '[bold red] No' # get miner status if can_connect_bool and installed: try: is_running = is_miner_running(connection) is_running_str = '[bold green] Yes' if is_running else '[bold red] No' except Exception as e: is_running = False is_running_str = '[bold red] No' logger.error( '{}: Failed to pull running status: error = {}', droplet.name, e) else: is_running = False is_running_str = '[bold red] No' # get is_subscribed try: uid = meta.hotkeys.index(hotkey) is_subscribed = True is_subscribed_str = '[bold green] Yes' except: is_subscribed = False is_subscribed_str = '[bold red] No' # get subscription status. if is_subscribed: stake = meta.S[uid].item() rank = meta.R[uid].item() incentive = meta.I[uid].item() lastemit = int(meta.block - meta.lastemit[uid]) lastemit = "[bold green]" + str( lastemit) if lastemit < 3000 else "[bold red]" + str( lastemit) address = str(meta.addresses[uid]) neuron = meta.neuron_endpoints[uid] total_stake += stake total_rank += rank total_incentive += incentive * 14400 uid_str = str(uid) stake_str = '[green]\u03C4{:.5}'.format(stake) rank_str = '[green]\u03C4{:.5}'.format(rank) incentive_str = '[green]\u03C4{:.5}'.format(incentive * 14400) lastemit_str = str(lastemit) address_str = str(address) else: uid_str = '[dim yellow] None' stake_str = '[dim yellow] None' rank_str = '[dim yellow] None' incentive_str = '[dim yellow] None' lastemit_str = '[dim yellow] None' address_str = '[dim yellow] None' # Make query and get response. if installed and is_running and is_subscribed and wallet.has_hotkey and neuron != None: start_time = time.time() result, code = dendrite.forward_text( neurons=[neuron], x=[torch.zeros((1, 1), dtype=torch.int64)]) end_time = time.time() code_to_string = bittensor.utils.codes.code_to_string( code.item()) code_color = bittensor.utils.codes.code_to_color(code.item()) code_str = '[' + str(code_color) + ']' + code_to_string query_time_str = '[' + str( code_color) + ']' + "" + '{:.3}'.format(end_time - start_time) + "s" if code.item() == 0: total_success += 1 total_time += end_time - start_time else: code_str = '[dim yellow] N/A' query_time_str = '[dim yellow] N/A' row = [ str(droplet.name), str(droplet.ip_address), str(droplet.region['name']), str(droplet.size_slug), str(connect_str), branch_str, is_installed_str, is_running_str, is_subscribed_str, address_str, uid_str, stake_str, rank_str, incentive_str, lastemit_str, query_time_str, code_str, hotkey_str, coldkeypub_str ] return row # Get latest droplets. droplets = manager.get_all_droplets(tag_name=[TAG]) if config.names == None: config.names = [droplet.name for droplet in droplets] subtensor.connect() meta.load() meta.sync(subtensor=subtensor, force=config.force) meta.save() TABLE_DATA = [] with ThreadPoolExecutor(max_workers=MAX_THREADS) as executor: if config.live: TABLE_DATA = list(executor.map(get_row, droplets)) else: TABLE_DATA = list( tqdm(executor.map(get_row, droplets), total=len(droplets))) TABLE_DATA = [row for row in TABLE_DATA if row != None] TABLE_DATA.sort(key=lambda TABLE_DATA: TABLE_DATA[0]) total_stake_str = '\u03C4{:.7}'.format(total_stake) total_rank_str = '\u03C4{:.7}'.format(total_rank) total_incentive_str = '\u03C4{:.7}'.format(total_incentive) total_time_str = '{:.3}s'.format( total_time / len(config.names)) if total_time != 0 else '0.0s' total_success_str = '[bold green]' + str( total_success) + '/[bold red]' + str( len(config.names) - total_success) console = Console() table = Table(show_footer=False) table.title = ("[bold white]Miners") table.add_column("[overline white]NAME", str(len(config.names)), footer_style="overline white", style='white') table.add_column("[overline white]IP", style='blue') table.add_column("[overline white]LOC", style='yellow') table.add_column("[overline white]SIZE", style='green') table.add_column("[overline white]CONN", style='green') table.add_column("[overline white]BRNCH", style='bold purple') table.add_column("[overline white]INSTL") table.add_column("[overline white]RNG") table.add_column("[overline white]SUBD") table.add_column("[overline white]ADDR", style='blue') table.add_column("[overline white]UID", style='yellow') table.add_column("[overline white]STAKE(\u03C4)", total_stake_str, footer_style="overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]RANK(\u03C4)", total_rank_str, footer_style="overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]INCN(\u03C4/d)", total_incentive_str, footer_style="overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]LEmit", justify='right', no_wrap=True) table.add_column("[overline white]Qry(sec)", total_time_str, footer_style="overline white", justify='right', no_wrap=True) table.add_column("[overline white]Qry(code)", total_success_str, footer_style="overline white", justify='right', no_wrap=True) table.add_column("[overline white]HOT", style='bold blue', no_wrap=False) table.add_column("[overline white]COLD", style='blue', no_wrap=False) table.show_footer = True console.clear() for row in TABLE_DATA: table.add_row(*row) table.box = None table.pad_edge = False table.width = None table = Align.center(table) return table
def overview(self): r""" Prints an overview for the wallet's colkey. """ console = bittensor.__console__ wallet = bittensor.wallet( config = self.config ) subtensor = bittensor.subtensor( config = self.config ) all_hotkeys = CLI._get_hotkey_wallets_for_wallet( wallet ) neurons = [] block = subtensor.block with console.status(":satellite: Syncing with chain: [white]{}[/white] ...".format(self.config.subtensor.network)): for wallet in tqdm(all_hotkeys): nn = subtensor.neuron_for_pubkey( wallet.hotkey.ss58_address ) if not nn.is_null: neurons.append( nn ) balance = subtensor.get_balance( wallet.coldkeypub.ss58_address ) TABLE_DATA = [] total_stake = 0.0 total_rank = 0.0 total_trust = 0.0 total_consensus = 0.0 total_incentive = 0.0 total_dividends = 0.0 total_emission = 0 for nn, hotwallet in tqdm(list(zip(neurons,all_hotkeys))): uid = nn.uid active = nn.active stake = nn.stake rank = nn.rank trust = nn.trust consensus = nn.consensus incentive = nn.incentive dividends = nn.dividends emission = int(nn.emission * 1000000000) last_update = int(block - nn.last_update) row = [ hotwallet.hotkey_str, str(uid), str(active), '{:.5f}'.format(stake), '{:.5f}'.format(rank), '{:.5f}'.format(trust), '{:.5f}'.format(consensus), '{:.5f}'.format(incentive), '{:.5f}'.format(dividends), '{}'.format(emission), str(last_update), bittensor.utils.networking.int_to_ip( nn.ip) + ':' + str(nn.port) if nn.port != 0 else '[yellow]none[/yellow]', nn.hotkey ] total_stake += stake total_rank += rank total_trust += trust total_consensus += consensus total_incentive += incentive total_dividends += dividends total_emission += emission TABLE_DATA.append(row) total_neurons = len(neurons) table = Table(show_footer=False) table.title = ( "[white]Wallet - {}:{}".format(self.config.wallet.name, wallet.coldkeypub.ss58_address) ) table.add_column("[overline white]HOTKEY", str(total_neurons), footer_style = "overline white", style='bold white') table.add_column("[overline white]UID", str(total_neurons), footer_style = "overline white", style='yellow') table.add_column("[overline white]ACTIVE", justify='right', style='green', no_wrap=True) table.add_column("[overline white]STAKE(\u03C4)", '\u03C4{:.5f}'.format(total_stake), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]RANK", '{:.5f}'.format(total_rank), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]TRUST", '{:.5f}'.format(total_trust), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]CONSENSUS", '{:.5f}'.format(total_consensus), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]INCENTIVE", '{:.5f}'.format(total_incentive), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]DIVIDENDS", '{:.5f}'.format(total_dividends), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]EMISSION(\u03C1)", '\u03C1{}'.format(int(total_emission)), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]UPDATED", justify='right', no_wrap=True) table.add_column("[overline white]AXON", justify='left', style='dim blue', no_wrap=True) table.add_column("[overline white]HOTKEY", style='dim blue', no_wrap=False) table.show_footer = True table.caption = "[white]Wallet balance: [green]\u03C4" + str(balance.tao) console.clear() for row in TABLE_DATA: table.add_row(*row) table.box = None table.pad_edge = False table.width = None console.print(table)
def metagraph(self): r""" Prints an entire metagraph. """ console = bittensor.__console__ subtensor = bittensor.subtensor( config = self.config ) metagraph = bittensor.metagraph( subtensor = subtensor ) console.print(":satellite: Syncing with chain: [white]{}[/white] ...".format(self.config.subtensor.network)) metagraph.sync() metagraph.save() issuance = subtensor.total_issuance difficulty = subtensor.difficulty TABLE_DATA = [] total_stake = 0.0 total_rank = 0.0 total_trust = 0.0 total_consensus = 0.0 total_incentive = 0.0 total_dividends = 0.0 total_emission = 0 for uid in metagraph.uids: ep = metagraph.endpoint_objs[uid] row = [ str(ep.uid), '{:.5f}'.format( metagraph.stake[uid]), '{:.5f}'.format( metagraph.ranks[uid]), '{:.5f}'.format( metagraph.trust[uid]), '{:.5f}'.format( metagraph.consensus[uid]), '{:.5f}'.format( metagraph.incentive[uid]), '{:.5f}'.format( metagraph.dividends[uid]), '{}'.format( int(metagraph.emission[uid] * 1000000000)), str((metagraph.block.item() - metagraph.last_update[uid].item())), str( metagraph.active[uid].item() ), ep.ip + ':' + str(ep.port) if ep.is_serving else '[yellow]none[/yellow]', ep.hotkey[:10], ep.coldkey[:10] ] total_stake += metagraph.stake[uid] total_rank += metagraph.ranks[uid] total_trust += metagraph.trust[uid] total_consensus += metagraph.consensus[uid] total_incentive += metagraph.incentive[uid] total_dividends += metagraph.dividends[uid] total_emission += int(metagraph.emission[uid] * 1000000000) TABLE_DATA.append(row) total_neurons = len(metagraph.uids) table = Table(show_footer=False) table.title = ( "[white]Metagraph: name: {}, block: {}, N: {}/{}, tau: {}/block, stake: {}, issuance: {}, difficulty: {}".format(subtensor.network, metagraph.block.item(), sum(metagraph.active.tolist()), metagraph.n.item(), bittensor.Balance.from_tao(metagraph.tau.item()), bittensor.Balance.from_tao(total_stake), issuance, difficulty ) ) table.add_column("[overline white]UID", str(total_neurons), footer_style = "overline white", style='yellow') table.add_column("[overline white]STAKE(\u03C4)", '\u03C4{:.5f}'.format(total_stake), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]RANK", '{:.5f}'.format(total_rank), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]TRUST", '{:.5f}'.format(total_trust), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]CONSENSUS", '{:.5f}'.format(total_consensus), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]INCENTIVE", '{:.5f}'.format(total_incentive), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]DIVIDENDS", '{:.5f}'.format(total_dividends), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]EMISSION(\u03C1)", '\u03C1{}'.format(int(total_emission)), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]UPDATED", justify='right', no_wrap=True) table.add_column("[overline white]ACTIVE", justify='right', style='green', no_wrap=True) table.add_column("[overline white]AXON", justify='left', style='dim blue', no_wrap=True) table.add_column("[overline white]HOTKEY", style='dim blue', no_wrap=False) table.add_column("[overline white]COLDKEY", style='dim purple', no_wrap=False) table.show_footer = True for row in TABLE_DATA: table.add_row(*row) table.box = None table.pad_edge = False table.width = None console.print(table)