Skip to content

Commit

Permalink
Merge pull request #2452 from opentensor/feat/roman/apply-bittensor-c…
Browse files Browse the repository at this point in the history
…onsole

Apply BittensorConsole + logging refactoring
  • Loading branch information
roman-opentensor authored Nov 22, 2024
2 parents d0fec96 + 4e70f3a commit 279a82c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bittensor/core/extrinsics/async_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def register_extrinsic(
`True` if extrinsic was finalized or included in the block. If we did not wait for finalization/inclusion, the response is `True`.
"""

logging.debug("Checking subnet status")
logging.debug("[magenta]Checking subnet status... [/magenta]")
if not await subtensor.subnet_exists(netuid):
logging.error(
f":cross_mark: [red]Failed error:[/red] subnet [blue]{netuid}[/blue] does not exist."
Expand Down
12 changes: 4 additions & 8 deletions bittensor/utils/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,9 @@ def is_connected(substrate) -> bool:
)
def reconnect_with_retries(self):
"""Attempt to reconnect with retries using retry library."""
logging.info("Attempting to reconnect to substrate...")
logging.console.info("Attempting to reconnect to substrate...")
self._get_substrate()

old_level = logging.get_level()
logging.set_info()
logging.success("Connection successfully restored!")
logging.setLevel(old_level)
logging.console.success("Connection successfully restored!")

@wraps(func)
def wrapper(self, *args, **kwargs):
Expand All @@ -198,14 +194,14 @@ def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except WebSocketConnectionClosedException:
logging.warning(
logging.console.warning(
"WebSocket connection closed. Attempting to reconnect 5 times..."
)
try:
reconnect_with_retries(self)
return func(self, *args, **kwargs)
except ConnectionRefusedError:
logging.error("Unable to restore connection. Raising exception.")
logging.critical("Unable to restore connection. Raising exception.")
raise ConnectionRefusedError("Failed to reconnect to substrate.")

return wrapper
6 changes: 3 additions & 3 deletions tests/e2e_tests/test_dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def test_dendrite(local_chain):
AssertionError: If any of the checks or verifications fail
"""

logging.info("Testing test_dendrite")
logging.console.info("Testing test_dendrite")
netuid = 1

# Register root as Alice - the subnet owner
Expand Down Expand Up @@ -113,7 +113,7 @@ async def test_dendrite(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
logging.info("Neuron Alice is now validating")
logging.console.info("Neuron Alice is now validating")
await asyncio.sleep(
5
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
Expand All @@ -133,4 +133,4 @@ async def test_dendrite(local_chain):
assert updated_neuron.coldkey == bob_keypair.ss58_address
assert updated_neuron.pruning_score != 0

logging.info("✅ Passed test_dendrite")
logging.console.info("✅ Passed test_dendrite")
4 changes: 2 additions & 2 deletions tests/e2e_tests/test_liquid_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_liquid_alpha(local_chain):
"""
u16_max = 65535
netuid = 1
logging.info("Testing test_liquid_alpha_enabled")
logging.console.info("Testing test_liquid_alpha_enabled")

# Register root as Alice
keypair, alice_wallet = setup_wallet("//Alice")
Expand Down Expand Up @@ -183,4 +183,4 @@ def test_liquid_alpha(local_chain):
assert (
subtensor.get_subnet_hyperparameters(netuid=1).liquid_alpha_enabled is False
), "Failed to disable liquid alpha"
logging.info("✅ Passed test_liquid_alpha")
logging.console.info("✅ Passed test_liquid_alpha")
4 changes: 2 additions & 2 deletions tests/e2e_tests/test_metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_metagraph(local_chain):
Raises:
AssertionError: If any of the checks or verifications fail
"""
logging.info("Testing test_metagraph_command")
logging.console.info("Testing test_metagraph_command")
netuid = 1

# Register Alice, Bob, and Dave
Expand Down Expand Up @@ -174,4 +174,4 @@ def test_metagraph(local_chain):
metagraph.neurons == metagraph_pre_dave.neurons
), "Neurons don't match after save and load"

logging.info("✅ Passed test_metagraph")
logging.console.info("✅ Passed test_metagraph")
2 changes: 1 addition & 1 deletion tests/unit_tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def normalize_hyperparameters(
else:
norm_value = value
except Exception as e:
logging.warning(f"Error normalizing parameter '{param}': {e}")
logging.console.error(f"Error normalizing parameter '{param}': {e}")
norm_value = "-"

normalized_values.append((param, str(value), str(norm_value)))
Expand Down

0 comments on commit 279a82c

Please sign in to comment.