From e0281d14178186dcd85863d3cd5d82229baa55b8 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 20 Nov 2024 16:42:20 -0800 Subject: [PATCH 1/2] apply BittensorConsole + logging refactoring --- bittensor/core/extrinsics/async_registration.py | 2 +- bittensor/utils/networking.py | 12 ++++-------- tests/e2e_tests/test_dendrite.py | 6 +++--- tests/e2e_tests/test_liquid_alpha.py | 4 ++-- tests/e2e_tests/test_metagraph.py | 4 ++-- tests/unit_tests/test_subtensor.py | 2 +- tests/unit_tests/utils/test_weight_utils.py | 2 +- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/bittensor/core/extrinsics/async_registration.py b/bittensor/core/extrinsics/async_registration.py index 0b2289b823..e9d5aff5e5 100644 --- a/bittensor/core/extrinsics/async_registration.py +++ b/bittensor/core/extrinsics/async_registration.py @@ -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." diff --git a/bittensor/utils/networking.py b/bittensor/utils/networking.py index 7524b353f5..fdf0e8e913 100644 --- a/bittensor/utils/networking.py +++ b/bittensor/utils/networking.py @@ -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): @@ -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 diff --git a/tests/e2e_tests/test_dendrite.py b/tests/e2e_tests/test_dendrite.py index adb15b8369..ee4dc745c5 100644 --- a/tests/e2e_tests/test_dendrite.py +++ b/tests/e2e_tests/test_dendrite.py @@ -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 @@ -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 @@ -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") diff --git a/tests/e2e_tests/test_liquid_alpha.py b/tests/e2e_tests/test_liquid_alpha.py index 2e05dcf3e2..5f8f15cde6 100644 --- a/tests/e2e_tests/test_liquid_alpha.py +++ b/tests/e2e_tests/test_liquid_alpha.py @@ -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") @@ -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") diff --git a/tests/e2e_tests/test_metagraph.py b/tests/e2e_tests/test_metagraph.py index 3dd88a0128..f06f79a09b 100644 --- a/tests/e2e_tests/test_metagraph.py +++ b/tests/e2e_tests/test_metagraph.py @@ -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 @@ -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") diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py index 602a3027d8..43ddbfd93f 100644 --- a/tests/unit_tests/test_subtensor.py +++ b/tests/unit_tests/test_subtensor.py @@ -371,7 +371,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))) diff --git a/tests/unit_tests/utils/test_weight_utils.py b/tests/unit_tests/utils/test_weight_utils.py index 74009434b9..02e5fffbde 100644 --- a/tests/unit_tests/utils/test_weight_utils.py +++ b/tests/unit_tests/utils/test_weight_utils.py @@ -411,7 +411,7 @@ def test_convert_root_weight_uids_and_vals_to_tensor_edge_cases( def test_convert_root_weight_uids_and_vals_to_tensor_error_cases( test_id, n, uids, weights, subnets, exception, caplog ): - with caplog.at_level(logging.WARNING): + with caplog.at_level(logging.warning): weight_utils.convert_root_weight_uids_and_vals_to_tensor( n, uids, weights, subnets ) From 937065f2b95090570e6dc34d21f566aa21f8b233 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 20 Nov 2024 17:37:53 -0800 Subject: [PATCH 2/2] apply BittensorConsole + logging refactoring --- tests/unit_tests/utils/test_weight_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/utils/test_weight_utils.py b/tests/unit_tests/utils/test_weight_utils.py index 02e5fffbde..74009434b9 100644 --- a/tests/unit_tests/utils/test_weight_utils.py +++ b/tests/unit_tests/utils/test_weight_utils.py @@ -411,7 +411,7 @@ def test_convert_root_weight_uids_and_vals_to_tensor_edge_cases( def test_convert_root_weight_uids_and_vals_to_tensor_error_cases( test_id, n, uids, weights, subnets, exception, caplog ): - with caplog.at_level(logging.warning): + with caplog.at_level(logging.WARNING): weight_utils.convert_root_weight_uids_and_vals_to_tensor( n, uids, weights, subnets )