Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.0...v9.7.1

## 9.7.0/2025-06-16

## What's Changed
Expand Down
10 changes: 10 additions & 0 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions bittensor_cli/src/commands/sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
28 changes: 28 additions & 0 deletions tests/e2e_tests/test_staking_sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Loading