From 45296899f35300f6f47a4ec8454818ac46032dc4 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 31 Oct 2024 20:36:29 -0700 Subject: [PATCH 1/8] replace `rich.console` to `btlogging.logging` --- bittensor/core/extrinsics/prometheus.py | 93 ++++--- bittensor/core/extrinsics/registration.py | 245 ++++++++---------- bittensor/core/extrinsics/root.py | 128 ++++----- bittensor/core/extrinsics/serving.py | 5 +- bittensor/core/extrinsics/set_weights.py | 65 +++-- bittensor/core/extrinsics/transfer.py | 95 ++++--- bittensor/core/metagraph.py | 9 +- bittensor/core/settings.py | 30 --- bittensor/core/subtensor.py | 4 +- bittensor/utils/btlogging/format.py | 4 + bittensor/utils/btlogging/loggingmachine.py | 13 +- bittensor/utils/registration.py | 12 +- tests/helpers/__init__.py | 1 - tests/helpers/helpers.py | 101 ++++---- .../test_subtensor_integration.py | 24 +- 15 files changed, 368 insertions(+), 461 deletions(-) diff --git a/bittensor/core/extrinsics/prometheus.py b/bittensor/core/extrinsics/prometheus.py index a6ab1cfb16..124b259b88 100644 --- a/bittensor/core/extrinsics/prometheus.py +++ b/bittensor/core/extrinsics/prometheus.py @@ -21,7 +21,7 @@ from retry import retry from bittensor.core.extrinsics.utils import submit_extrinsic -from bittensor.core.settings import version_as_int, bt_console +from bittensor.core.settings import version_as_int from bittensor.utils import networking as net, format_error_message from bittensor.utils.btlogging import logging from bittensor.utils.networking import ensure_connected @@ -113,10 +113,9 @@ def prometheus_extrinsic( if ip is None: try: external_ip = net.get_external_ip() - bt_console.print( - f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]" + logging.success( + f":white_heavy_check_mark: Found external ip: {external_ip}" ) - logging.success(prefix="External IP", suffix="{external_ip}") except Exception as e: raise RuntimeError( f"Unable to attain your external ip. Check your internet connection. error: {e}" @@ -131,57 +130,53 @@ def prometheus_extrinsic( "ip_type": net.ip_version(external_ip), } - with bt_console.status(":satellite: Checking Prometheus..."): - neuron = subtensor.get_neuron_for_pubkey_and_subnet( - wallet.hotkey.ss58_address, netuid=netuid - ) - neuron_up_to_date = not neuron.is_null and call_params == { - "version": neuron.prometheus_info.version, - "ip": net.ip_to_int(neuron.prometheus_info.ip), - "port": neuron.prometheus_info.port, - "ip_type": neuron.prometheus_info.ip_type, - } + logging.info(":satellite: Checking Prometheus...") + neuron = subtensor.get_neuron_for_pubkey_and_subnet( + wallet.hotkey.ss58_address, netuid=netuid + ) + neuron_up_to_date = not neuron.is_null and call_params == { + "version": neuron.prometheus_info.version, + "ip": net.ip_to_int(neuron.prometheus_info.ip), + "port": neuron.prometheus_info.port, + "ip_type": neuron.prometheus_info.ip_type, + } if neuron_up_to_date: - bt_console.print( - f":white_heavy_check_mark: [green]Prometheus already Served[/green]\n" - f"[green not bold]- Status: [/green not bold] |" - f"[green not bold] ip: [/green not bold][white not bold]{neuron.prometheus_info.ip}[/white not bold] |" - f"[green not bold] ip_type: [/green not bold][white not bold]{neuron.prometheus_info.ip_type}[/white not bold] |" - f"[green not bold] port: [/green not bold][white not bold]{neuron.prometheus_info.port}[/white not bold] | " - f"[green not bold] version: [/green not bold][white not bold]{neuron.prometheus_info.version}[/white not bold] |" - ) - - bt_console.print( - f":white_heavy_check_mark: [white]Prometheus already served.[/white]" + logging.info( + ":white_heavy_check_mark: Prometheus already Served" ) + logging.info("Status:") + logging.info(f"\tip: {neuron.prometheus_info.ip}") + logging.info(f"\tip_type: {neuron.prometheus_info.ip_type}") + logging.info(f"\tport: {neuron.prometheus_info.port}") + logging.info(f"\tversion: {neuron.prometheus_info.version}") return True # Add netuid, not in prometheus_info call_params["netuid"] = netuid - with bt_console.status( - f":satellite: Serving prometheus on: [white]{subtensor.network}:{netuid}[/white] ..." - ): - success, error_message = do_serve_prometheus( - self=subtensor, - wallet=wallet, - call_params=call_params, - wait_for_finalization=wait_for_finalization, - wait_for_inclusion=wait_for_inclusion, - ) - - if wait_for_inclusion or wait_for_finalization: - if success is True: - json_ = json.dumps(call_params, indent=4, sort_keys=True) - bt_console.print( - f":white_heavy_check_mark: [green]Served prometheus[/green]\n [bold white]{json_}[/bold white]" - ) - return True - else: - bt_console.print( - f":cross_mark: [red]Failed[/red]: {format_error_message(error_message)}" - ) - return False - else: + logging.info( + f":satellite: Serving prometheus on: {subtensor.network}:{netuid} " + ) + success, error_message = do_serve_prometheus( + self=subtensor, + wallet=wallet, + call_params=call_params, + wait_for_finalization=wait_for_finalization, + wait_for_inclusion=wait_for_inclusion, + ) + + if wait_for_inclusion or wait_for_finalization: + if success is True: + json_ = json.dumps(call_params, indent=4, sort_keys=True) + logging.info( + f":white_heavy_check_mark: Served prometheus: {json_}" + ) return True + else: + logging.error( + f":cross_mark: Failed: {format_error_message(error_message)}" + ) + return False + else: + return True diff --git a/bittensor/core/extrinsics/registration.py b/bittensor/core/extrinsics/registration.py index 2528368094..cd4807ab88 100644 --- a/bittensor/core/extrinsics/registration.py +++ b/bittensor/core/extrinsics/registration.py @@ -22,7 +22,6 @@ from retry import retry from rich.prompt import Confirm -from bittensor.core.settings import bt_console from bittensor.utils import format_error_message from bittensor.utils.btlogging import logging from bittensor.utils.networking import ensure_connected @@ -142,24 +141,20 @@ def register_extrinsic( Flag is ``true`` if extrinsic was finalized or uncluded in the block. If we did not wait for finalization / inclusion, the response is ``true``. """ if not subtensor.subnet_exists(netuid): - bt_console.print( - ":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{}[/bold white] does not exist.".format( - netuid - ) + logging.error( + f":cross_mark: Failed: Subnet {netuid} does not exist." ) return False - with bt_console.status( - f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]..." - ): - neuron = subtensor.get_neuron_for_pubkey_and_subnet( - wallet.hotkey.ss58_address, netuid=netuid + logging.info(f":satellite: Checking Account on subnet {netuid}...") + neuron = subtensor.get_neuron_for_pubkey_and_subnet( + wallet.hotkey.ss58_address, netuid=netuid + ) + if not neuron.is_null: + logging.debug( + f"Wallet {wallet} is already registered on {neuron.netuid} with {neuron.uid}." ) - if not neuron.is_null: - logging.debug( - f"Wallet {wallet} is already registered on {neuron.netuid} with {neuron.uid}" - ) - return True + return True if prompt: if not Confirm.ask( @@ -178,14 +173,14 @@ def register_extrinsic( # Attempt rolling registration. attempts = 1 while True: - bt_console.print( - ":satellite: Registering...({}/{})".format(attempts, max_allowed_attempts) + logging.info( + f":satellite: Registering...({attempts}/{max_allowed_attempts})" ) # Solve latest POW. if cuda: if not torch.cuda.is_available(): if prompt: - bt_console.print("CUDA is not available.") + logging.info("CUDA is not available.") return False pow_result: Optional[POWSolution] = create_pow( subtensor, @@ -218,73 +213,71 @@ def register_extrinsic( netuid=netuid, hotkey_ss58=wallet.hotkey.ss58_address ) if is_registered: - bt_console.print( - f":white_heavy_check_mark: [green]Already registered on netuid:{netuid}[/green]" + logging.info( + f":white_heavy_check_mark: Already registered on netuid:{netuid}" ) return True # pow successful, proceed to submit pow to chain for registration else: - with bt_console.status(":satellite: Submitting POW..."): - # check if pow result is still valid - while not pow_result.is_stale(subtensor=subtensor): - result: tuple[bool, Optional[str]] = _do_pow_register( - self=subtensor, - netuid=netuid, - wallet=wallet, - pow_result=pow_result, - wait_for_inclusion=wait_for_inclusion, - wait_for_finalization=wait_for_finalization, - ) - success, err_msg = result - - if not success: - # Look error here - # https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs - if "HotKeyAlreadyRegisteredInSubNet" in err_msg: - bt_console.print( - f":white_heavy_check_mark: [green]Already Registered on [bold]subnet:{netuid}[/bold][/green]" - ) - return True + logging.info(":satellite: Submitting POW...") + # check if pow result is still valid + while not pow_result.is_stale(subtensor=subtensor): + result: tuple[bool, Optional[str]] = _do_pow_register( + self=subtensor, + netuid=netuid, + wallet=wallet, + pow_result=pow_result, + wait_for_inclusion=wait_for_inclusion, + wait_for_finalization=wait_for_finalization, + ) + success, err_msg = result + + if not success: + # Look error here + # https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs + if "HotKeyAlreadyRegisteredInSubNet" in err_msg: + logging.info( + f":white_heavy_check_mark: Already Registered on subnet {netuid}." + ) + return True - bt_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") - time.sleep(0.5) + logging.error(f":cross_mark: Failed: {err_msg}") + time.sleep(0.5) - # Successful registration, final check for neuron and pubkey + # Successful registration, final check for neuron and pubkey + else: + logging.info(":satellite: Checking Balance...") + is_registered = subtensor.is_hotkey_registered( + hotkey_ss58=wallet.hotkey.ss58_address, + netuid=netuid, + ) + if is_registered: + logging.info( + ":white_heavy_check_mark: Registered" + ) + return True else: - bt_console.print(":satellite: Checking Balance...") - is_registered = subtensor.is_hotkey_registered( - hotkey_ss58=wallet.hotkey.ss58_address, - netuid=netuid, + # neuron not found, try again + logging.error( + ":cross_mark: Unknown error. Neuron not found." ) - if is_registered: - bt_console.print( - ":white_heavy_check_mark: [green]Registered[/green]" - ) - return True - else: - # neuron not found, try again - bt_console.print( - ":cross_mark: [red]Unknown error. Neuron not found.[/red]" - ) - continue - else: - # Exited loop because pow is no longer valid. - bt_console.print("[red]POW is stale.[/red]") - # Try again. - continue + continue + else: + # Exited loop because pow is no longer valid. + logging.error("POW is stale.") + # Try again. + continue if attempts < max_allowed_attempts: # Failed registration, retry pow attempts += 1 - bt_console.print( - ":satellite: Failed registration, retrying pow ...({}/{})".format( - attempts, max_allowed_attempts - ) + logging.info( + f":satellite: Failed registration, retrying pow ...({attempts}/{max_allowed_attempts})" ) else: # Failed to register after max attempts. - bt_console.print("[red]No more attempts.[/red]") + logging.error("No more attempts.") return False @@ -370,82 +363,70 @@ def burned_register_extrinsic( success (bool): Flag is ``true`` if extrinsic was finalized or uncluded in the block. If we did not wait for finalization / inclusion, the response is ``true``. """ if not subtensor.subnet_exists(netuid): - bt_console.print( - ":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{}[/bold white] does not exist.".format( - netuid - ) + logging.error( + f":cross_mark: Failed error: subnet {netuid} does not exist." ) return False try: wallet.unlock_coldkey() except KeyFileError: - bt_console.print( - ":cross_mark: [red]Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid[/red]:[bold white]\n [/bold white]" + logging.error( + ":cross_mark: Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid." ) return False - with bt_console.status( - f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]..." - ): - neuron = subtensor.get_neuron_for_pubkey_and_subnet( - wallet.hotkey.ss58_address, netuid=netuid - ) - - old_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address) - - recycle_amount = subtensor.recycle(netuid=netuid) - if not neuron.is_null: - bt_console.print( - ":white_heavy_check_mark: [green]Already Registered[/green]:\n" - "uid: [bold white]{}[/bold white]\n" - "netuid: [bold white]{}[/bold white]\n" - "hotkey: [bold white]{}[/bold white]\n" - "coldkey: [bold white]{}[/bold white]".format( - neuron.uid, neuron.netuid, neuron.hotkey, neuron.coldkey - ) - ) - return True + logging.info( + f":satellite: Checking Account on subnet {netuid} ..." + ) + neuron = subtensor.get_neuron_for_pubkey_and_subnet( + wallet.hotkey.ss58_address, netuid=netuid + ) + + old_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address) + + recycle_amount = subtensor.recycle(netuid=netuid) + if not neuron.is_null: + logging.info(":white_heavy_check_mark: Already Registered") + logging.info(f"\t\tuid: {neuron.uid}") + logging.info(f"\t\tnetuid: {neuron.netuid}") + logging.info(f"\t\thotkey: {neuron.hotkey}") + logging.info(f"\t\tcoldkey: {neuron.coldkey}") + return True if prompt: # Prompt user for confirmation. if not Confirm.ask(f"Recycle {recycle_amount} to register on subnet:{netuid}?"): return False - with bt_console.status(":satellite: Recycling TAO for Registration..."): - success, err_msg = _do_burned_register( - self=subtensor, - netuid=netuid, - wallet=wallet, - wait_for_inclusion=wait_for_inclusion, - wait_for_finalization=wait_for_finalization, + logging.info(":satellite: Recycling TAO for Registration...") + success, err_msg = _do_burned_register( + self=subtensor, + netuid=netuid, + wallet=wallet, + wait_for_inclusion=wait_for_inclusion, + wait_for_finalization=wait_for_finalization, + ) + + if not success: + logging.error(f":cross_mark: Failed: {err_msg}") + time.sleep(0.5) + return False + # Successful registration, final check for neuron and pubkey + else: + logging.info(":satellite: Checking Balance...") + block = subtensor.get_current_block() + new_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address, block=block) + + logging.info( + f"Balance: {old_balance} :arrow_right: {new_balance}" ) - - if not success: - bt_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") - time.sleep(0.5) - return False - # Successful registration, final check for neuron and pubkey + is_registered = subtensor.is_hotkey_registered( + netuid=netuid, hotkey_ss58=wallet.hotkey.ss58_address + ) + if is_registered: + logging.info(":white_heavy_check_mark: Registered") + return True else: - bt_console.print(":satellite: Checking Balance...") - block = subtensor.get_current_block() - new_balance = subtensor.get_balance( - wallet.coldkeypub.ss58_address, block=block - ) - - bt_console.print( - "Balance:\n [blue]{}[/blue] :arrow_right: [green]{}[/green]".format( - old_balance, new_balance - ) - ) - is_registered = subtensor.is_hotkey_registered( - netuid=netuid, hotkey_ss58=wallet.hotkey.ss58_address - ) - if is_registered: - bt_console.print(":white_heavy_check_mark: [green]Registered[/green]") - return True - else: - # neuron not found, try again - bt_console.print( - ":cross_mark: [red]Unknown error. Neuron not found.[/red]" - ) - return False + # neuron not found, try again + logging.error(":cross_mark: Unknown error. Neuron not found.") + return False diff --git a/bittensor/core/extrinsics/root.py b/bittensor/core/extrinsics/root.py index 1fd7e7b26e..32df5dbea4 100644 --- a/bittensor/core/extrinsics/root.py +++ b/bittensor/core/extrinsics/root.py @@ -7,7 +7,7 @@ from retry import retry from rich.prompt import Confirm -from bittensor.core.settings import bt_console, version_as_int +from bittensor.core.settings import version_as_int from bittensor.utils import format_error_message, weight_utils from bittensor.utils.btlogging import logging from bittensor.utils.networking import ensure_connected @@ -80,8 +80,8 @@ def root_register_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: - bt_console.print( - ":cross_mark: [red]Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid[/red]:[bold white]\n [/bold white]" + logging.error( + "Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid." ) return False @@ -89,9 +89,7 @@ def root_register_extrinsic( netuid=0, hotkey_ss58=wallet.hotkey.ss58_address ) if is_registered: - bt_console.print( - ":white_heavy_check_mark: [green]Already registered on root network.[/green]" - ) + logging.info("Already registered on root network.") return True if prompt: @@ -99,30 +97,28 @@ def root_register_extrinsic( if not Confirm.ask("Register to root network?"): return False - with bt_console.status(":satellite: Registering to root network..."): - success, err_msg = _do_root_register( - wallet=wallet, - wait_for_inclusion=wait_for_inclusion, - wait_for_finalization=wait_for_finalization, - ) + logging.info(":satellite: Registering to root network...") + success, err_msg = _do_root_register( + wallet=wallet, + wait_for_inclusion=wait_for_inclusion, + wait_for_finalization=wait_for_finalization, + ) - if not success: - bt_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") - time.sleep(0.5) + if not success: + logging.error(f"Failed: {err_msg}") + time.sleep(0.5) - # Successful registration, final check for neuron and pubkey + # Successful registration, final check for neuron and pubkey + else: + is_registered = subtensor.is_hotkey_registered( + netuid=0, hotkey_ss58=wallet.hotkey.ss58_address + ) + if is_registered: + logging.success(":white_heavy_check_mark: Registered") + return True else: - is_registered = subtensor.is_hotkey_registered( - netuid=0, hotkey_ss58=wallet.hotkey.ss58_address - ) - if is_registered: - bt_console.print(":white_heavy_check_mark: [green]Registered[/green]") - return True - else: - # neuron not found, try again - bt_console.print( - ":cross_mark: [red]Unknown error. Neuron not found.[/red]" - ) + # neuron not found, try again + logging.error(":cross_mark: Unknown error. Neuron not found.") @ensure_connected @@ -222,8 +218,8 @@ def set_root_weights_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: - bt_console.print( - ":cross_mark: [red]Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid[/red]:[bold white]\n [/bold white]" + logging.error( + ":cross_mark: Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid." ) return False @@ -252,8 +248,8 @@ def set_root_weights_extrinsic( formatted_weights = weight_utils.normalize_max_weight( x=weights, limit=max_weight_limit ) - bt_console.print( - f"\nRaw Weights -> Normalized weights: \n\t{weights} -> \n\t{formatted_weights}\n" + logging.info( + f"Raw Weights -> Normalized weights: {weights} -> {formatted_weights}" ) # Ask before moving on. @@ -265,46 +261,36 @@ def set_root_weights_extrinsic( ): return False - with bt_console.status( - ":satellite: Setting root weights on [white]{}[/white] ...".format( - subtensor.network + logging.info( + f":satellite: Setting root weights on {subtensor.network} ..." + ) + try: + weight_uids, weight_vals = weight_utils.convert_weights_and_uids_for_emit( + netuids, weights ) - ): - try: - weight_uids, weight_vals = weight_utils.convert_weights_and_uids_for_emit( - netuids, weights - ) - success, error_message = _do_set_root_weights( - wallet=wallet, - netuid=0, - uids=weight_uids, - vals=weight_vals, - version_key=version_key, - wait_for_finalization=wait_for_finalization, - wait_for_inclusion=wait_for_inclusion, - ) + success, error_message = _do_set_root_weights( + wallet=wallet, + netuid=0, + uids=weight_uids, + vals=weight_vals, + version_key=version_key, + wait_for_finalization=wait_for_finalization, + wait_for_inclusion=wait_for_inclusion, + ) + + if not wait_for_finalization and not wait_for_inclusion: + return True - bt_console.print(success, error_message) - - if not wait_for_finalization and not wait_for_inclusion: - return True - - if success is True: - bt_console.print(":white_heavy_check_mark: [green]Finalized[/green]") - logging.success( - prefix="Set weights", - suffix="Finalized: " + str(success), - ) - return True - else: - bt_console.print(f":cross_mark: [red]Failed[/red]: {error_message}") - logging.warning( - prefix="Set weights", - suffix="Failed: " + str(error_message), - ) - return False - - except Exception as e: - bt_console.print(":cross_mark: [red]Failed[/red]: error:{}".format(e)) - logging.warning(prefix="Set weights", suffix="Failed: " + str(e)) + if success is True: + logging.info(":white_heavy_check_mark: Finalized") + logging.success(f"Set weights {str(success)}") + return True + else: + logging.error( + f":cross_mark: Failed set weights. {str(error_message)}" + ) return False + + except Exception as e: + logging.error(f":cross_mark: Failed set weights. {str(e)}") + return False diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index 490f9c268e..72b9484d4d 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -23,7 +23,7 @@ from bittensor.core.errors import MetadataError from bittensor.core.extrinsics.utils import submit_extrinsic -from bittensor.core.settings import version_as_int, bt_console +from bittensor.core.settings import version_as_int from bittensor.utils import format_error_message, networking as net from bittensor.utils.btlogging import logging from bittensor.utils.networking import ensure_connected @@ -219,9 +219,6 @@ def serve_axon_extrinsic( if axon.external_ip is None: try: external_ip = net.get_external_ip() - bt_console.print( - f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]" - ) logging.success(prefix="External IP", suffix=f"{external_ip}") except Exception as e: raise RuntimeError( diff --git a/bittensor/core/extrinsics/set_weights.py b/bittensor/core/extrinsics/set_weights.py index 7680061c5b..e73f264578 100644 --- a/bittensor/core/extrinsics/set_weights.py +++ b/bittensor/core/extrinsics/set_weights.py @@ -24,7 +24,7 @@ from rich.prompt import Confirm from bittensor.core.extrinsics.utils import submit_extrinsic -from bittensor.core.settings import bt_console, version_as_int +from bittensor.core.settings import version_as_int from bittensor.utils import format_error_message, weight_utils from bittensor.utils.btlogging import logging from bittensor.utils.networking import ensure_connected @@ -157,38 +157,31 @@ def set_weights_extrinsic( ): return False, "Prompt refused." - with bt_console.status( - f":satellite: Setting weights on [white]{subtensor.network}[/white] ..." - ): - try: - success, error_message = do_set_weights( - self=subtensor, - wallet=wallet, - netuid=netuid, - uids=weight_uids, - vals=weight_vals, - version_key=version_key, - wait_for_finalization=wait_for_finalization, - wait_for_inclusion=wait_for_inclusion, - ) - - if not wait_for_finalization and not wait_for_inclusion: - return True, "Not waiting for finalization or inclusion." - - if success is True: - bt_console.print(":white_heavy_check_mark: [green]Finalized[/green]") - logging.success( - msg=str(success), - prefix="Set weights", - suffix="Finalized: ", - ) - return True, "Successfully set weights and Finalized." - else: - error_message = format_error_message(error_message) - logging.error(error_message) - return False, error_message - - except Exception as e: - bt_console.print(f":cross_mark: [red]Failed[/red]: error:{e}") - logging.debug(str(e)) - return False, str(e) + logging.info(f":satellite: Setting weights on {subtensor.network} ...") + try: + success, error_message = do_set_weights( + self=subtensor, + wallet=wallet, + netuid=netuid, + uids=weight_uids, + vals=weight_vals, + version_key=version_key, + wait_for_finalization=wait_for_finalization, + wait_for_inclusion=wait_for_inclusion, + ) + + if not wait_for_finalization and not wait_for_inclusion: + return True, "Not waiting for finalization or inclusion." + + if success is True: + logging.success(f"Finalized! Set weights: {str(success)}") + return True, "Successfully set weights and Finalized." + else: + error_message = format_error_message(error_message) + logging.error(error_message) + return False, error_message + + except Exception as e: + logging.error(f":cross_mark: Failed.: Error: {e}") + logging.debug(str(e)) + return False, str(e) diff --git a/bittensor/core/extrinsics/transfer.py b/bittensor/core/extrinsics/transfer.py index 896fecbf96..ec232d323a 100644 --- a/bittensor/core/extrinsics/transfer.py +++ b/bittensor/core/extrinsics/transfer.py @@ -20,8 +20,9 @@ from retry import retry from rich.prompt import Confirm +from bittensor import logging from bittensor.core.extrinsics.utils import submit_extrinsic -from bittensor.core.settings import bt_console, NETWORK_EXPLORER_MAP +from bittensor.core.settings import NETWORK_EXPLORER_MAP from bittensor.utils import ( get_explorer_url_for_network, format_error_message, @@ -121,9 +122,7 @@ def transfer_extrinsic( """ # Validate destination address. if not is_valid_bittensor_address_or_public_key(dest): - bt_console.print( - f":cross_mark: [red]Invalid destination address[/red]:[bold white]\n {dest}[/bold white]" - ) + logging.error(f"Invalid destination address: {dest}") return False if isinstance(dest, bytes): @@ -140,15 +139,15 @@ def transfer_extrinsic( transfer_balance = amount # Check balance. - with bt_console.status(":satellite: Checking Balance..."): - account_balance = subtensor.get_balance(wallet.coldkey.ss58_address) - # check existential deposit. - existential_deposit = subtensor.get_existential_deposit() - - with bt_console.status(":satellite: Transferring..."): - fee = subtensor.get_transfer_fee( - wallet=wallet, dest=dest, value=transfer_balance.rao - ) + logging.info(":satellite: Checking Balance...") + account_balance = subtensor.get_balance(wallet.coldkey.ss58_address) + # check existential deposit. + existential_deposit = subtensor.get_existential_deposit() + + logging.info(":satellite: Transferring...") + fee = subtensor.get_transfer_fee( + wallet=wallet, dest=dest, value=transfer_balance.rao + ) if not keep_alive: # Check if the transfer should keep_alive the account @@ -156,12 +155,10 @@ def transfer_extrinsic( # Check if we have enough balance. if account_balance < (transfer_balance + fee + existential_deposit): - bt_console.print( - ":cross_mark: [red]Not enough balance[/red]:[bold white]\n" - f" balance: {account_balance}\n" - f" amount: {transfer_balance}\n" - f" for fee: {fee}[/bold white]" - ) + logging.error(":cross_mark: Not enough balance:") + logging.info(f"\t\tBalance: \t{account_balance}") + logging.info(f"\t\tAmount: \t{transfer_balance}") + logging.info(f"\t\tFor fee: \t{fee}") return False # Ask before moving on. @@ -175,41 +172,41 @@ def transfer_extrinsic( ): return False - with bt_console.status(":satellite: Transferring..."): - success, block_hash, error_message = do_transfer( - self=subtensor, - wallet=wallet, - dest=dest, - transfer_balance=transfer_balance, - wait_for_finalization=wait_for_finalization, - wait_for_inclusion=wait_for_inclusion, - ) + logging.info(":satellite: Transferring...") + success, block_hash, error_message = do_transfer( + self=subtensor, + wallet=wallet, + dest=dest, + transfer_balance=transfer_balance, + wait_for_finalization=wait_for_finalization, + wait_for_inclusion=wait_for_inclusion, + ) - if success: - bt_console.print(":white_heavy_check_mark: [green]Finalized[/green]") - bt_console.print(f"[green]Block Hash: {block_hash}[/green]") + if success: + logging.success(":white_heavy_check_mark: Finalized") + logging.info(f"Block Hash: {block_hash}") - explorer_urls = get_explorer_url_for_network( - subtensor.network, block_hash, NETWORK_EXPLORER_MAP + explorer_urls = get_explorer_url_for_network( + subtensor.network, block_hash, NETWORK_EXPLORER_MAP + ) + if explorer_urls != {} and explorer_urls: + logging.info( + f"Opentensor Explorer Link: {explorer_urls.get('opentensor')}" ) - if explorer_urls != {} and explorer_urls: - bt_console.print( - f"[green]Opentensor Explorer Link: {explorer_urls.get('opentensor')}[/green]" - ) - bt_console.print( - f"[green]Taostats Explorer Link: {explorer_urls.get('taostats')}[/green]" - ) - else: - bt_console.print( - f":cross_mark: [red]Failed[/red]: {format_error_message(error_message)}" + logging.info( + f"Taostats Explorer Link: {explorer_urls.get('taostats')}" ) + else: + logging.error( + f":cross_mark: Failed: {format_error_message(error_message)}" + ) if success: - with bt_console.status(":satellite: Checking Balance..."): - new_balance = subtensor.get_balance(wallet.coldkey.ss58_address) - bt_console.print( - f"Balance:\n [blue]{account_balance}[/blue] :arrow_right: [green]{new_balance}[/green]" - ) - return True + logging.info(":satellite: Checking Balance...") + new_balance = subtensor.get_balance(wallet.coldkey.ss58_address) + logging.success( + f"Balance: {account_balance} :arrow_right: {new_balance}" + ) + return True return False diff --git a/bittensor/core/metagraph.py b/bittensor/core/metagraph.py index 208eaa6b9f..75e8d947c9 100644 --- a/bittensor/core/metagraph.py +++ b/bittensor/core/metagraph.py @@ -1249,12 +1249,11 @@ def load_from_path(self, dir_path: str) -> "Metagraph": with open(graph_filename, "rb") as graph_file: state_dict = pickle.load(graph_file) except pickle.UnpicklingError: - settings.bt_console.print( + logging.info( "Unable to load file. Attempting to restore metagraph using torch." ) - settings.bt_console.print( - ":warning:[yellow]Warning:[/yellow] This functionality exists to load " - "metagraph state from legacy saves, but will not be supported in the future." + logging.warning( + ":warning: This functionality exists to load metagraph state from legacy saves, but will not be supported in the future." ) try: import torch as real_torch @@ -1264,7 +1263,7 @@ def load_from_path(self, dir_path: str) -> "Metagraph": state_dict[key] = state_dict[key].detach().numpy() del real_torch except (RuntimeError, ImportError): - settings.bt_console.print("Unable to load file. It may be corrupted.") + logging.error("Unable to load file. It may be corrupted.") raise self.n = state_dict["n"] diff --git a/bittensor/core/settings.py b/bittensor/core/settings.py index 29948b612e..2eb6d4f416 100644 --- a/bittensor/core/settings.py +++ b/bittensor/core/settings.py @@ -23,36 +23,6 @@ from pathlib import Path from munch import munchify -from rich.console import Console -from rich.traceback import install - -# Rich console. -__console__ = Console() -__use_console__ = True - -# Remove overdue locals in debug training. -install(show_locals=False) - - -def turn_console_off(): - global __use_console__ - global __console__ - from io import StringIO - - __use_console__ = False - __console__ = Console(file=StringIO(), stderr=False) - - -def turn_console_on(): - global __use_console__ - global __console__ - __use_console__ = True - __console__ = Console() - - -turn_console_off() - -bt_console = __console__ HOME_DIR = Path.home() diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index ac6c46bc46..cda8d007a2 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -1770,9 +1770,7 @@ def get_transfer_fee( call=call, keypair=wallet.coldkeypub ) except Exception as e: - settings.bt_console.print( - f":cross_mark: [red]Failed to get payment info[/red]:[bold white]\n {e}[/bold white]" - ) + logging.error(f"Failed to get payment info. {e}") payment_info = {"partialFee": int(2e7)} # assume 0.02 Tao fee = Balance.from_rao(payment_info["partialFee"]) diff --git a/bittensor/utils/btlogging/format.py b/bittensor/utils/btlogging/format.py index 1aa505c82c..9e279a3b26 100644 --- a/bittensor/utils/btlogging/format.py +++ b/bittensor/utils/btlogging/format.py @@ -54,6 +54,8 @@ def _success(self, message: str, *args, **kws): ":white_heavy_check_mark:": "✅", ":cross_mark:": "❌", ":satellite:": "🛰️", + ":warning:": "⚠️", + ":arrow_right:": "➡️", } @@ -64,6 +66,8 @@ def _success(self, message: str, *args, **kws): "": Style.RESET_ALL, "": Fore.GREEN, "": Style.RESET_ALL, + "": Fore.MAGENTA, + "": Style.RESET_ALL, } diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index abc4758bf8..66d7cc7595 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -49,7 +49,8 @@ def _concat_message(msg="", prefix="", suffix=""): """Concatenates a message with optional prefix and suffix.""" - msg = f"{f'{prefix} - ' if prefix else ''}{msg}{f' - {suffix}' if suffix else ''}" + empty_pref_suf = [None, ""] + msg = f"{f'{prefix} - ' if prefix not in empty_pref_suf else ''}{msg}{f' - {suffix}' if suffix not in empty_pref_suf else ''}" return msg @@ -443,27 +444,27 @@ def info(self, msg="", prefix="", suffix="", *args, **kwargs): def success(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps success message with prefix and suffix.""" - msg = f"{prefix} - {msg} - {suffix}" + msg = _concat_message(msg, prefix, suffix) self._logger.success(msg, *args, **kwargs) def warning(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps warning message with prefix and suffix.""" - msg = f"{prefix} - {msg} - {suffix}" + msg = _concat_message(msg, prefix, suffix) self._logger.warning(msg, *args, **kwargs) def error(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps error message with prefix and suffix.""" - msg = f"{prefix} - {msg} - {suffix}" + msg = _concat_message(msg, prefix, suffix) self._logger.error(msg, *args, **kwargs) def critical(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps critical message with prefix and suffix.""" - msg = f"{prefix} - {msg} - {suffix}" + msg = _concat_message(msg, prefix, suffix) self._logger.critical(msg, *args, **kwargs) def exception(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps exception message with prefix and suffix.""" - msg = f"{prefix} - {msg} - {suffix}" + msg = _concat_message(msg, prefix, suffix) self._logger.exception(msg, *args, **kwargs) def on(self): diff --git a/bittensor/utils/registration.py b/bittensor/utils/registration.py index 46c39d3d40..e0d2b20236 100644 --- a/bittensor/utils/registration.py +++ b/bittensor/utils/registration.py @@ -30,16 +30,22 @@ from queue import Empty, Full from typing import Any, Callable, Optional, Union, TYPE_CHECKING -import backoff import numpy from Crypto.Hash import keccak +from retry import retry from rich import console as rich_console, status as rich_status +from rich.console import Console +from rich.traceback import install -from bittensor.core.settings import bt_console from bittensor.utils.btlogging import logging from bittensor.utils.formatting import get_human_readable, millify from bittensor.utils.register_cuda import solve_cuda +# Console for `RegistrationStatisticsLogger` class +bt_console = Console() +# Remove overdue locals in debug training. +install(show_locals=False) + def use_torch() -> bool: """Force the use of torch over numpy for certain operations.""" @@ -735,7 +741,7 @@ def _solve_for_difficulty_fast( return solution -@backoff.on_exception(backoff.constant, Exception, interval=1, max_tries=3) +@retry(Exception, tries=3, delay=1) def _get_block_with_retry( subtensor: "Subtensor", netuid: int ) -> tuple[int, int, bytes]: diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py index f876d249bd..3c6badb91c 100644 --- a/tests/helpers/__init__.py +++ b/tests/helpers/__init__.py @@ -18,7 +18,6 @@ import os from .helpers import ( # noqa: F401 CLOSE_IN_VALUE, - MockConsole, __mock_wallet_factory__, ) from bittensor_wallet.mock.wallet_mock import ( # noqa: F401 diff --git a/tests/helpers/helpers.py b/tests/helpers/helpers.py index 417bd643b3..d7c9bf4402 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -22,14 +22,11 @@ from bittensor_wallet.mock.wallet_mock import get_mock_hotkey from bittensor_wallet.mock.wallet_mock import get_mock_wallet -from rich.console import Console -from rich.text import Text - from bittensor.utils.balance import Balance from bittensor.core.chain_data import AxonInfo, NeuronInfo, PrometheusInfo -def __mock_wallet_factory__(*args, **kwargs) -> _MockWallet: +def __mock_wallet_factory__(*_, **__) -> _MockWallet: """Returns a mock wallet object.""" mock_wallet = get_mock_wallet() @@ -120,51 +117,51 @@ def get_mock_neuron_by_uid(uid: int, **kwargs) -> NeuronInfo: ) -class MockStatus: - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, traceback): - pass - - def start(self): - pass - - def stop(self): - pass - - def update(self, *args, **kwargs): - MockConsole().print(*args, **kwargs) - - -class MockConsole: - """ - Mocks the console object for status and print. - Captures the last print output as a string. - """ - - captured_print = None - - def status(self, *args, **kwargs): - return MockStatus() - - def print(self, *args, **kwargs): - console = Console( - width=1000, no_color=True, markup=False - ) # set width to 1000 to avoid truncation - console.begin_capture() - console.print(*args, **kwargs) - self.captured_print = console.end_capture() - - def clear(self, *args, **kwargs): - pass - - @staticmethod - def remove_rich_syntax(text: str) -> str: - """ - Removes rich syntax from the given text. - Removes markup and ansi syntax. - """ - output_no_syntax = Text.from_ansi(Text.from_markup(text).plain).plain - - return output_no_syntax +# class MockStatus: +# def __enter__(self): +# return self +# +# def __exit__(self, exc_type, exc_value, traceback): +# pass +# +# def start(self): +# pass +# +# def stop(self): +# pass +# +# def update(self, *args, **kwargs): +# MockConsole().print(*args, **kwargs) +# +# +# class MockConsole: +# """ +# Mocks the console object for status and print. +# Captures the last print output as a string. +# """ +# +# captured_print = None +# +# def status(self, *args, **kwargs): +# return MockStatus() +# +# def print(self, *args, **kwargs): +# console = Console( +# width=1000, no_color=True, markup=False +# ) # set width to 1000 to avoid truncation +# console.begin_capture() +# console.print(*args, **kwargs) +# self.captured_print = console.end_capture() +# +# def clear(self, *args, **kwargs): +# pass +# +# @staticmethod +# def remove_rich_syntax(text: str) -> str: +# """ +# Removes rich syntax from the given text. +# Removes markup and ansi syntax. +# """ +# output_no_syntax = Text.from_ansi(Text.from_markup(text).plain).plain +# +# return output_no_syntax diff --git a/tests/integration_tests/test_subtensor_integration.py b/tests/integration_tests/test_subtensor_integration.py index 552e5ab993..bacb340f2c 100644 --- a/tests/integration_tests/test_subtensor_integration.py +++ b/tests/integration_tests/test_subtensor_integration.py @@ -30,7 +30,6 @@ from bittensor.utils.mock import MockSubtensor from tests.helpers import ( get_mock_coldkey, - MockConsole, get_mock_keypair, get_mock_wallet, ) @@ -52,12 +51,6 @@ def setUp(self): @classmethod def setUpClass(cls) -> None: - # mock rich console status - mock_console = MockConsole() - cls._mock_console_patcher = patch( - "bittensor.core.settings.bt_console", mock_console - ) - cls._mock_console_patcher.start() # Keeps the same mock network for all tests. This stops the network from being re-setup for each test. cls._mock_subtensor = MockSubtensor() cls._do_setup_subnet() @@ -69,10 +62,6 @@ def _do_setup_subnet(cls): # Setup the mock subnet 3 cls._mock_subtensor.create_subnet(netuid=3) - @classmethod - def tearDownClass(cls) -> None: - cls._mock_console_patcher.stop() - def test_network_overrides(self): """Tests that the network overrides the chain_endpoint.""" # Argument importance: chain_endpoint (arg) > network (arg) > config.subtensor.chain_endpoint > config.subtensor.network @@ -284,15 +273,10 @@ def test_registration_multiprocessed_already_registered(self): ) self.subtensor._do_pow_register = MagicMock(return_value=(True, None)) - with patch("bittensor.core.settings.bt_console") as mock_set_status: - # Need to patch the console status to avoid opening a parallel live display - mock_set_status.__enter__ = MagicMock(return_value=True) - mock_set_status.__exit__ = MagicMock(return_value=True) - - # should return True - assert self.subtensor.register( - wallet=wallet, netuid=3, num_processes=3, update_interval=5 - ) + # should return True + assert self.subtensor.register( + wallet=wallet, netuid=3, num_processes=3, update_interval=5 + ) # calls until True and once again before exiting subtensor class # This assertion is currently broken when difficulty is too low From 74d75f3b1ce5a28a312978e1bde76e7bb5dc84ea Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 31 Oct 2024 20:46:48 -0700 Subject: [PATCH 2/8] update requirements --- requirements/prod.txt | 1 - scripts/environments/apple_m1_environment.yml | 1 - tests/helpers/helpers.py | 50 ------------------- 3 files changed, 52 deletions(-) diff --git a/requirements/prod.txt b/requirements/prod.txt index bed65e9d2e..17c73f6f25 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -1,7 +1,6 @@ wheel setuptools~=70.0.0 aiohttp~=3.9 -backoff bittensor-cli bt-decode colorama~=0.4.6 diff --git a/scripts/environments/apple_m1_environment.yml b/scripts/environments/apple_m1_environment.yml index 25824aa64e..7d949c7e4e 100644 --- a/scripts/environments/apple_m1_environment.yml +++ b/scripts/environments/apple_m1_environment.yml @@ -126,7 +126,6 @@ dependencies: - argparse==1.4.0 - arrow==1.2.3 - async-timeout==4.0.2 - - backoff==2.1.0 - blinker==1.6.2 - cachetools==4.2.4 - certifi==2024.2.2 diff --git a/tests/helpers/helpers.py b/tests/helpers/helpers.py index d7c9bf4402..41109ee5e6 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -115,53 +115,3 @@ def get_mock_neuron_by_uid(uid: int, **kwargs) -> NeuronInfo: return get_mock_neuron( uid=uid, hotkey=get_mock_hotkey(uid), coldkey=get_mock_coldkey(uid), **kwargs ) - - -# class MockStatus: -# def __enter__(self): -# return self -# -# def __exit__(self, exc_type, exc_value, traceback): -# pass -# -# def start(self): -# pass -# -# def stop(self): -# pass -# -# def update(self, *args, **kwargs): -# MockConsole().print(*args, **kwargs) -# -# -# class MockConsole: -# """ -# Mocks the console object for status and print. -# Captures the last print output as a string. -# """ -# -# captured_print = None -# -# def status(self, *args, **kwargs): -# return MockStatus() -# -# def print(self, *args, **kwargs): -# console = Console( -# width=1000, no_color=True, markup=False -# ) # set width to 1000 to avoid truncation -# console.begin_capture() -# console.print(*args, **kwargs) -# self.captured_print = console.end_capture() -# -# def clear(self, *args, **kwargs): -# pass -# -# @staticmethod -# def remove_rich_syntax(text: str) -> str: -# """ -# Removes rich syntax from the given text. -# Removes markup and ansi syntax. -# """ -# output_no_syntax = Text.from_ansi(Text.from_markup(text).plain).plain -# -# return output_no_syntax From 7a66d9232516737ec46112a181cf37ac6a68896b Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 31 Oct 2024 20:48:24 -0700 Subject: [PATCH 3/8] use whole path import --- bittensor/core/extrinsics/transfer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/extrinsics/transfer.py b/bittensor/core/extrinsics/transfer.py index ec232d323a..aaa2795583 100644 --- a/bittensor/core/extrinsics/transfer.py +++ b/bittensor/core/extrinsics/transfer.py @@ -20,7 +20,6 @@ from retry import retry from rich.prompt import Confirm -from bittensor import logging from bittensor.core.extrinsics.utils import submit_extrinsic from bittensor.core.settings import NETWORK_EXPLORER_MAP from bittensor.utils import ( @@ -29,6 +28,7 @@ is_valid_bittensor_address_or_public_key, ) from bittensor.utils.balance import Balance +from bittensor.utils.btlogging import logging from bittensor.utils.networking import ensure_connected # For annotation purposes From 62c5e29161bbcea24b8fc6a41008fca06e57f248 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 31 Oct 2024 21:09:03 -0700 Subject: [PATCH 4/8] fix some logging --- bittensor/core/extrinsics/prometheus.py | 20 +++++++++++++------- bittensor/core/extrinsics/registration.py | 14 ++++++++------ bittensor/core/extrinsics/root.py | 8 +++++--- bittensor/core/extrinsics/serving.py | 4 +++- bittensor/core/extrinsics/set_weights.py | 4 +++- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/bittensor/core/extrinsics/prometheus.py b/bittensor/core/extrinsics/prometheus.py index 124b259b88..8184a42e1c 100644 --- a/bittensor/core/extrinsics/prometheus.py +++ b/bittensor/core/extrinsics/prometheus.py @@ -114,7 +114,7 @@ def prometheus_extrinsic( try: external_ip = net.get_external_ip() logging.success( - f":white_heavy_check_mark: Found external ip: {external_ip}" + f":white_heavy_check_mark: Found external ip: {external_ip}" ) except Exception as e: raise RuntimeError( @@ -146,17 +146,23 @@ def prometheus_extrinsic( ":white_heavy_check_mark: Prometheus already Served" ) logging.info("Status:") - logging.info(f"\tip: {neuron.prometheus_info.ip}") - logging.info(f"\tip_type: {neuron.prometheus_info.ip_type}") - logging.info(f"\tport: {neuron.prometheus_info.port}") - logging.info(f"\tversion: {neuron.prometheus_info.version}") + logging.info(f"\tip: {neuron.prometheus_info.ip}") + logging.info( + f"\tip_type: {neuron.prometheus_info.ip_type}" + ) + logging.info( + f"\tport: {neuron.prometheus_info.port}" + ) + logging.info( + f"\tversion: {neuron.prometheus_info.version}" + ) return True # Add netuid, not in prometheus_info call_params["netuid"] = netuid logging.info( - f":satellite: Serving prometheus on: {subtensor.network}:{netuid} " + f":satellite: Serving prometheus on: {subtensor.network}:{netuid} " ) success, error_message = do_serve_prometheus( self=subtensor, @@ -170,7 +176,7 @@ def prometheus_extrinsic( if success is True: json_ = json.dumps(call_params, indent=4, sort_keys=True) logging.info( - f":white_heavy_check_mark: Served prometheus: {json_}" + f":white_heavy_check_mark: Served prometheus: {json_}" ) return True else: diff --git a/bittensor/core/extrinsics/registration.py b/bittensor/core/extrinsics/registration.py index cd4807ab88..0b29fafc2b 100644 --- a/bittensor/core/extrinsics/registration.py +++ b/bittensor/core/extrinsics/registration.py @@ -142,17 +142,19 @@ def register_extrinsic( """ if not subtensor.subnet_exists(netuid): logging.error( - f":cross_mark: Failed: Subnet {netuid} does not exist." + f":cross_mark: Failed: Subnet {netuid} does not exist." ) return False - logging.info(f":satellite: Checking Account on subnet {netuid}...") + logging.info( + f":satellite: Checking Account on subnet {netuid}..." + ) neuron = subtensor.get_neuron_for_pubkey_and_subnet( wallet.hotkey.ss58_address, netuid=netuid ) if not neuron.is_null: logging.debug( - f"Wallet {wallet} is already registered on {neuron.netuid} with {neuron.uid}." + f"Wallet {wallet} is already registered on {neuron.netuid} with {neuron.uid}." ) return True @@ -174,7 +176,7 @@ def register_extrinsic( attempts = 1 while True: logging.info( - f":satellite: Registering...({attempts}/{max_allowed_attempts})" + f":satellite: Registering... ({attempts}/{max_allowed_attempts})" ) # Solve latest POW. if cuda: @@ -214,7 +216,7 @@ def register_extrinsic( ) if is_registered: logging.info( - f":white_heavy_check_mark: Already registered on netuid:{netuid}" + f":white_heavy_check_mark: Already registered on netuid: {netuid}" ) return True @@ -273,7 +275,7 @@ def register_extrinsic( # Failed registration, retry pow attempts += 1 logging.info( - f":satellite: Failed registration, retrying pow ...({attempts}/{max_allowed_attempts})" + f":satellite: Failed registration, retrying pow ... ({attempts}/{max_allowed_attempts})" ) else: # Failed to register after max attempts. diff --git a/bittensor/core/extrinsics/root.py b/bittensor/core/extrinsics/root.py index 32df5dbea4..129e852777 100644 --- a/bittensor/core/extrinsics/root.py +++ b/bittensor/core/extrinsics/root.py @@ -89,7 +89,9 @@ def root_register_extrinsic( netuid=0, hotkey_ss58=wallet.hotkey.ss58_address ) if is_registered: - logging.info("Already registered on root network.") + logging.info( + ":white_heavy_check_mark: Already registered on root network." + ) return True if prompt: @@ -97,7 +99,7 @@ def root_register_extrinsic( if not Confirm.ask("Register to root network?"): return False - logging.info(":satellite: Registering to root network...") + logging.info(":satellite: Registering to root network...") success, err_msg = _do_root_register( wallet=wallet, wait_for_inclusion=wait_for_inclusion, @@ -105,7 +107,7 @@ def root_register_extrinsic( ) if not success: - logging.error(f"Failed: {err_msg}") + logging.error(f":cross_mark: Failed: {err_msg}") time.sleep(0.5) # Successful registration, final check for neuron and pubkey diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index 72b9484d4d..ac712cd8cb 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -219,7 +219,9 @@ def serve_axon_extrinsic( if axon.external_ip is None: try: external_ip = net.get_external_ip() - logging.success(prefix="External IP", suffix=f"{external_ip}") + logging.success( + f":white_heavy_check_mark: Found external ip: {external_ip}" + ) except Exception as e: raise RuntimeError( f"Unable to attain your external ip. Check your internet connection. error: {e}" diff --git a/bittensor/core/extrinsics/set_weights.py b/bittensor/core/extrinsics/set_weights.py index e73f264578..98f4c16917 100644 --- a/bittensor/core/extrinsics/set_weights.py +++ b/bittensor/core/extrinsics/set_weights.py @@ -157,7 +157,9 @@ def set_weights_extrinsic( ): return False, "Prompt refused." - logging.info(f":satellite: Setting weights on {subtensor.network} ...") + logging.info( + f":satellite: Setting weights on {subtensor.network} ..." + ) try: success, error_message = do_set_weights( self=subtensor, From edad97507da0eb1e5320ebfdf766910e05ee5ff9 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 1 Nov 2024 00:59:20 -0700 Subject: [PATCH 5/8] fix registration.py --- bittensor/utils/registration.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/bittensor/utils/registration.py b/bittensor/utils/registration.py index e0d2b20236..05a90c9a3e 100644 --- a/bittensor/utils/registration.py +++ b/bittensor/utils/registration.py @@ -35,17 +35,11 @@ from retry import retry from rich import console as rich_console, status as rich_status from rich.console import Console -from rich.traceback import install from bittensor.utils.btlogging import logging from bittensor.utils.formatting import get_human_readable, millify from bittensor.utils.register_cuda import solve_cuda -# Console for `RegistrationStatisticsLogger` class -bt_console = Console() -# Remove overdue locals in debug training. -install(show_locals=False) - def use_torch() -> bool: """Force the use of torch over numpy for certain operations.""" @@ -494,12 +488,14 @@ class RegistrationStatistics: class RegistrationStatisticsLogger: """Logs statistics for a registration.""" - console: rich_console.Console status: Optional[rich_status.Status] def __init__( - self, console: rich_console.Console, output_in_place: bool = True + self, console: Optional[rich_console.Console] = None, output_in_place: bool = True ) -> None: + if console is None: + console = Console() + self.console = console if output_in_place: @@ -655,7 +651,7 @@ def _solve_for_difficulty_fast( start_time_perpetual = time.time() - logger = RegistrationStatisticsLogger(bt_console, output_in_place) + logger = RegistrationStatisticsLogger(output_in_place=output_in_place) logger.start() solution = None @@ -959,7 +955,7 @@ def _solve_for_difficulty_fast_cuda( start_time_perpetual = time.time() - logger = RegistrationStatisticsLogger(bt_console, output_in_place) + logger = RegistrationStatisticsLogger(output_in_place=output_in_place) logger.start() hash_rates = [0] * n_samples # The last n true hash_rates From 7e1b7a01093bb34178030de85b816d95fc930baa Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 1 Nov 2024 01:10:15 -0700 Subject: [PATCH 6/8] ruff --- bittensor/utils/registration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bittensor/utils/registration.py b/bittensor/utils/registration.py index 05a90c9a3e..4dd6d8ec67 100644 --- a/bittensor/utils/registration.py +++ b/bittensor/utils/registration.py @@ -491,7 +491,9 @@ class RegistrationStatisticsLogger: status: Optional[rich_status.Status] def __init__( - self, console: Optional[rich_console.Console] = None, output_in_place: bool = True + self, + console: Optional[rich_console.Console] = None, + output_in_place: bool = True, ) -> None: if console is None: console = Console() From 5875f4f5d05838b98c2d089bc177a6807bf98eab Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 4 Nov 2024 09:13:09 -0800 Subject: [PATCH 7/8] del prometheus.py --- bittensor/core/extrinsics/prometheus.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 bittensor/core/extrinsics/prometheus.py diff --git a/bittensor/core/extrinsics/prometheus.py b/bittensor/core/extrinsics/prometheus.py deleted file mode 100644 index e69de29bb2..0000000000 From d8d12e5b04f4f8fb005d04feb9969c8825b3e674 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 4 Nov 2024 09:22:45 -0800 Subject: [PATCH 8/8] fix review comments --- bittensor/core/extrinsics/registration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bittensor/core/extrinsics/registration.py b/bittensor/core/extrinsics/registration.py index 0b29fafc2b..8f7f3292b9 100644 --- a/bittensor/core/extrinsics/registration.py +++ b/bittensor/core/extrinsics/registration.py @@ -216,7 +216,7 @@ def register_extrinsic( ) if is_registered: logging.info( - f":white_heavy_check_mark: Already registered on netuid: {netuid}" + f":white_heavy_check_mark: Already registered on netuid: {netuid}." ) return True @@ -240,7 +240,7 @@ def register_extrinsic( # https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs if "HotKeyAlreadyRegisteredInSubNet" in err_msg: logging.info( - f":white_heavy_check_mark: Already Registered on subnet {netuid}." + f":white_heavy_check_mark: Already Registered on subnet {netuid}." ) return True