From b815484d0611cc7a93f576fa18c6d8834bd06388 Mon Sep 17 00:00:00 2001 From: BD Himes <37844818+thewhaleking@users.noreply.github.com> Date: Tue, 24 Jun 2025 19:01:31 +0200 Subject: [PATCH 1/4] Merge pull request #511 from opentensor/fix/thewhaleking/ensure-we-parse-strings --- bittensor_cli/src/commands/sudo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bittensor_cli/src/commands/sudo.py b/bittensor_cli/src/commands/sudo.py index 0f919659b..cc6a4ab13 100644 --- a/bittensor_cli/src/commands/sudo.py +++ b/bittensor_cli/src/commands/sudo.py @@ -234,9 +234,9 @@ async def set_hyperparameter_extrinsic( if isinstance(value, list): # Ensure that there are enough values for all non-netuid parameters non_netuid_fields = [ - param["name"] + pn_str for param in extrinsic_params["fields"] - if "netuid" not in param["name"] + if "netuid" not in (pn_str := str(param["name"])) ] if len(value) < len(non_netuid_fields): @@ -246,7 +246,7 @@ async def set_hyperparameter_extrinsic( return False call_params.update( - {str(name): val for name, val in zip(non_netuid_fields, value)} + {name: val for name, val in zip(non_netuid_fields, value)} ) else: From 31a438269acecb2b41db58cdf9a325772c288fe9 Mon Sep 17 00:00:00 2001 From: BD Himes <37844818+thewhaleking@users.noreply.github.com> Date: Mon, 23 Jun 2025 19:18:25 +0200 Subject: [PATCH 2/4] Merge pull request #510 from opentensor/fix/thewhaleking/convert-from-strings Convert hyperparams from strings --- bittensor_cli/src/bittensor/utils.py | 10 ++++++++++ bittensor_cli/src/commands/sudo.py | 6 +++--- tests/e2e_tests/test_staking_sudo.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index 31ca5ea61..0ea43d727 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -122,6 +122,11 @@ def u64_normalized_float(x: int) -> float: return float(x) / float(U64_MAX) +def string_to_u64(value: str) -> int: + """Converts a string to u64""" + return float_to_u64(float(value)) + + def float_to_u64(value: float) -> int: """Converts a float to a u64 int""" # Ensure the input is within the expected range @@ -142,6 +147,11 @@ def u64_to_float(value: int) -> float: return min(value / u64_max, 1.0) # Ensure the result is never greater than 1.0 +def string_to_u16(value: str) -> int: + """Converts a string to a u16 int""" + return float_to_u16(float(value)) + + def float_to_u16(value: float) -> int: # Ensure the input is within the expected range if not (0 <= value <= 1): diff --git a/bittensor_cli/src/commands/sudo.py b/bittensor_cli/src/commands/sudo.py index cc6a4ab13..de02993bb 100644 --- a/bittensor_cli/src/commands/sudo.py +++ b/bittensor_cli/src/commands/sudo.py @@ -18,9 +18,9 @@ normalize_hyperparameters, unlock_key, blocks_to_duration, - float_to_u64, - float_to_u16, json_console, + string_to_u16, + string_to_u64, ) if TYPE_CHECKING: @@ -108,7 +108,7 @@ def type_converter_with_retry(type_, val, arg_name): except ValueError: return type_converter_with_retry(type_, None, arg_name) - arg_types = {"bool": string_to_bool, "u16": float_to_u16, "u64": float_to_u64} + arg_types = {"bool": string_to_bool, "u16": string_to_u16, "u64": string_to_u64} arg_type_output = {"bool": "bool", "u16": "float", "u64": "float"} call_crafter = {"netuid": netuid} diff --git a/tests/e2e_tests/test_staking_sudo.py b/tests/e2e_tests/test_staking_sudo.py index 0a0984488..8bc2107c2 100644 --- a/tests/e2e_tests/test_staking_sudo.py +++ b/tests/e2e_tests/test_staking_sudo.py @@ -533,3 +533,31 @@ def test_staking(local_chain, wallet_setup): assert yuma3_val["value"] is True assert yuma3_val["normalized_value"] is True print("✅ Passed staking and sudo commands") + + change_arbitrary_hyperparam = exec_command_alice( + command="sudo", + sub_command="set", + extra_args=[ + "--wallet-path", + wallet_path_alice, + "--wallet-name", + wallet_alice.name, + "--hotkey", + wallet_alice.hotkey_str, + "--chain", + "ws://127.0.0.1:9945", + "--netuid", + netuid, + "--param", + "sudo_set_bonds_penalty", # arbitrary hyperparam + "--value", + "0", # int/float value + "--no-prompt", + "--json-output", + ], + ) + change_arbitrary_hyperparam_json = json.loads(change_arbitrary_hyperparam.stdout) + assert change_arbitrary_hyperparam_json["success"] is True, ( + change_arbitrary_hyperparam.stdout, + change_arbitrary_hyperparam.stderr, + ) From 8b86395ae16c749c731ecf9602bf8ed22b05070c Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 26 Jun 2025 06:29:27 -0700 Subject: [PATCH 3/4] bumps version and changelog --- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f646dc19..c77ce824d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 9.7.1/2025-06-26 + +## What's Changed +* Convert hyperparams from strings by @thewhaleking in https://github.com/opentensor/btcli/pull/510 +* Ensure we parse strings for param names by @thewhaleking in https://github.com/opentensor/btcli/pull/511 + +**Full Changelog**: https://github.com/opentensor/btcli/compare/v9.7.1...v9.7.1 + ## 9.7.0/2025-06-16 ## What's Changed diff --git a/pyproject.toml b/pyproject.toml index fdafdd92f..ff7a019e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "bittensor-cli" -version = "9.7.0" +version = "9.7.1" description = "Bittensor CLI" readme = "README.md" authors = [ From 302bc8fae1fcf55cf10df708549df85e42b846e7 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 26 Jun 2025 06:30:23 -0700 Subject: [PATCH 4/4] updates changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c77ce824d..f06cebcbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * Convert hyperparams from strings by @thewhaleking in https://github.com/opentensor/btcli/pull/510 * Ensure we parse strings for param names by @thewhaleking in https://github.com/opentensor/btcli/pull/511 -**Full Changelog**: https://github.com/opentensor/btcli/compare/v9.7.1...v9.7.1 +**Full Changelog**: https://github.com/opentensor/btcli/compare/v9.7.0...v9.7.1 ## 9.7.0/2025-06-16