Skip to content

Commit daa3eb1

Browse files
authored
Merge pull request #553 from opentensor/feat/roman/get-hyperparameters-in-alphabetical-order
Hyperparameters in alphabetical order for `btcli sudo get/set`
2 parents 5295a0a + 700eb0a commit daa3eb1

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

bittensor_cli/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4597,7 +4597,9 @@ def sudo_set(
45974597
"Param name not supplied with `--no-prompt` flag. Cannot continue"
45984598
)
45994599
return False
4600-
hyperparam_list = [field.name for field in fields(SubnetHyperparameters)]
4600+
hyperparam_list = sorted(
4601+
[field.name for field in fields(SubnetHyperparameters)]
4602+
)
46014603
console.print("Available hyperparameters:\n")
46024604
for idx, param in enumerate(hyperparam_list, start=1):
46034605
console.print(f" {idx}. {param}")

bittensor_cli/src/commands/sudo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ async def get_hyperparameters(
671671
dict_out = []
672672

673673
normalized_values = normalize_hyperparameters(subnet, json_output=json_output)
674-
for param, value, norm_value in normalized_values:
674+
sorted_values = sorted(normalized_values, key=lambda x: x[0])
675+
for param, value, norm_value in sorted_values:
675676
if not json_output:
676677
table.add_row(" " + param, value, norm_value)
677678
else:

tests/e2e_tests/test_staking_sudo.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,20 +396,17 @@ def test_staking(local_chain, wallet_setup):
396396
hyperparams = exec_command_alice(
397397
command="sudo",
398398
sub_command="get",
399-
extra_args=[
400-
"--chain",
401-
"ws://127.0.0.1:9945",
402-
"--netuid",
403-
netuid,
404-
],
399+
extra_args=["--chain", "ws://127.0.0.1:9945", "--netuid", netuid, "--json-out"],
405400
)
406401

407402
# Parse all hyperparameters and single out max_burn in TAO
408-
all_hyperparams = hyperparams.stdout.splitlines()
409-
max_burn_tao = all_hyperparams[22].split()[2].strip("\u200e")
403+
all_hyperparams = json.loads(hyperparams.stdout)
404+
max_burn_tao = next(
405+
filter(lambda x: x["hyperparameter"] == "max_burn", all_hyperparams)
406+
)["value"]
410407

411408
# Assert max_burn is 100 TAO from default
412-
assert Balance.from_tao(float(max_burn_tao)) == Balance.from_tao(100.0)
409+
assert Balance.from_rao(int(max_burn_tao)) == Balance.from_tao(100.0)
413410

414411
hyperparams_json = exec_command_alice(
415412
command="sudo",
@@ -468,7 +465,11 @@ def test_staking(local_chain, wallet_setup):
468465

469466
# Parse updated hyperparameters
470467
all_updated_hyperparams = updated_hyperparams.stdout.splitlines()
471-
updated_max_burn_tao = all_updated_hyperparams[22].split()[2].strip("\u200e")
468+
updated_max_burn_tao = (
469+
next(filter(lambda x: x[3:11] == "max_burn", all_updated_hyperparams))
470+
.split()[2]
471+
.strip("\u200e")
472+
)
472473

473474
# Assert max_burn is now 10 TAO
474475
assert Balance.from_tao(float(updated_max_burn_tao)) == Balance.from_tao(10)

0 commit comments

Comments
 (0)