Skip to content

Commit

Permalink
Feat/thewhaleking/galina fixes (#72)
Browse files Browse the repository at this point in the history
* Weights

* Reuse the options in CLI to keep things in sync

* `netuids` and `weights` were being treated as tuples because of a hanging comma.

---------

Co-authored-by: Benjamin Himes <benhimes@opentensor.dev>
  • Loading branch information
ibraheem-opentensor and thewhaleking authored Sep 16, 2024
1 parent 1e3844d commit 1304ffb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 61 deletions.
77 changes: 17 additions & 60 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Options:
wallet_name = typer.Option(
None,
"--wallet-name",
"-w",
"--name",
"--wallet_name",
"--wallet.name",
help="Name of wallet",
Expand Down Expand Up @@ -140,6 +140,12 @@ class Options:
help="The netuid (network unique identifier) of the subnet within the root network, (e.g. 1)",
prompt=True,
)
weights = typer.Option(
[],
"--weights",
"-w",
help="Corresponding weights for the specified UIDs, e.g. `-w 0.2 -w 0.4 -w 0.1 ...",
)
reuse_last = typer.Option(
False,
"--reuse-last",
Expand Down Expand Up @@ -732,44 +738,11 @@ def metagraph_config(

def set_config(
self,
wallet_name: Optional[str] = typer.Option(
None,
"--wallet-name",
"--name",
"--wallet_name",
help="Wallet name",
),
wallet_path: Optional[str] = typer.Option(
None,
"--wallet-path",
"--path",
"-p",
"--wallet_path",
help="Path to root of wallets",
),
wallet_hotkey: Optional[str] = typer.Option(
None,
"--wallet-hotkey",
"--hotkey",
"-k",
"--wallet_hotkey",
help="name of the wallet hotkey file",
),
network: Optional[str] = typer.Option(
None,
"--network",
"-n",
"--subtensor.network",
help="Network name: [finney, test, local]",
),
chain: Optional[str] = typer.Option(
None,
"--chain",
"-c",
"--subtensor.chain_endpoint",
help="chain endpoint for the network (e.g. ws://127.0.0.1:9945, "
"wss://entrypoint-finney.opentensor.ai:443)",
),
wallet_name: Optional[str] = Options.wallet_name,
wallet_path: Optional[str] = Options.wallet_path,
wallet_hotkey: Optional[str] = Options.wallet_hotkey,
network: Optional[str] = Options.network,
chain: Optional[str] = Options.chain,
no_cache: Optional[bool] = typer.Option(
False,
"--no-cache",
Expand Down Expand Up @@ -2144,13 +2117,8 @@ def root_set_weights(
wallet_name: str = Options.wallet_name,
wallet_path: str = Options.wallet_path,
wallet_hotkey: str = Options.wallet_hotkey,
netuids: list[int] = typer.Option(
None, help="Netuids, e.g. `-n 0 -n 1 -n 2` ..."
),
weights: list[float] = typer.Argument(
None,
help="Weights: e.g. `0.02 0.03 0.01` ...",
),
netuids: list[int] = Options.netuids,
weights: list[float] = Options.weights,
prompt: bool = Options.prompt,
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
Expand All @@ -2176,15 +2144,14 @@ def root_set_weights(
"""
self.verbosity_handler(quiet, verbose)
netuids = list_prompt(netuids, int, "Enter netuids (e.g: 1, 4, 6)")
weights = list_prompt(weights, float, "Enter weights (e.g. 0.02, 0.03, 0.01)")
wallet = self.wallet_ask(
wallet_name,
wallet_path,
wallet_hotkey,
ask_for=[WO.HOTKEY, WO.NAME],
validate=WV.WALLET_AND_HOTKEY,
)
if not weights:
weights = list_prompt([], float, "Weights (e.g. 0.02, 0.03, 0.01)")
self._run_command(
root.set_weights(
wallet, self.initialize_chain(network, chain), netuids, weights, prompt
Expand Down Expand Up @@ -4205,12 +4172,7 @@ def weights_reveal(
"-u",
help="Corresponding UIDs for the specified netuid, e.g. -u 1 -u 2 -u 3 ...",
),
weights: list[float] = typer.Option(
[],
"--weights",
"-w",
help="Corresponding weights for the specified UIDs, e.g. `-w 0.2 -w 0.4 -w 0.1 ...",
),
weights: list[float] = Options.weights,
salt: list[int] = typer.Option(
[],
"--salt",
Expand Down Expand Up @@ -4280,12 +4242,7 @@ def weights_commit(
"-u",
help="Corresponding UIDs for the specified netuid, e.g. -u 1 -u 2 -u 3 ...",
),
weights: list[float] = typer.Option(
[],
"--weights",
"-w",
help="Corresponding weights for the specified UIDs, e.g. `-w 0.2 -w 0.4 -w 0.1 ...",
),
weights: list[float] = Options.weights,
salt: list[int] = typer.Option(
[],
"--salt",
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/bittensor/extrinsics/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ async def _do_set_weights():
if my_uid is None:
err_console.print("Your hotkey is not registered to the root network")
return False

try:
wallet.unlock_coldkey()
except KeyFileError:
Expand Down

0 comments on commit 1304ffb

Please sign in to comment.