Skip to content

Commit

Permalink
- fix args parser errors
Browse files Browse the repository at this point in the history
- fix set weight
- fix staking
  • Loading branch information
Snedashkovsky committed Mar 15, 2024
1 parent ad1dbb0 commit aa7535b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 52 deletions.
16 changes: 1 addition & 15 deletions cybertensor/commands/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,6 @@ def add_args(parser: argparse.ArgumentParser):
parser.add_argument(
"--netuid", dest="netuid", type=int, required=False, default=False
)
parser.add_argument(
"--no_prompt",
dest="no_prompt",
action="store_true",
help="""Set true to avoid prompting the user.""",
default=False,
)
Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)

Expand Down Expand Up @@ -731,7 +724,7 @@ def run(cli: "cybertensor.cli") -> None:
r"""Get weights for root network."""
try:
cwtensor = cybertensor.cwtensor(config=cli.config, log_verbose=False)
SubnetSetWeightsCommand._run(cli, cwtensor)
SubnetGetWeightsCommand._run(cli, cwtensor)
finally:
if "cwtensor" in locals():
cwtensor.close()
Expand Down Expand Up @@ -811,13 +804,6 @@ def add_args(parser: argparse.ArgumentParser):
parser.add_argument(
"--netuid", dest="netuid", type=int, required=False, default=False
)
parser.add_argument(
"--no_prompt",
dest="no_prompt",
action="store_true",
help="""Set true to avoid prompting the user.""",
default=False,
)
Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)

Expand Down
4 changes: 2 additions & 2 deletions cybertensor/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,10 @@ def get_stake_accounts(
cold_balance = cwtensor.get_balance(wallet.coldkeypub.address)

# Populate the stake accounts with local hotkeys data.
wallet_stake_accounts.update(get_stakes_from_hotkeys(cwtensor, wallet))
wallet_stake_accounts.update(get_stakes_from_hotkeys(cwtensor=cwtensor, wallet=wallet))

# Populate the stake accounts with delegations data.
wallet_stake_accounts.update(get_stakes_from_delegates(cwtensor, wallet))
wallet_stake_accounts.update(get_stakes_from_delegates(cwtensor=cwtensor, wallet=wallet))

return {
"name": wallet.name,
Expand Down
7 changes: 0 additions & 7 deletions cybertensor/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,6 @@ def add_args(parser: argparse.ArgumentParser):
help="""Updates the wallet security using NaCL instead of anvisible vault.""",
)
update_wallet_parser.add_argument("--all", action="store_true")
update_wallet_parser.add_argument(
"--no_prompt",
dest="no_prompt",
action="store_true",
help="""Set true to avoid prompting the user.""",
default=False,
)
Wallet.add_args(update_wallet_parser)
cybertensor.cwtensor.add_args(update_wallet_parser)

Expand Down
86 changes: 65 additions & 21 deletions cybertensor/cwtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,29 +623,29 @@ def set_weights(
This function is crucial in shaping the network's collective intelligence, where each neuron's
learning and contribution are influenced by the weights it sets towards others【81†source】.
"""
uid = self.get_uid_for_hotkey_on_subnet(wallet.hotkey.address, netuid)
retries = 0
# uid = self.get_uid_for_hotkey_on_subnet(wallet.hotkey.address, netuid)
# retries = 0
success = False
message = "No attempt made. Perhaps it is too soon to set weights!"
while (
self.blocks_since_last_update(netuid, uid) > self.weights_rate_limit(netuid) # type: ignore
and retries < max_retries
):
try:
success, message = set_weights_message(
cwtensor=self,
wallet=wallet,
netuid=netuid,
uids=uids,
weights=weights,
version_key=version_key,
wait_for_finalization=wait_for_finalization,
prompt=prompt,
)
except Exception as e:
cybertensor.logging.error(f"Error setting weights: {e}")
finally:
retries += 1
# while (
# self.blocks_since_last_update(netuid, uid) > self.weights_rate_limit(netuid) # type: ignore
# and retries < max_retries
# ):
try:
success, message = set_weights_message(
cwtensor=self,
wallet=wallet,
netuid=netuid,
uids=uids,
weights=weights,
version_key=version_key,
wait_for_finalization=wait_for_finalization,
prompt=prompt,
)
except Exception as e:
cybertensor.logging.error(f"Error setting weights: {e}")
# finally:
# retries += 1

return success, message

Expand Down Expand Up @@ -1548,6 +1548,50 @@ def subnetwork_n(self, netuid: int, block: Optional[int] = None) -> Optional[int

return subnet_info.subnetwork_n

# def max_n(self, netuid: int, block: Optional[int] = None) -> Optional[int]:
# """Returns network MaxAllowedUids hyper parameter"""
# if not self.subnet_exists(netuid, block):
# return None
# _res = self.contract.query(
# {"max_allowed_uids": {"netuid": netuid}}
# )
# if _res is None:
# return None
# return _res
#
# def blocks_since_epoch(
# self, netuid: int, block: Optional[int] = None
# ) -> Optional[int]:
# """Returns network BlocksSinceLastStep hyper parameter"""
# if not self.subnet_exists(netuid, block):
# return None
# _res = self.contract.query(
# {"block_since_last_step": {"netuid": netuid}}
# )
# if _res is None:
# return None
# return _res

# def blocks_since_last_update(self, netuid: int, uid: int) -> Optional[int]:
# if not self.subnet_exists(netuid):
# return None
# _res = self.contract.query(
# {"block_since_last_update": {"netuid": netuid, "uid": uid}}
# )
# if _res is None:
# return None
# return _res

# def weights_rate_limit(self, netuid: int) -> Optional[int]:
# if not self.subnet_exists(netuid):
# return None
# _res = self.contract.query(
# {"weights_set_rate_limit": {"netuid": netuid}}
# )
# if _res is None:
# return None
# return _res

def tempo(self, netuid: int, block: Optional[int] = None) -> Optional[int]:
"""Returns network Tempo hyperparameter"""
tempo = self.contract.query({"get_tempo": {"netuid": netuid}})
Expand Down
15 changes: 8 additions & 7 deletions cybertensor/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,6 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None):
default_name = os.getenv("CT_WALLET_NAME") or "default"
default_hotkey = os.getenv("CT_WALLET_NAME") or "default"
default_path = os.getenv("CT_WALLET_PATH") or "~/.cybertensor/wallets/"
parser.add_argument(
"--no_prompt",
dest="no_prompt",
action="store_true",
help="""Set true to avoid prompting the user.""",
default=False,
)
parser.add_argument(
"--" + prefix_str + "wallet.name",
required=False,
Expand All @@ -163,7 +156,15 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None):
default=default_path,
help="The path to your cybertensor wallets",
)
parser.add_argument(
"--no_prompt",
dest="no_prompt",
action="store_true",
help="""Set true to avoid prompting the user.""",
default=False,
)
except argparse.ArgumentError as e:
print(f'ArgumentError {e}')
pass

def __init__(
Expand Down

0 comments on commit aa7535b

Please sign in to comment.