-
Notifications
You must be signed in to change notification settings - Fork 5
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
Adds support for list type inputs #103
Merged
ibraheem-opentensor
merged 17 commits into
main
from
enhancement/abe/adds-support-lists
Sep 23, 2024
Merged
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1705ba8
Adds support for passing comma sep values
ibraheem-opentensor b5602c1
Adds func to salt
ibraheem-opentensor 1036c81
Merge branch 'main' into enhancement/abe/adds-support-lists
ibraheem-opentensor d812e90
Seventh set of Typer docstrings
d4c9207
Table fixes / E2E Test - Senate command fix (#100)
ibraheem-opentensor 156b8e0
Merge branch 'main' into enhancement/abe/adds-support-lists
ibraheem-opentensor 6e640f4
Update help.
thewhaleking 8d45c1c
Merge remote-tracking branch 'origin/main' into enhancement/abe/adds-…
thewhaleking d869f14
Ruff
thewhaleking e8265be
Give user their UID immediately after root/sn registration. (#108)
thewhaleking 7711916
Don't check size of PGP fingerprint if it's not set (#110)
thewhaleking fc329ac
Enhancement: max-stake and table tweak (#105)
ibraheem-opentensor 8a8010b
Propagates list supp, exists in-case of no subnet in sudo set, fixes …
ibraheem-opentensor 4b8c9b0
Ruff
ibraheem-opentensor 0f26a1d
Merge branch 'main' into enhancement/abe/adds-support-lists
ibraheem-opentensor 193ae97
Adds support for both hotkeys and ss58s
ibraheem-opentensor 3017f84
Updated help docstring for stake_remove to reflect new list style
thewhaleking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,7 @@ class Options: | |
show_default=False, | ||
) | ||
netuids = typer.Option( | ||
[], | ||
None, | ||
"--netuids", | ||
"-n", | ||
help="Set the netuid(s) to filter by. Separate multiple netuids with a space, for example: `0 1 2`.", | ||
|
@@ -149,7 +149,7 @@ class Options: | |
prompt=True, | ||
) | ||
weights = typer.Option( | ||
[], | ||
None, | ||
"--weights", | ||
"-w", | ||
help="Weights for the specified UIDs, e.g. `-w 0.2 -w 0.4 -w 0.1 ...` Must correspond to the order of the UIDs.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs updated |
||
|
@@ -207,6 +207,14 @@ def list_prompt(init_var: list, list_type: type, help_text: str) -> list: | |
return init_var | ||
|
||
|
||
def parse_to_list(raw_list: str, list_type: type, error_message: str) -> list: | ||
try: | ||
# Split the string by commas and convert each part to according to type | ||
return [list_type(uid.strip()) for uid in raw_list.split(",") if uid.strip()] | ||
except ValueError: | ||
raise typer.BadParameter(error_message) | ||
|
||
|
||
def verbosity_console_handler(verbosity_level: int = 1) -> None: | ||
""" | ||
Sets verbosity level of console output | ||
|
@@ -1105,7 +1113,7 @@ def wallet_overview( | |
help="Hotkeys to exclude. Specify by name or ss58 address. " | ||
"If left empty, all hotkeys, except those in the '--include-hotkeys', will be excluded.", | ||
), | ||
netuids: list[int] = Options.netuids, | ||
netuids: str = Options.netuids, | ||
network: str = Options.network, | ||
chain: str = Options.chain, | ||
quiet: bool = Options.quiet, | ||
|
@@ -1174,6 +1182,13 @@ def wallet_overview( | |
) | ||
raise typer.Exit() | ||
|
||
if netuids: | ||
netuids = parse_to_list( | ||
netuids, | ||
int, | ||
"Netuids must be a comma-separated list of ints, e.g., `--netuids 1,2,3,4`.", | ||
) | ||
|
||
ask_for = [WO.NAME] if not all_wallets else [WO.PATH] | ||
validate = WV.WALLET if not all_wallets else WV.NONE | ||
wallet = self.wallet_ask( | ||
|
@@ -1325,7 +1340,7 @@ def wallet_inspect( | |
wallet_hotkey: str = Options.wallet_hotkey, | ||
network: str = Options.network, | ||
chain: str = Options.chain, | ||
netuids: list[int] = Options.netuids, | ||
netuids: str = Options.netuids, | ||
quiet: bool = Options.quiet, | ||
verbose: bool = Options.verbose, | ||
): | ||
|
@@ -1361,8 +1376,15 @@ def wallet_inspect( | |
[bold]Note[/bold]: The `inspect` command is for displaying information only and does not perform any transactions or state changes on the blockchain. It is intended to be used with Bittensor CLI and not as a standalone function in user code. | ||
""" | ||
self.verbosity_handler(quiet, verbose) | ||
# if all-wallets is entered, ask for path | ||
|
||
if netuids: | ||
netuids = parse_to_list( | ||
netuids, | ||
int, | ||
"Netuids must be a comma-separated list of ints, e.g., `--netuids 1,2,3,4`.", | ||
) | ||
|
||
# if all-wallets is entered, ask for path | ||
ask_for = [WO.NAME] if not all_wallets else [WO.PATH] | ||
validate = WV.WALLET if not all_wallets else WV.NONE | ||
wallet = self.wallet_ask( | ||
|
@@ -1774,7 +1796,8 @@ def wallet_create_wallet( | |
|
||
if not wallet_name: | ||
wallet_name = Prompt.ask( | ||
"Enter the name of the new wallet (coldkey)", default=defaults.wallet.name | ||
"Enter the name of the new wallet (coldkey)", | ||
default=defaults.wallet.name, | ||
) | ||
if not wallet_hotkey: | ||
wallet_hotkey = Prompt.ask( | ||
|
@@ -1959,8 +1982,8 @@ def wallet_set_id( | |
|
||
The command prompts the user for the identity attributes and validates the input size for each attribute. It provides an option to update an existing validator hotkey identity. If the user consents to the transaction cost, the identity is updated on the blockchain. | ||
|
||
Each field has a maximum size of 64 bytes. The PGP fingerprint field is an exception and has a maximum size of 20 bytes. The user is prompted to enter the PGP fingerprint as a hex string, which is then converted to bytes. The user is also prompted to enter the coldkey or hotkey ``ss58`` address for the identity to be updated. | ||
Each field has a maximum size of 64 bytes. The PGP fingerprint field is an exception and has a maximum size of 20 bytes. The user is prompted to enter the PGP fingerprint as a hex string, which is then converted to bytes. The user is also prompted to enter the coldkey or hotkey ``ss58`` address for the identity to be updated. | ||
|
||
If the user does not have a hotkey, the coldkey address is used by default. If setting a validator identity, the hotkey will be used by default. If the user is setting an identity for a subnet, the coldkey will be used by default. | ||
|
||
EXAMPLE | ||
|
@@ -2115,8 +2138,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] = Options.netuids, | ||
weights: list[float] = Options.weights, | ||
netuids: str = Options.netuids, | ||
weights: str = Options.weights, | ||
prompt: bool = Options.prompt, | ||
quiet: bool = Options.quiet, | ||
verbose: bool = Options.verbose, | ||
|
@@ -2141,8 +2164,32 @@ def root_set_weights( | |
[green]$[/green] btcli root set-weights --netuids "1, 2" --weights "0.2, 0.3" | ||
""" | ||
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)") | ||
|
||
if netuids: | ||
netuids = parse_to_list( | ||
netuids, | ||
int, | ||
"Netuids must be a comma-separated list of ints, e.g., `--netuid 1,2,3,4`.", | ||
) | ||
else: | ||
netuids = list_prompt(netuids, int, "Enter netuids (e.g: 1, 4, 6)") | ||
|
||
if weights: | ||
weights = parse_to_list( | ||
weights, | ||
float, | ||
"Weights must be a comma-separated list of floats, e.g., `--weights 0.3,0.4,0.3`.", | ||
) | ||
else: | ||
weights = list_prompt( | ||
weights, float, "Enter weights (e.g. 0.02, 0.03, 0.01)" | ||
) | ||
|
||
if len(netuids) != len(weights): | ||
raise typer.BadParameter( | ||
"The number of netuids and weights must be the same." | ||
) | ||
|
||
wallet = self.wallet_ask( | ||
wallet_name, | ||
wallet_path, | ||
|
@@ -4072,15 +4119,15 @@ def weights_reveal( | |
wallet_path: str = Options.wallet_path, | ||
wallet_hotkey: str = Options.wallet_hotkey, | ||
netuid: int = Options.netuid, | ||
uids: list[int] = typer.Option( | ||
[], | ||
uids: str = typer.Option( | ||
None, | ||
"--uids", | ||
"-u", | ||
help="Corresponding UIDs for the specified netuid, e.g. -u 1 -u 2 -u 3 ...", | ||
help="Corresponding UIDs for the specified netuid, e.g. -u 1,2,3 ...", | ||
), | ||
weights: list[float] = Options.weights, | ||
salt: list[int] = typer.Option( | ||
[], | ||
weights: str = Options.weights, | ||
salt: str = typer.Option( | ||
None, | ||
"--salt", | ||
"-s", | ||
help="Corresponding salt for the hash function, e.g. -s 163 -s 241 -s 217 ...", | ||
|
@@ -4104,16 +4151,45 @@ def weights_reveal( | |
[italic]Note[/italic]: This command is used to reveal weights for a specific subnet and requires the user to have the necessary permissions. | ||
""" | ||
self.verbosity_handler(quiet, verbose) | ||
uids = list_prompt(uids, int, "Corresponding UIDs for the specified netuid") | ||
weights = list_prompt( | ||
weights, float, "Corresponding weights for the specified UIDs" | ||
) | ||
if uids: | ||
uids = parse_to_list( | ||
uids, | ||
int, | ||
"Uids must be a comma-separated list of ints, e.g., `--uids 1,2,3,4`.", | ||
) | ||
else: | ||
uids = list_prompt( | ||
uids, int, "Corresponding UIDs for the specified netuid (eg: 1,2,3)" | ||
) | ||
|
||
if weights: | ||
weights = parse_to_list( | ||
weights, | ||
float, | ||
"Weights must be a comma-separated list of floats, e.g., `--weights 0.3,0.4,0.3`.", | ||
) | ||
else: | ||
weights = list_prompt( | ||
weights, | ||
float, | ||
"Corresponding weights for the specified UIDs (eg: 0.2,0.3,0.4)", | ||
) | ||
|
||
if len(uids) != len(weights): | ||
err_console.print( | ||
"The number of UIDs you specify must match up with the number of weights you specify" | ||
) | ||
raise typer.Exit() | ||
salt = list_prompt(salt, int, "Corresponding salt for the hash function") | ||
|
||
if salt: | ||
salt = parse_to_list( | ||
salt, | ||
int, | ||
"Salt must be a comma-separated list of ints, e.g., `--weights 123,163,194`.", | ||
) | ||
else: | ||
salt = list_prompt(salt, int, "Corresponding salt for the hash function") | ||
|
||
wallet = self.wallet_ask( | ||
wallet_name, | ||
wallet_path, | ||
|
@@ -4142,15 +4218,15 @@ def weights_commit( | |
wallet_path: str = Options.wallet_path, | ||
wallet_hotkey: str = Options.wallet_hotkey, | ||
netuid: int = Options.netuid, | ||
uids: list[int] = typer.Option( | ||
[], | ||
uids: str = typer.Option( | ||
None, | ||
"--uids", | ||
"-u", | ||
help="Corresponding UIDs for the specified netuid, e.g. -u 1 -u 2 -u 3 ...", | ||
help="Corresponding UIDs for the specified netuid, e.g. -u 1,2,3 ...", | ||
), | ||
weights: list[float] = Options.weights, | ||
salt: list[int] = typer.Option( | ||
[], | ||
weights: str = Options.weights, | ||
salt: str = typer.Option( | ||
None, | ||
"--salt", | ||
"-s", | ||
help="Corresponding salt for the hash function, e.g. -s 163 -s 241 -s 217 ...", | ||
|
@@ -4170,22 +4246,52 @@ def weights_commit( | |
|
||
### Example usage: | ||
|
||
[green]$[/green] btcli wt commit --netuid 1 --uids 1,2,3,4 --w 0.1 -w 0.2 -w 0.3 -w 0.4 | ||
[green]$[/green] btcli wt commit --netuid 1 --uids 1,2,3,4 --w 0.1,0.2,0.3 | ||
|
||
[italic]Note[/italic]: This command is used to commit weights for a specific subnet and requires the user to have the necessary | ||
permissions. | ||
""" | ||
self.verbosity_handler(quiet, verbose) | ||
uids = list_prompt(uids, int, "Corresponding UIDs for the specified netuid") | ||
weights = list_prompt( | ||
weights, float, "Corresponding weights for the specified UIDs" | ||
) | ||
|
||
if uids: | ||
uids = parse_to_list( | ||
uids, | ||
int, | ||
"Uids must be a comma-separated list of ints, e.g., `--uids 1,2,3,4`.", | ||
) | ||
else: | ||
uids = list_prompt( | ||
uids, int, "Corresponding UIDs for the specified netuid (eg: 1,2,3)" | ||
) | ||
|
||
if weights: | ||
weights = parse_to_list( | ||
weights, | ||
float, | ||
"Weights must be a comma-separated list of floats, e.g., `--weights 0.3,0.4,0.3`.", | ||
) | ||
else: | ||
weights = list_prompt( | ||
weights, | ||
float, | ||
"Corresponding weights for the specified UIDs (eg: 0.2,0.3,0.4)", | ||
) | ||
|
||
if len(uids) != len(weights): | ||
err_console.print( | ||
"The number of UIDs you specify must match up with the number of weights you specify" | ||
) | ||
raise typer.Exit() | ||
salt = list_prompt(salt, int, "Corresponding salt for the hash function") | ||
|
||
if salt: | ||
salt = parse_to_list( | ||
salt, | ||
int, | ||
"Salt must be a comma-separated list of ints, e.g., `--weights 123,163,194`.", | ||
) | ||
else: | ||
salt = list_prompt(salt, int, "Corresponding salt for the hash function") | ||
|
||
wallet = self.wallet_ask( | ||
wallet_name, | ||
wallet_path, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs updated