Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add root get_weights command to btcli #1536

Merged
merged 9 commits into from
Oct 5, 2023
1 change: 1 addition & 0 deletions bittensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"commands": {
"list": RootList,
"weights": RootSetWeightsCommand,
"get_weights": RootGetWeightsCommand,
"senate_vote": VoteCommand,
"register": RootRegisterCommand,
"proposals": ProposalsCommand,
Expand Down
7 changes: 6 additions & 1 deletion bittensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@
SubnetHyperparamsCommand,
SubnetGetHyperparamsCommand,
)
from .root import RootRegisterCommand, RootList, RootSetWeightsCommand
from .root import (
RootRegisterCommand,
RootList,
RootSetWeightsCommand,
RootGetWeightsCommand,
)
59 changes: 59 additions & 0 deletions bittensor/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,62 @@ def check_config(config: "bittensor.config"):
if not config.is_set("wallet.hotkey") and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default=defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)


class RootGetWeightsCommand:
@staticmethod
def run(cli):
r"""Get weights for root network."""
subtensor = bittensor.subtensor(config=cli.config)
weights = subtensor.weights(0)

table = Table(show_footer=False)
table.title = "[white]Root Network Weights"
table.add_column(
"[overline white]UID",
footer_style="overline white",
style="rgb(50,163,219)",
no_wrap=True,
)
table.add_column(
"[overline white]NETUID",
footer_style="overline white",
justify="right",
style="green",
no_wrap=True,
)
table.add_column(
"[overline white]WEIGHT",
footer_style="overline white",
justify="right",
style="green",
no_wrap=True,
)
table.show_footer = True

for matrix in weights:
uid = matrix[0]
for weight_data in matrix[1]:
table.add_row(
str(uid),
str(weight_data[0]),
"{:0.2f}%".format((weight_data[1] / 65535) * 100),
)

table.box = None
table.pad_edge = False
table.width = None
bittensor.__console__.print(table)

@staticmethod
def add_args(parser: argparse.ArgumentParser):
parser = parser.add_parser(
"get_weights", help="""Get weights for root network."""
)

bittensor.wallet.add_args(parser)
bittensor.subtensor.add_args(parser)

@staticmethod
def check_config(config: "bittensor.config"):
pass