Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

black formatting #1685

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
python -m venv env/
. env/bin/activate
python -m pip install --upgrade pip
pip install black
pip install black==23.7.0

- save_cache:
name: Save cached black venv
Expand Down
9 changes: 6 additions & 3 deletions bittensor/axon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Create and initialize Axon, which services the forward and backward requests from other neurons.
"""

# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
Expand Down Expand Up @@ -1207,9 +1208,11 @@ async def verify(self, synapse: bittensor.Synapse):
# We attempt to run the verification function using the synapse instance
# created from the request. If this function runs without throwing an exception,
# it means that the verification was successful.
await verify_fn(synapse) if inspect.iscoroutinefunction(
verify_fn
) else verify_fn(synapse)
(
await verify_fn(synapse)
if inspect.iscoroutinefunction(verify_fn)
else verify_fn(synapse)
)
except Exception as e:
# If there was an exception during the verification process, we log that
# there was a verification exception.
Expand Down
7 changes: 4 additions & 3 deletions bittensor/btlogging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Standardized logging for Bittensor.
"""

# The MIT License (MIT)
# Copyright © 2021 Yuma Rao

Expand Down Expand Up @@ -59,7 +60,7 @@ def __new__(
logging_dir: str = None,
):
r"""Instantiate Bittensor logging system backend.

Args:
config (bittensor.config, optional):
bittensor.logging.config()
Expand Down Expand Up @@ -131,8 +132,8 @@ def __new__(
@classmethod
def config(cls):
"""Get config from the argument parser.
Return:

Return:
bittensor.config object
"""
parser = argparse.ArgumentParser()
Expand Down
10 changes: 9 additions & 1 deletion bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class NeuronInfo:
r"""
Dataclass for neuron metadata.
"""

hotkey: str
coldkey: str
uid: int
Expand Down Expand Up @@ -516,6 +517,7 @@ class NeuronInfoLite:
r"""
Dataclass for neuron metadata, but without the weights and bonds.
"""

hotkey: str
coldkey: str
uid: int
Expand Down Expand Up @@ -673,6 +675,7 @@ class PrometheusInfo:
r"""
Dataclass for prometheus info.
"""

block: int
version: int
ip: str
Expand All @@ -694,6 +697,7 @@ class DelegateInfo:
r"""
Dataclass for delegate info.
"""

hotkey_ss58: str # Hotkey of delegate
total_stake: Balance # Total stake of the delegate
nominators: List[
Expand Down Expand Up @@ -766,7 +770,7 @@ def delegated_list_from_vec_u8(
cls, vec_u8: List[int]
) -> List[Tuple["DelegateInfo", Balance]]:
r"""Returns a list of Tuples of DelegateInfo objects, and Balance, from a ``vec_u8``.

This is the list of delegates that the user has delegated to, and the amount of stake delegated.
"""
decoded = from_scale_encoding(vec_u8, ChainDataType.DelegatedInfo, is_vec=True)
Expand All @@ -787,6 +791,7 @@ class StakeInfo:
r"""
Dataclass for stake info.
"""

hotkey_ss58: str # Hotkey address
coldkey_ss58: str # Coldkey address
stake: Balance # Stake for the hotkey-coldkey pair
Expand Down Expand Up @@ -857,6 +862,7 @@ class SubnetInfo:
r"""
Dataclass for subnet info.
"""

netuid: int
rho: int
kappa: int
Expand Down Expand Up @@ -948,6 +954,7 @@ class SubnetHyperparameters:
r"""
Dataclass for subnet hyperparameters.
"""

rho: int
kappa: int
immunity_period: int
Expand Down Expand Up @@ -1039,6 +1046,7 @@ class IPInfo:
r"""
Dataclass for associated IP Info.
"""

ip: str
ip_type: int
protocol: int
Expand Down
2 changes: 1 addition & 1 deletion bittensor/commands/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
),
# f'{delegate.take * 100:.1f}%',s
f"{ delegate[0].total_daily_return.tao * ( 1000 / ( 0.001 + delegate[0].total_stake.tao ) )!s:6.6}",
str(delegate_description)
str(delegate_description),
# f'{delegate_profile.description:140.140}',
)

Expand Down
8 changes: 5 additions & 3 deletions bittensor/commands/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
"*" if metagraph.validator_permit[uid] else "",
str((metagraph.block.item() - metagraph.last_update[uid].item())),
str(metagraph.active[uid].item()),
ep.ip + ":" + str(ep.port)
if ep.is_serving
else "[yellow]none[/yellow]",
(
ep.ip + ":" + str(ep.port)
if ep.is_serving
else "[yellow]none[/yellow]"
),
ep.hotkey[:10],
ep.coldkey[:10],
]
Expand Down
12 changes: 7 additions & 5 deletions bittensor/commands/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,13 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
"{:.5f}".format(validator_trust),
"*" if validator_permit else "",
str(last_update),
bittensor.utils.networking.int_to_ip(nn.axon_info.ip)
+ ":"
+ str(nn.axon_info.port)
if nn.axon_info.port != 0
else "[yellow]none[/yellow]",
(
bittensor.utils.networking.int_to_ip(nn.axon_info.ip)
+ ":"
+ str(nn.axon_info.port)
if nn.axon_info.port != 0
else "[yellow]none[/yellow]"
),
nn.hotkey,
]

Expand Down
8 changes: 5 additions & 3 deletions bittensor/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
for neuron_data in root_neurons:
table.add_row(
str(neuron_data.uid),
delegate_info[neuron_data.hotkey].name
if neuron_data.hotkey in delegate_info
else "",
(
delegate_info[neuron_data.hotkey].name
if neuron_data.hotkey in delegate_info
else ""
),
neuron_data.hotkey,
"{:.5f}".format(
float(subtensor.get_total_stake_for_hotkey(neuron_data.hotkey))
Expand Down
8 changes: 5 additions & 3 deletions bittensor/commands/senate.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):

for ss58_address in senate_members:
table.add_row(
delegate_info[ss58_address].name
if ss58_address in delegate_info
else "",
(
delegate_info[ss58_address].name
if ss58_address in delegate_info
else ""
),
ss58_address,
)

Expand Down
6 changes: 3 additions & 3 deletions bittensor/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ def check_config(config: "bittensor.config"):
else:
config.ss58_address = prompt_answer
if not bittensor.utils.is_valid_bittensor_address_or_public_key(
address=config.ss58_address
if config.ss58_address
else config.public_key_hex
address=(
config.ss58_address if config.ss58_address else config.public_key_hex
)
):
sys.exit(1)

Expand Down
3 changes: 2 additions & 1 deletion bittensor/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Implementation of the config class, which manages the configuration of different Bittensor modules.
"""

# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
Expand Down Expand Up @@ -247,7 +248,7 @@ def __parse_args__(
args: List[str], parser: argparse.ArgumentParser = None, strict: bool = False
) -> argparse.Namespace:
"""Parses the passed args use the passed parser.

Args:
args (List[str]):
List of arguments to parse.
Expand Down
34 changes: 17 additions & 17 deletions bittensor/dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

class dendrite(torch.nn.Module):
"""
The Dendrite class, inheriting from PyTorch's Module class, represents the abstracted implementation of a network client module.
The Dendrite class, inheriting from PyTorch's Module class, represents the abstracted implementation of a network client module.

In the brain analogy, dendrites receive signals
from other neurons (in this case, network servers or axons), and the Dendrite class here is designed
to send requests to those endpoint to recieve inputs.
Expand Down Expand Up @@ -73,11 +73,11 @@ class dendrite(torch.nn.Module):
aclose_session(self):
Asynchronously closes the internal aiohttp client session.

NOTE:
NOTE:
When working with async `aiohttp <https://github.com/aio-libs/aiohttp>`_ client sessions, it is recommended to use a context manager.

Example with a context manager::

>>> aysnc with dendrite(wallet = bittensor.wallet()) as d:
>>> print(d)
>>> d( <axon> ) # ping axon
Expand All @@ -87,7 +87,7 @@ class dendrite(torch.nn.Module):
However, you are able to safely call :func:`dendrite.query()` without a context manager in a synchronous setting.

Example without a context manager::

>>> d = dendrite(wallet = bittensor.wallet() )
>>> print(d)
>>> d( <axon> ) # ping axon
Expand Down Expand Up @@ -141,7 +141,7 @@ async def session(self) -> aiohttp.ClientSession:
the dendrite, adhering to the async nature of the network interactions in the Bittensor framework.

Example usage::

import bittensor as bt # Import bittensor
wallet = bt.wallet( ... ) # Initialize a wallet
dendrite = bt.dendrite( wallet ) # Initialize a dendrite instance with the wallet
Expand All @@ -167,7 +167,7 @@ def close_session(self):
resources like open connections and internal buffers. It is crucial for preventing resource leakage
and should be called when the dendrite instance is no longer in use, especially in synchronous contexts.

Note:
Note:
This method utilizes asyncio's event loop to close the session asynchronously from a synchronous context. It is advisable to use this method only when asynchronous context management is not feasible.

Usage:
Expand All @@ -193,7 +193,7 @@ async def aclose_session(self):
await :func:`dendrite_instance.aclose_session()`.

Example::

async with dendrite_instance:
# Operations using dendrite
pass
Expand Down Expand Up @@ -237,7 +237,7 @@ def _handle_request_errors(self, synapse, request_name, exception):
request_name: The name of the request during which the exception occurred.
exception: The exception object caught during the request.

Note:
Note:
This method updates the synapse object in-place.
"""
if isinstance(exception, aiohttp.ClientConnectorError):
Expand All @@ -263,7 +263,7 @@ def _log_outgoing_request(self, synapse):
is crucial for monitoring and debugging network activity within the Bittensor network.

To turn on debug messages, set the environment variable BITTENSOR_DEBUG to ``1``, or call the bittensor debug method like so::

import bittensor
bittensor.debug()

Expand Down Expand Up @@ -349,7 +349,7 @@ async def forward(
returned, each containing the response from the corresponding Axon.

For example::

>>> ...
>>> wallet = bittensor.wallet() # Initialize a wallet
>>> synapse = bittensor.Synapse(...) # Create a synapse object that contains query data
Expand All @@ -362,7 +362,7 @@ async def forward(
iterated over to process each chunk individually.

For example::

>>> ...
>>> dendrte = bittensor.dendrite(wallet = wallet)
>>> async for chunk in dendrite.forward(axons, synapse, timeout, deserialize, run_async, streaming):
Expand Down Expand Up @@ -768,7 +768,7 @@ async def __aenter__(self):
Dendrite: The current instance of the Dendrite class.

Usage::

async with Dendrite() as dendrite:
await dendrite.some_async_method()
"""
Expand All @@ -787,11 +787,11 @@ async def __aexit__(self, exc_type, exc_value, traceback):
traceback (TracebackType, optional): A traceback object encapsulating the call stack at the point where the exception was raised.

Usage::

async with bt.dendrite( wallet ) as dendrite:
await dendrite.some_async_method()

Note:
Note:
This automatically closes the session by calling :func:`__aexit__` after the context closes.
"""
await self.aclose_session()
Expand All @@ -803,11 +803,11 @@ def __del__(self):
This method is invoked when the Dendrite instance is about to be destroyed. The destructor ensures that the
aiohttp client session is closed before the instance is fully destroyed, releasing any remaining resources.

Note:
Note:
Relying on the destructor for cleanup can be unpredictable. It is recommended to explicitly close sessions using the provided methods or the ``async with`` context manager.

Usage::

dendrite = Dendrite()
# ... some operations ...
del dendrite # This will implicitly invoke the __del__ method and close the session.
Expand Down
Loading