Skip to content

Commit

Permalink
Use Charfield for hyperparameter values
Browse files Browse the repository at this point in the history
  • Loading branch information
olzhasar-reef committed May 6, 2024
1 parent 7ed0f44 commit 4d42faf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/src/bittensor_panel/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-05-06 16:07
# Generated by Django 4.2.11 on 2024-05-06 18:02

from django.db import migrations, models

Expand All @@ -24,7 +24,7 @@ class Migration(migrations.Migration):
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("name", models.CharField(max_length=255, unique=True)),
("value", models.DecimalField(decimal_places=0, max_digits=32)),
("value", models.CharField(max_length=255)),
],
),
]
2 changes: 1 addition & 1 deletion app/src/bittensor_panel/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class HyperParameter(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=255, unique=True)
value = models.DecimalField(max_digits=32, decimal_places=0)
value = models.CharField(max_length=255)
2 changes: 1 addition & 1 deletion app/src/bittensor_panel/core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def update_hyperparam(instance: HyperParameter) -> None:
Update hyperparameter in the subtensor with the new value and save changes to the database.
"""

result = update_remote_hyperparam(instance.name, int(instance.value))
result = update_remote_hyperparam(instance.name, instance.value)

if not result:
raise HyperParameterUpdateFailed("Failed to update remote hyperparameter. Subtensor returned False.")
Expand Down
8 changes: 6 additions & 2 deletions app/src/bittensor_panel/core/tests/test_bt.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def mock_wallet(mocker: MockerFixture):


@pytest.mark.parametrize("result", [True, False])
def test_update_remote_hyperparam(mock_subtensor: MagicMock, mock_wallet: MagicMock, result: bool, settings):
def test_update_remote_hyperparam(
mock_subtensor: MagicMock, mock_wallet: MagicMock, result: bool, settings
):
mock_subtensor.return_value.set_hyperparameter.return_value = result

name = "difficulty"
Expand All @@ -134,7 +136,9 @@ def test_update_remote_hyperparam(mock_subtensor: MagicMock, mock_wallet: MagicM
)


def test_update_remote_hyperparam_exception(mock_subtensor: MagicMock, mock_wallet: MagicMock):
def test_update_remote_hyperparam_exception(
mock_subtensor: MagicMock, mock_wallet: MagicMock
):
mock_subtensor.return_value.set_hyperparameter.side_effect = RuntimeError

with pytest.raises(SubtensorServerError):
Expand Down
14 changes: 8 additions & 6 deletions app/src/bittensor_panel/core/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
def hyperparam():
return HyperParameter.objects.create(
name="test",
value=123,
value="123",
)


Expand All @@ -34,7 +34,7 @@ def test_update_hyperparam(
):
mock_update_remote_hyperparam.return_value = True

new_value = 999
new_value = "999"

hyperparam.value = new_value

Expand All @@ -54,7 +54,7 @@ def test_update_hyperparam_remote_returns_false(
):
mock_update_remote_hyperparam.return_value = False

hyperparam.value = 999
hyperparam.value = "999"

with django_assert_num_queries(0):
with pytest.raises(HyperParameterUpdateFailed):
Expand All @@ -68,7 +68,7 @@ def test_update_hyperparam_remote_exception(
):
mock_update_remote_hyperparam.side_effect = RuntimeError

hyperparam.value = 999
hyperparam.value = "999"

with django_assert_num_queries(0):
with pytest.raises(RuntimeError):
Expand All @@ -77,12 +77,14 @@ def test_update_hyperparam_remote_exception(

@pytest.fixture
def hyperparam_dict(faker: Faker):
return {faker.word(): faker.pyint() for _ in range(10)}
return {faker.word(): str(faker.pyint()) for _ in range(10)}


@pytest.fixture
def mock_load_hyperparams(mocker: MockerFixture, hyperparam_dict: dict[str, int]):
return mocker.patch("bittensor_panel.core.services.load_hyperparams", return_value=hyperparam_dict)
return mocker.patch(
"bittensor_panel.core.services.load_hyperparams", return_value=hyperparam_dict
)


def test_refresh_hyperparams(
Expand Down

0 comments on commit 4d42faf

Please sign in to comment.