Esempio n. 1
0
def render_tables():
    console = Console(
        width=60,
        force_terminal=True,
        file=io.StringIO(),
        legacy_windows=False,
        color_system=None,
    )

    table = Table(title="test table", caption="table caption", expand=True)
    table.add_column("foo",
                     footer=Text("total"),
                     no_wrap=True,
                     overflow="ellipsis")
    table.add_column("bar", justify="center")
    table.add_column("baz", justify="right")

    table.add_row("Averlongwordgoeshere", "banana pancakes", None)

    assert Measurement.get(console, table, 80) == Measurement(41, 48)

    for width in range(10, 60, 5):
        console.print(table, width=width)

    table.expand = False
    console.print(table, justify="left")
    console.print(table, justify="center")
    console.print(table, justify="right")

    assert table.row_count == 1

    table.row_styles = ["red", "yellow"]
    table.add_row("Coffee")
    table.add_row("Coffee", "Chocolate", None, "cinnamon")

    assert table.row_count == 3

    console.print(table)

    table.show_lines = True
    console.print(table)

    table.show_footer = True
    console.print(table)

    table.show_edge = False

    console.print(table)

    table.padding = 1
    console.print(table)

    table.width = 20
    assert Measurement.get(console, table, 80) == Measurement(20, 20)
    console.print(table)

    return console.file.getvalue()
Esempio n. 2
0
            # Compute execution time and show it
            time = (end - start) * 1000
            time_str = f"{round(time):,} ms"
            time_text[runtime].renderable = Text(time_str)
            if time < 1000:
                time_text[runtime].style = Style(color="green")
            elif 1000 <= time < 5000:
                time_text[runtime].style = Style(color="orange1")
            else:
                time_text[runtime].style = Style(color="red")

            total_combined[i] = time if total_combined[i] == 0 else min(total_combined[i], time)

            # Add part 1 + 2 results if we didn't yet
            # Assumes the output contains part 1 result on first line and part 2 result on second line
            if not results_added:
                results = output.decode("UTF-8").splitlines()
                p1_text.append(results[0] if len(results) >= 1 else "N/A")
                p2_text.append(results[1] if len(results) >= 2 else "N/A")

                results_added = True

            total[runtime].append(time)

    # Add footer after all days are finished
    python_time_text.renderable = Text.from_markup(f"[uu]{round(sum(total[PYTHON])):,} ms[/uu]")
    pypy_time_text.renderable = Text.from_markup(f"[uu]{round(sum(total[PYPY])):,} ms\n" +
                                                 f"[orange3]{round(sum(total_combined)):,} ms[/orange3][/uu]")
    table.show_footer = True
Esempio n. 3
0
    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)
Esempio n. 4
0
    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
Esempio n. 5
0
    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)