Skip to content

Commit

Permalink
Merge pull request #1666 from rajkaramchedu/rajk/3-docstrings
Browse files Browse the repository at this point in the history
Third docstrings formatting PR
  • Loading branch information
ifrit98 authored Jan 23, 2024
2 parents 426cad6 + f028548 commit 65b370a
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 328 deletions.
69 changes: 23 additions & 46 deletions bittensor/extrinsics/delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ def nominate_extrinsic(
wait_for_inclusion: bool = True,
) -> bool:
r"""Becomes a delegate for the hotkey.
Args:
wallet ( bittensor.wallet ):
The wallet to become a delegate for.
wallet (bittensor.wallet): The wallet to become a delegate for.
Returns:
success (bool):
True if the transaction was successful.
success (bool): ``True`` if the transaction was successful.
"""
# Unlock the coldkey.
wallet.coldkey
Expand Down Expand Up @@ -105,31 +104,20 @@ def delegate_extrinsic(
prompt: bool = False,
) -> bool:
r"""Delegates the specified amount of stake to the passed delegate.
Args:
wallet (bittensor.wallet):
Bittensor wallet object.
delegate_ss58 (Optional[str]):
ss58 address of the delegate.
amount (Union[Balance, float]):
Amount to stake as bittensor balance, or float interpreted as Tao.
wait_for_inclusion (bool):
If set, waits for the extrinsic to enter a block before returning true,
or returns false if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool):
If set, waits for the extrinsic to be finalized on the chain before returning true,
or returns false if the extrinsic fails to be finalized within the timeout.
prompt (bool):
If true, the call waits for confirmation from the user before proceeding.
wallet (bittensor.wallet): Bittensor wallet object.
delegate_ss58 (Optional[str]): The ``ss58`` address of the delegate.
amount (Union[Balance, float]): Amount to stake as bittensor balance, or ``float`` interpreted as Tao.
wait_for_inclusion (bool): If set, waits for the extrinsic to enter a block before returning ``true``, or returns ``false`` if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool): If set, waits for the extrinsic to be finalized on the chain before returning ``true``, or returns ``false`` if the extrinsic fails to be finalized within the timeout.
prompt (bool): If ``true``, the call waits for confirmation from the user before proceeding.
Returns:
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.
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``.
Raises:
NotRegisteredError:
If the wallet is not registered on the chain.
NotDelegateError:
If the hotkey is not a delegate on the chain.
NotRegisteredError: If the wallet is not registered on the chain.
NotDelegateError: If the hotkey is not a delegate on the chain.
"""
# Decrypt keys,
wallet.coldkey
Expand Down Expand Up @@ -251,31 +239,20 @@ def undelegate_extrinsic(
prompt: bool = False,
) -> bool:
r"""Un-delegates stake from the passed delegate.
Args:
wallet (bittensor.wallet):
Bittensor wallet object.
delegate_ss58 (Optional[str]):
ss58 address of the delegate.
amount (Union[Balance, float]):
Amount to unstake as bittensor balance, or float interpreted as Tao.
wait_for_inclusion (bool):
If set, waits for the extrinsic to enter a block before returning true,
or returns false if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool):
If set, waits for the extrinsic to be finalized on the chain before returning true,
or returns false if the extrinsic fails to be finalized within the timeout.
prompt (bool):
If true, the call waits for confirmation from the user before proceeding.
wallet (bittensor.wallet): Bittensor wallet object.
delegate_ss58 (Optional[str]): The ``ss58`` address of the delegate.
amount (Union[Balance, float]): Amount to unstake as bittensor balance, or ``float`` interpreted as Tao.
wait_for_inclusion (bool): If set, waits for the extrinsic to enter a block before returning ``true``, or returns ``false`` if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool): If set, waits for the extrinsic to be finalized on the chain before returning ``true``, or returns ``false`` if the extrinsic fails to be finalized within the timeout.
prompt (bool): If ``true``, the call waits for confirmation from the user before proceeding.
Returns:
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.
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``.
Raises:
NotRegisteredError:
If the wallet is not registered on the chain.
NotDelegateError:
If the hotkey is not a delegate on the chain.
NotRegisteredError: If the wallet is not registered on the chain.
NotDelegateError: If the hotkey is not a delegate on the chain.
"""
# Decrypt keys,
wallet.coldkey
Expand Down
128 changes: 64 additions & 64 deletions bittensor/extrinsics/log_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class ValidatorLogger:
Including console log styling, console table print and prometheus.
Args:
config (:obj:`bittensor.Config`, `optional`):
bittensor.server.config()
config (:func:`bittensor.Config`, optional): ``bittensor.server.config()``
"""

def __init__(self, config=None):
Expand Down Expand Up @@ -227,19 +226,19 @@ def print_response_table(
tasks_per_server: int = 3,
):
r"""
Prints the query response table: top prediction probabilities and texts for batch tasks.
Args:
batch_predictions (:obj:`List[Union[str, Dict{torch.Tensor, str}]]`, `required`):
Predictions in string per task per uid. In the format of [(task, {uid, "prob: phrase" })] of length batch size.
stats (:obj:`Dict{Dict}`, `required`):
Statistics per endpoint for this batch. In the format of {uid, {statistics}}.
sort_col (:type:`str`, `required`):
Column name used for sorting. Options from self.neuron_stats_columns[:, 1].
task_repeat (:type:`int`, `required`):
The number of servers to compare against under the same set of task.
tasks_per_server (:type:`int`, `required`):
How many tasks to show for each server.
Prints the query response table with top prediction probabilities and texts for batch tasks.
Args:
batch_predictions (:obj:`List[Union[str, Dict{torch.Tensor, str}]]`, required):
Predictions in string per task per ``uid``. In the format of ``[(task, {uid, "prob: phrase" })]`` of length batch size.
stats (:obj:`Dict{Dict}`, required):
Statistics per endpoint for this batch. In the format of ``{uid, {statistics}}``.
sort_col (str, required):
Column name used for sorting. Options from ``self.neuron_stats_columns[:, 1]``.
task_repeat (int, required):
The number of servers to compare against under the same set of task.
tasks_per_server (int, required):
How many tasks to show for each server.
"""
# === Batch permutation ===
batch_size = len(batch_predictions)
Expand Down Expand Up @@ -325,13 +324,13 @@ def print_synergy_table(self, stats: Dict, syn_loss_diff: Dict, sort_col: str):
r"""
Prints the synergy loss diff matrix with pairwise loss reduction due to synergy (original loss on diagonal).
Args:
stats (:obj:`Dict{Dict}`, `required`):
Statistics per endpoint for this batch. In the format of {uid, {statistics}}.
syn_loss_diff (:obj:`Dict`, `required`):
Dictionary table of pairwise synergies as loss reductions, with direct loss on diagonal.
sort_col (:type:`str`, `required`):
Column name used for sorting. Options from self.neuron_stats_columns[:, 1].
Args:
stats (:obj:`Dict{Dict}`, required):
Statistics per endpoint for this batch. In the format of ``{uid, {statistics}}``.
syn_loss_diff (:obj:`Dict`, required):
Dictionary table of pairwise synergies as loss reductions, with direct loss on diagonal.
sort_col (str, required):
Column name used for sorting. Options from ``self.neuron_stats_columns[:, 1]``.
"""
sort = sorted(
[(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s],
Expand Down Expand Up @@ -384,15 +383,15 @@ def print_stats_table(
r"""
Gathers data and constructs neuron statistics table and prints it.
Args:
stats (:obj:`Dict{Dict}`, `required`):
Statistics per endpoint for this batch. In the format of {uid, {statistics}}.
sort_col (:type:`str`, `required`):
Column name used for sorting. Options from self.neuron_stats_columns[:, 1].
title (:type:`str`, `required`):
Title of the table.
caption (:type:`str`, `required`):
Caption shown at the end of table.
Args:
stats (:obj:`Dict{Dict}`, required):
Statistics per endpoint for this batch. In the format of ``{uid, {statistics}}``.
sort_col (str, required):
Column name used for sorting. Options from ``self.neuron_stats_columns[:, 1]``.
title (str, required):
Title of the table.
caption (str, required):
Caption shown at the end of table.
"""
# === Gather columns and rows ===
if mark_uids is None:
Expand Down Expand Up @@ -459,17 +458,17 @@ def print_synapse_table(
self, name: str, stats: Dict, sort_col: str, start_time: time.time
):
r"""
Prints the evaluation of the neuron responses to the validator request
Args:
stats (:obj:`Dict{Dict}`, `required`):
Statistics per endpoint for this batch. In the format of {uid, {statistics}}.
sort_col (:type:`str`, `required`):
Column name used for sorting. Options from self.neuron_stats_columns[:, 1].
name (:obj:`str`, `required`):
Name of synapse for the title of the table.
start_time (:obj:`time.time`, `required`):
Starting time for shapley calculation.
Prints the evaluation of the neuron responses to the validator request.
Args:
stats (Dict{Dict}, required):
Statistics per endpoint for this batch. In the format of ``{uid, {statistics}}``.
sort_col (str, required):
Column name used for sorting. Options from ``self.neuron_stats_columns[:, 1]``.
name (str, required):
Name of synapse for the title of the table.
start_time (time.time, required):
Starting time for shapley calculation.
"""
self.print_stats_table(
Expand All @@ -496,25 +495,25 @@ def print_weights_table(
r"""
Prints weights table given sample_uids and sample_weights.
Args:
min_allowed_weights (:type:`int`, `required`):
subtensor minimum allowed weight to set.
max_weight_limit (:type:`int`, `required`):
subtensor maximum allowed weight to set.
neuron_stats (:obj:`Dict{Dict}`, `required`):
Statistics per endpoint for this batch. In the format of {uid, {statistics}}.
title (:type:`str`, `required`):
Title of the table.
metagraph_n (:type:`int`, `required`):
Total number of uids in the metagraph.
sample_uids (:obj:`torch.Tensor`, `required`):
Uids to set weight for.
sample_weights (:obj:`torch.Tensor`, `required`):
Weights to set uids for.
include_uids (:type:`list`, `optional`):
Set of uids to inculde in the table.
num_rows (:type:`int`, `optional`):
Total number of uids to print in total.
Args:
min_allowed_weights (int, required):
subtensor minimum allowed weight to set.
max_weight_limit (int, required):
subtensor maximum allowed weight to set.
neuron_stats (Dict{Dict}, required):
Statistics per endpoint for this batch. In the format of ``{uid, {statistics}}``.
title (str, required):
Title of the table.
metagraph_n (int, required):
Total number of ``uid``s in the metagraph.
sample_uids (torch.Tensor, required):
``Uid``s to set weight for.
sample_weights (torch.Tensor, required):
Weights to set ``uid``s for.
include_uids (list, optional):
Set of ``uid``s to inculde in the table.
num_rows (int, optional):
Total number of ``uid``s to print in total.
"""
# === Weight table ===
# Prints exponential moving average statistics of valid neurons and latest weights
Expand Down Expand Up @@ -666,9 +665,10 @@ def print_console_subtensor_weight(
class ValidatorPrometheus:
r"""
Prometheis logging object for validator.
Args:
config (:obj:`bittensor.Config`, `optional`):
bittensor.server.config()
Args:
config (bittensor.Config, optional):
``bittensor.server.config()``
"""

def __init__(self, config):
Expand Down
28 changes: 13 additions & 15 deletions bittensor/extrinsics/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ def register_subnetwork_extrinsic(
wait_for_finalization: bool = True,
prompt: bool = False,
) -> bool:
r"""Registers a new subnetwork
r"""Registers a new subnetwork.
Args:
wallet (bittensor.wallet):
bittensor wallet object.
wait_for_inclusion (bool):
If set, waits for the extrinsic to enter a block before returning true,
or returns false if the extrinsic fails to enter the block within the timeout.
If set, waits for the extrinsic to enter a block before returning ``true``, or returns ``false`` if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool):
If set, waits for the extrinsic to be finalized on the chain before returning true,
or returns false if the extrinsic fails to be finalized within the timeout.
If set, waits for the extrinsic to be finalized on the chain before returning ``true``, or returns ``false`` if the extrinsic fails to be finalized within the timeout.
prompt (bool):
If true, the call waits for confirmation from the user before proceeding.
Returns:
success (bool):
flag is true if extrinsic was finalized or included in the block.
If we did not wait for finalization / inclusion, the response is true.
Flag is ``true`` if extrinsic was finalized or included in the block.
If we did not wait for finalization / inclusion, the response is ``true``.
"""
your_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address)
burn_cost = bittensor.utils.balance.Balance(subtensor.get_subnet_burn_cost())
Expand Down Expand Up @@ -117,27 +116,26 @@ def set_hyperparameter_extrinsic(
prompt: bool = False,
) -> bool:
r"""Sets a hyperparameter for a specific subnetwork.
Args:
wallet (bittensor.wallet):
bittensor wallet object.
netuid (int):
Subnetwork uid.
Subnetwork ``uid``.
parameter (str):
Hyperparameter name.
value (any):
New hyperparameter value.
wait_for_inclusion (bool):
If set, waits for the extrinsic to enter a block before returning true,
or returns false if the extrinsic fails to enter the block within the timeout.
If set, waits for the extrinsic to enter a block before returning ``true``, or returns ``false`` if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool):
If set, waits for the extrinsic to be finalized on the chain before returning true,
or returns false if the extrinsic fails to be finalized within the timeout.
If set, waits for the extrinsic to be finalized on the chain before returning ``true``, or returns ``false`` if the extrinsic fails to be finalized within the timeout.
prompt (bool):
If true, the call waits for confirmation from the user before proceeding.
If ``true``, the call waits for confirmation from the user before proceeding.
Returns:
success (bool):
flag is true if extrinsic was finalized or included in the block.
If we did not wait for finalization / inclusion, the response is true.
Flag is ``true`` if extrinsic was finalized or included in the block.
If we did not wait for finalization / inclusion, the response is ``true``.
"""
if subtensor.get_subnet_owner(netuid) != wallet.coldkeypub.ss58_address:
bittensor.__console__.print(
Expand Down
23 changes: 11 additions & 12 deletions bittensor/extrinsics/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,27 @@ def prometheus_extrinsic(
wait_for_inclusion: bool = False,
wait_for_finalization=True,
) -> bool:
r"""Subscribes an bittensor endpoint to the substensor chain.
r"""Subscribes an Bittensor endpoint to the substensor chain.
Args:
subtensor (bittensor.subtensor):
bittensor subtensor object.
Bittensor subtensor object.
wallet (bittensor.wallet):
bittensor wallet object.
Bittensor wallet object.
ip (str):
endpoint host port i.e. 192.122.31.4
Endpoint host port i.e., ``192.122.31.4``.
port (int):
endpoint port number i.e. 9221
Endpoint port number i.e., `9221`.
netuid (int):
network uid to serve on.
Network `uid` to serve on.
wait_for_inclusion (bool):
if set, waits for the extrinsic to enter a block before returning true,
or returns false if the extrinsic fails to enter the block within the timeout.
If set, waits for the extrinsic to enter a block before returning ``true``, or returns ``false`` if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool):
if set, waits for the extrinsic to be finalized on the chain before returning true,
or returns false if the extrinsic fails to be finalized within the timeout.
If set, waits for the extrinsic to be finalized on the chain before returning ``true``, or returns ``false`` if the extrinsic fails to be finalized within the timeout.
Returns:
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.
Flag is ``true`` if extrinsic was finalized or uncluded in the block.
If we did not wait for finalization / inclusion, the response is ``true``.
"""

# ---- Get external ip ----
Expand Down
Loading

0 comments on commit 65b370a

Please sign in to comment.