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

Fixed a bug in the get_subnets function #2240

Open
wants to merge 21 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8022866
Applies fix and assertions
ibraheem-opentensor Aug 14, 2024
96badeb
Debug commit
ibraheem-opentensor Aug 15, 2024
af76ca3
Fixed a bug in the get_subnets function
niljub Aug 15, 2024
40512c8
Dummy commit
ibraheem-opentensor Aug 15, 2024
bf00b93
Merge branch 'staging' into hotfix/7.3.0/get-subnets-fix/niljub
niljub Aug 16, 2024
89d0bd3
Merge branch 'staging' into hotfix/7.3.0/get-subnets-fix/niljub
niljub Aug 17, 2024
1934ad3
Changed the test to test 500 subnets
niljub Aug 19, 2024
65aa008
Merge branch 'hotfix/7.3.0/get-subnets-fix/niljub' of https://github.…
niljub Aug 19, 2024
ad1c35a
Fixed a bug in the get_subnets function (again)
niljub Aug 19, 2024
0d236db
Child Hotkeys netuid Refactor
opendansor Aug 29, 2024
4379c59
CHK Test
opendansor Aug 29, 2024
4b046c3
u16 float limit
opendansor Aug 29, 2024
dfe3cfd
Merge branch 'staging' into feat/opendansor/chk
opendansor Aug 29, 2024
f0e09f2
Merge pull request #2276 from opentensor/feat/opendansor/chk
opendansor Aug 29, 2024
0d7361b
Merge branch 'staging' into hotfix/7.3.0/get-subnets-fix/niljub
distributedstatemachine Sep 3, 2024
f7345a6
Merge branch 'staging' into fix/metagraph-load-and-assertions
ibraheem-opentensor Sep 3, 2024
d438b0f
Merge pull request #2235 from opentensor/fix/metagraph-load-and-asser…
ibraheem-opentensor Sep 3, 2024
6a7b2ca
Add reconnection logic + tests
roman-opentensor Sep 3, 2024
5fcdcfd
Merge pull request #2280 from opentensor/feat/roman/add-subtensor-rec…
roman-opentensor Sep 3, 2024
c7b4739
removed exit sys call for ConnectionRefusedError in _get_substrate (#…
garrett-opentensor Sep 6, 2024
8cdf462
Merge branch 'staging' into hotfix/7.3.0/get-subnets-fix/niljub
niljub Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions bittensor/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,25 @@


def get_netuid(
cli: "bittensor.cli", subtensor: "bittensor.subtensor"
cli: "bittensor.cli", subtensor: "bittensor.subtensor", prompt: bool = True
) -> Tuple[bool, int]:
"""Retrieve and validate the netuid from the user or configuration."""
console = Console()
if not cli.config.is_set("netuid"):
try:
cli.config.netuid = int(Prompt.ask("Enter netuid"))
except ValueError:
console.print(
"[red]Invalid input. Please enter a valid integer for netuid.[/red]"
)
return False, -1
if not cli.config.is_set("netuid") and prompt:
cli.config.netuid = Prompt.ask("Enter netuid")
try:
cli.config.netuid = int(cli.config.netuid)
except ValueError:
console.print(
"[red]Invalid input. Please enter a valid integer for netuid.[/red]"
)
return False, -1
netuid = cli.config.netuid
if netuid < 0 or netuid > 65535:
console.print(
"[red]Invalid input. Please enter a valid integer for netuid in subnet range.[/red]"
)
return False, -1
if not subtensor.subnet_exists(netuid=netuid):
console.print(
"[red]Network with netuid {} does not exist. Please try again.[/red]".format(
Expand Down Expand Up @@ -1136,10 +1142,27 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
wallet = bittensor.wallet(config=cli.config)

# check all
if not cli.config.is_set("all"):
exists, netuid = get_netuid(cli, subtensor)
if not exists:
return
if cli.config.is_set("all"):
cli.config.netuid = None
cli.config.all = True
elif cli.config.is_set("netuid"):
if cli.config.netuid == "all":
cli.config.all = True
else:
cli.config.netuid = int(cli.config.netuid)
exists, netuid = get_netuid(cli, subtensor)
if not exists:
return
else:
netuid_input = Prompt.ask("Enter netuid or 'all'", default="all")
if netuid_input == "all":
cli.config.netuid = None
cli.config.all = True
else:
cli.config.netuid = int(netuid_input)
exists, netuid = get_netuid(cli, subtensor, False)
if not exists:
return

# get parent hotkey
hotkey = get_hotkey(wallet, cli.config)
Expand All @@ -1148,11 +1171,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
return

try:
netuids = (
subtensor.get_all_subnet_netuids()
if cli.config.is_set("all")
else [netuid]
)
netuids = subtensor.get_all_subnet_netuids() if cli.config.all else [netuid]
hotkey_stake = GetChildrenCommand.get_parent_stake_info(
console, subtensor, hotkey
)
Expand Down Expand Up @@ -1236,7 +1255,7 @@ def add_args(parser: argparse.ArgumentParser):
parser = parser.add_parser(
"get_children", help="""Get child hotkeys on subnet."""
)
parser.add_argument("--netuid", dest="netuid", type=int, required=False)
parser.add_argument("--netuid", dest="netuid", type=str, required=False)
parser.add_argument("--hotkey", dest="hotkey", type=str, required=False)
parser.add_argument(
"--all",
Expand Down Expand Up @@ -1294,7 +1313,7 @@ def render_table(

# Add columns to the table with specific styles
table.add_column("Index", style="bold yellow", no_wrap=True, justify="center")
table.add_column("ChildHotkey", style="bold green")
table.add_column("Child Hotkey", style="bold green")
table.add_column("Proportion", style="bold cyan", no_wrap=True, justify="right")
table.add_column(
"Childkey Take", style="bold blue", no_wrap=True, justify="right"
Expand Down
2 changes: 2 additions & 0 deletions bittensor/extrinsics/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bittensor
import bittensor.utils.networking as net
from bittensor.utils import format_error_message
from bittensor.utils.networking import ensure_connected
from ..errors import MetadataError


Expand Down Expand Up @@ -269,6 +270,7 @@ def publish_metadata(
raise MetadataError(format_error_message(response.error_message))


@ensure_connected
def get_metadata(self, netuid: int, hotkey: str, block: Optional[int] = None) -> str:
@retry(delay=2, tries=3, backoff=2, max_delay=4)
def make_substrate_call_with_retry():
Expand Down
4 changes: 4 additions & 0 deletions bittensor/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def state_dict(self):
"bonds": self.bonds,
"uids": self.uids,
"axons": self.axons,
"neurons": self.neurons,
}

def sync(
Expand Down Expand Up @@ -782,6 +783,7 @@ def save(self) -> "metagraph": # type: ignore
graph_filename = f"{save_directory}/block-{self.block.item()}.pt"
state_dict = self.state_dict()
state_dict["axons"] = self.axons
state_dict["neurons"] = self.neurons
torch.save(state_dict, graph_filename)
state_dict = torch.load(
graph_filename
Expand Down Expand Up @@ -1029,6 +1031,7 @@ def load_from_path(self, dir_path: str) -> "metagraph": # type: ignore
)
self.uids = torch.nn.Parameter(state_dict["uids"], requires_grad=False)
self.axons = state_dict["axons"]
self.neurons = state_dict["neurons"]
if "weights" in state_dict:
self.weights = torch.nn.Parameter(
state_dict["weights"], requires_grad=False
Expand Down Expand Up @@ -1173,6 +1176,7 @@ def load_from_path(self, dir_path: str) -> "metagraph": # type: ignore
self.last_update = state_dict["last_update"]
self.validator_permit = state_dict["validator_permit"]
self.axons = state_dict["axons"]
self.neurons = state_dict["neurons"]
if "weights" in state_dict:
self.weights = state_dict["weights"]
if "bonds" in state_dict:
Expand Down
Loading
Loading