bittensor.utils#
Submodules#
Attributes#
Exceptions#
| Common base class for all non-exit exceptions. | 
Functions#
| Force the use of torch over numpy for certain operations. | |
| 
 | Deprecated, kept for backwards compatibility. Use check_version() instead. | 
| 
 | Check if the current version of Bittensor is up to date with the latest version on PyPi. | 
| 
 | Returns the ss58 format of the given ss58 address. | 
| 
 | Checks if the given address is a valid ss58 address. | 
| 
 | Checks if the given public_key is a valid ed25519 key. | 
| Checks if the given address is a valid destination address. | |
| 
 | Creates a dictionary with structure for identity extrinsic. Must fit within 64 bits. | 
| 
 | |
| 
 | |
| 
 | Selects topk as in torch.topk but does not bias lower indices when values are equal. | 
| 
 | Selects topk as in torch.topk but does not bias lower indices when values are equal. | 
| 
 | Creates a strtobool function with a default value. | 
| 
 | Converts a string to a boolean value. | 
| 
 | Returns the explorer root url for the given network name from the given network map. | 
| 
 | Returns the explorer url for the given block hash and network. | 
| 
 | Converts a ss58 address to a bytes object. | 
| 
 | Converts a u8-encoded account key to an ss58 address. | 
| 
 | |
| 
 | Formats an error message from the Subtensor error information to using in extrinsics. | 
Package Contents#
- bittensor.utils.torch#
- bittensor.utils.use_torch()[source]#
- Force the use of torch over numpy for certain operations. - Return type:
 
- bittensor.utils.version_checking(timeout=15)[source]#
- Deprecated, kept for backwards compatibility. Use check_version() instead. - Parameters:
- timeout (int) 
 
- bittensor.utils.check_version(timeout=15)[source]#
- Check if the current version of Bittensor is up to date with the latest version on PyPi. Raises a VersionCheckError if the version check fails. - Parameters:
- timeout (int) 
 
- exception bittensor.utils.VersionCheckError[source]#
- Bases: - Exception- Common base class for all non-exit exceptions. - Initialize self. See help(type(self)) for accurate signature. 
- bittensor.utils.get_ss58_format(ss58_address)[source]#
- Returns the ss58 format of the given ss58 address. 
- bittensor.utils.is_valid_ss58_address(address)[source]#
- Checks if the given address is a valid ss58 address. 
- bittensor.utils.is_valid_ed25519_pubkey(public_key)[source]#
- Checks if the given public_key is a valid ed25519 key. 
- bittensor.utils.is_valid_bittensor_address_or_public_key(address)[source]#
- Checks if the given address is a valid destination address. 
- bittensor.utils.create_identity_dict(display='', legal='', web='', riot='', email='', pgp_fingerprint=None, image='', info='', twitter='')[source]#
- Creates a dictionary with structure for identity extrinsic. Must fit within 64 bits. - Parameters:
- display (str) – String to be converted and stored under ‘display’. 
- legal (str) – String to be converted and stored under ‘legal’. 
- web (str) – String to be converted and stored under ‘web’. 
- riot (str) – String to be converted and stored under ‘riot’. 
- email (str) – String to be converted and stored under ‘email’. 
- pgp_fingerprint (str) – String to be converted and stored under ‘pgp_fingerprint’. 
- image (str) – String to be converted and stored under ‘image’. 
- info (str) – String to be converted and stored under ‘info’. 
- twitter (str) – String to be converted and stored under ‘twitter’. 
 
- Returns:
- A dictionary with the specified structure and byte string conversions. 
- Return type:
 - Raises: ValueError: If pgp_fingerprint is not exactly 20 bytes long when encoded. 
- bittensor.utils.RAOPERTAO = 1000000000.0#
- bittensor.utils.U16_MAX = 65535#
- bittensor.utils.U64_MAX = 18446744073709551615#
- bittensor.utils._unbiased_topk(values, k, dim=0, sorted=True, largest=True, axis=0, return_type='numpy')[source]#
- Selects topk as in torch.topk but does not bias lower indices when values are equal. :param values: (np.ndarray) if using numpy, (torch.Tensor) if using torch: - Values to index into. - Parameters:
- k (int) – (int): Number to take. 
- dim – (int): Dimension to index into (used by Torch) 
- sorted – (bool): Whether to sort indices. 
- largest – (bool): Whether to take the largest value. 
- axis – (int): Axis along which to index into (used by Numpy) 
- return_type (str) – (str): Whether or use torch or numpy approach 
- values (wallet_utils.Union[numpy.ndarray, registration.torch.Tensor]) 
 
- Returns:
- (np.ndarray) if using numpy, (torch.Tensor) if using torch:
- topk k values. 
- indices: (np.ndarray) if using numpy, (torch.LongTensor) if using torch:
- indices of the topk values. 
 
- Return type:
- topk 
 
- bittensor.utils.unbiased_topk(values, k, dim=0, sorted=True, largest=True, axis=0)[source]#
- Selects topk as in torch.topk but does not bias lower indices when values are equal. :param values: (np.ndarray) if using numpy, (torch.Tensor) if using torch: - Values to index into. - Parameters:
- k (int) – (int): Number to take. 
- dim (int) – (int): Dimension to index into (used by Torch) 
- sorted (bool) – (bool): Whether to sort indices. 
- largest (bool) – (bool): Whether to take the largest value. 
- axis (int) – (int): Axis along which to index into (used by Numpy) 
- values (wallet_utils.Union[numpy.ndarray, registration.torch.Tensor]) 
 
- Returns:
- (np.ndarray) if using numpy, (torch.Tensor) if using torch:
- topk k values. 
- indices: (np.ndarray) if using numpy, (torch.LongTensor) if using torch:
- indices of the topk values. 
 
- Return type:
- topk 
 
- bittensor.utils.strtobool_with_default(default)[source]#
- Creates a strtobool function with a default value. 
- bittensor.utils.strtobool(val)[source]#
- Converts a string to a boolean value. - truth-y values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false-y values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’. - Raises ValueError if ‘val’ is anything else. 
- bittensor.utils.get_explorer_root_url_by_network_from_map(network, network_map)[source]#
- Returns the explorer root url for the given network name from the given network map. 
- bittensor.utils.get_explorer_url_for_network(network, block_hash, network_map)[source]#
- Returns the explorer url for the given block hash and network. - Parameters:
- Returns:
- The explorer url for the given block hash and network. Or None if the network is not known. 
- Return type:
- wallet_utils.Optional[List[str]] 
 
- bittensor.utils.ss58_address_to_bytes(ss58_address)[source]#
- Converts a ss58 address to a bytes object. 
- bittensor.utils.u8_key_to_ss58(u8_key)[source]#
- Converts a u8-encoded account key to an ss58 address.