From 7532c954a1eb5968b9fef9b786ff0ac26bf9fd8e Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 26 Jan 2023 13:30:09 +0200 Subject: [PATCH 1/4] Add neuron_info fields for ValidatorTrust and WeightConsensus --- bittensor/_cli/commands/metagraph.py | 16 ++++++++++++---- bittensor/_cli/commands/overview.py | 15 ++++++++++++--- bittensor/_metagraph/__init__.py | 8 ++++++++ bittensor/_metagraph/metagraph_impl.py | 22 ++++++++++++++++++++-- bittensor/_metagraph/metagraph_mock.py | 6 ++++++ bittensor/_neuron/text/core_server/run.py | 4 ++++ bittensor/_subtensor/chain_data.py | 8 ++++++++ bittensor/_subtensor/subtensor_impl.py | 2 ++ bittensor/_subtensor/subtensor_mock.py | 2 ++ bittensor/_wallet/wallet_impl.py | 6 ++++++ 10 files changed, 80 insertions(+), 9 deletions(-) diff --git a/bittensor/_cli/commands/metagraph.py b/bittensor/_cli/commands/metagraph.py index b4650dc258..a0d8fa01e8 100644 --- a/bittensor/_cli/commands/metagraph.py +++ b/bittensor/_cli/commands/metagraph.py @@ -39,8 +39,10 @@ def run (cli): TABLE_DATA = [] total_stake = 0.0 total_rank = 0.0 + total_validator_trust = 0.0 total_trust = 0.0 total_consensus = 0.0 + total_weight_consensus = 0.0 total_incentive = 0.0 total_dividends = 0.0 total_emission = 0 @@ -49,23 +51,27 @@ def run (cli): row = [ str(ep.uid), '{:.5f}'.format( metagraph.stake[uid]), - '{:.5f}'.format( metagraph.ranks[uid]), + '{:.5f}'.format( metagraph.ranks[uid]), '{:.5f}'.format( metagraph.trust[uid]), - '{:.5f}'.format( metagraph.consensus[uid]), + '{:.5f}'.format( metagraph.consensus[uid]), + '{:.5f}'.format( metagraph.weight_consensus[uid]), '{:.5f}'.format( metagraph.incentive[uid]), '{:.5f}'.format( metagraph.dividends[uid]), '{}'.format( int(metagraph.emission[uid] * 1000000000)), + '{:.5f}'.format( metagraph.validator_trust[uid]), + '*' if metagraph.validator_permit[uid] else '', str((metagraph.block.item() - metagraph.last_update[uid].item())), str( metagraph.active[uid].item() ), - '*' if metagraph.validator_permit[uid] else '', ep.ip + ':' + str(ep.port) if ep.is_serving else '[yellow]none[/yellow]', ep.hotkey[:10], ep.coldkey[:10] ] total_stake += metagraph.stake[uid] total_rank += metagraph.ranks[uid] + total_validator_trust += metagraph.validator_trust[uid] total_trust += metagraph.trust[uid] total_consensus += metagraph.consensus[uid] + total_weight_consensus += metagraph.weight_consensus[uid] total_incentive += metagraph.incentive[uid] total_dividends += metagraph.dividends[uid] total_emission += int(metagraph.emission[uid] * 1000000000) @@ -80,12 +86,14 @@ def run (cli): table.add_column("[overline white]RANK", '{:.5f}'.format(total_rank), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]TRUST", '{:.5f}'.format(total_trust), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]CONSENSUS", '{:.5f}'.format(total_consensus), footer_style = "overline white", justify='right', style='green', no_wrap=True) + table.add_column("[overline white]WCONSENSUS", '{:.5f}'.format(total_weight_consensus), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]INCENTIVE", '{:.5f}'.format(total_incentive), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]DIVIDENDS", '{:.5f}'.format(total_dividends), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]EMISSION(\u03C1)", '\u03C1{}'.format(int(total_emission)), footer_style = "overline white", justify='right', style='green', no_wrap=True) + table.add_column("[overline white]VTRUST", '{:.5f}'.format(total_validator_trust), footer_style = "overline white", justify='right', style='green', no_wrap=True) + table.add_column("[overline white]VAL", justify='right', style='green', no_wrap=True) table.add_column("[overline white]UPDATED", justify='right', no_wrap=True) table.add_column("[overline white]ACTIVE", justify='right', style='green', no_wrap=True) - table.add_column("[overline white]VAL", justify='right', style='green', no_wrap=True) table.add_column("[overline white]AXON", justify='left', style='dim blue', no_wrap=True) table.add_column("[overline white]HOTKEY", style='dim blue', no_wrap=False) table.add_column("[overline white]COLDKEY", style='dim purple', no_wrap=False) diff --git a/bittensor/_cli/commands/overview.py b/bittensor/_cli/commands/overview.py index 94f9ddd6cb..ae60ca0882 100644 --- a/bittensor/_cli/commands/overview.py +++ b/bittensor/_cli/commands/overview.py @@ -114,6 +114,8 @@ def run( cli ): total_rank = 0.0 total_trust = 0.0 total_consensus = 0.0 + total_validator_trust = 0.0 + total_weight_consensus = 0.0 total_incentive = 0.0 total_dividends = 0.0 total_emission = 0 @@ -126,6 +128,8 @@ def run( cli ): rank = nn.rank trust = nn.trust consensus = nn.consensus + validator_trust = nn.validator_trust + weight_consensus = nn.weight_consensus incentive = nn.incentive dividends = nn.dividends emission = int(nn.emission * 1000000000) @@ -139,12 +143,14 @@ def run( cli ): '{:.5f}'.format(stake), '{:.5f}'.format(rank), '{:.5f}'.format(trust), - '{:.5f}'.format(consensus), + '{:.5f}'.format(consensus), + '{:.5f}'.format(weight_consensus), '{:.5f}'.format(incentive), '{:.5f}'.format(dividends), '{}'.format(emission), - str(last_update), + '{:.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]', nn.hotkey ] @@ -152,9 +158,11 @@ def run( cli ): total_rank += rank total_trust += trust total_consensus += consensus + total_weight_consensus += weight_consensus total_incentive += incentive total_dividends += dividends total_emission += emission + total_validator_trust += validator_trust TABLE_DATA.append(row) total_neurons = len(neurons) @@ -174,8 +182,9 @@ def run( cli ): table.add_column("[overline white]INCENTIVE", '{:.5f}'.format(total_incentive), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]DIVIDENDS", '{:.5f}'.format(total_dividends), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]EMISSION(\u03C1)", '\u03C1{}'.format(int(total_emission)), footer_style = "overline white", justify='right', style='green', no_wrap=True) - table.add_column("[overline white]UPDATED", justify='right', no_wrap=True) + table.add_column("[overline white]VTRUST", '{:.5f}'.format(total_validator_trust), footer_style="overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]VAL", justify='right', no_wrap=True) + table.add_column("[overline white]UPDATED", justify='right', no_wrap=True) table.add_column("[overline white]AXON", justify='left', style='dim blue', no_wrap=True) table.add_column("[overline white]HOTKEY_SS58", style='dim blue', no_wrap=False) table.show_footer = True diff --git a/bittensor/_metagraph/__init__.py b/bittensor/_metagraph/__init__.py index d954627391..264b5a8a19 100644 --- a/bittensor/_metagraph/__init__.py +++ b/bittensor/_metagraph/__init__.py @@ -137,6 +137,8 @@ def from_neurons( network: str, netuid: int, neurons: List['bittensor.NeuronInfo ranks = [ 0 for _ in range(n_total) ] trust = [ 0 for _ in range(n_total) ] consensus = [ 0 for _ in range(n_total) ] + validator_trust = [ 0 for _ in range(n_total) ] + weight_consensus = [ 0 for _ in range(n_total) ] incentive = [ 0 for _ in range(n_total) ] emission = [ 0 for _ in range(n_total) ] dividends = [ 0 for _ in range(n_total) ] @@ -155,6 +157,8 @@ def from_neurons( network: str, netuid: int, neurons: List['bittensor.NeuronInfo ranks[n.uid] = n.rank trust[n.uid] = n.trust consensus[n.uid] = n.consensus + validator_trust[n.uid] = n.validator_trust + weight_consensus[n.uid] = n.weight_consensus incentive[n.uid] = n.incentive dividends[n.uid] = n.dividends emission[n.uid] = n.emission @@ -183,6 +187,8 @@ def from_neurons( network: str, netuid: int, neurons: List['bittensor.NeuronInfo tranks = torch.tensor( ranks, dtype=torch.float32 ) ttrust = torch.tensor( trust, dtype=torch.float32 ) tconsensus = torch.tensor( consensus, dtype=torch.float32 ) + tvalidator_trust = torch.tensor( validator_trust, dtype=torch.float32 ) + tweight_consensus = torch.tensor( weight_consensus, dtype=torch.float32 ) tincentive = torch.tensor( incentive, dtype=torch.float32 ) temission = torch.tensor( emission, dtype=torch.float32 ) tdividends = torch.tensor( dividends, dtype=torch.float32 ) @@ -203,6 +209,8 @@ def from_neurons( network: str, netuid: int, neurons: List['bittensor.NeuronInfo metagraph.ranks = torch.nn.Parameter( tranks, requires_grad=False ) metagraph.trust = torch.nn.Parameter( ttrust, requires_grad=False ) metagraph.consensus = torch.nn.Parameter( tconsensus, requires_grad=False ) + metagraph.validator_trust = torch.nn.Parameter( tvalidator_trust, requires_grad=False ) + metagraph.weight_consensus = torch.nn.Parameter( tweight_consensus, requires_grad=False ) metagraph.incentive = torch.nn.Parameter( tincentive, requires_grad=False ) metagraph.emission = torch.nn.Parameter( temission, requires_grad=False ) metagraph.dividends = torch.nn.Parameter( tdividends, requires_grad=False ) diff --git a/bittensor/_metagraph/metagraph_impl.py b/bittensor/_metagraph/metagraph_impl.py index 12d01ab170..c196d99e98 100644 --- a/bittensor/_metagraph/metagraph_impl.py +++ b/bittensor/_metagraph/metagraph_impl.py @@ -77,6 +77,8 @@ def clear( self ) -> 'Metagraph': self.ranks = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.trust = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.consensus = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) + self.validator_trust = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) + self.weight_consensus = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.incentive = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.emission = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.dividends = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) @@ -127,6 +129,18 @@ def T(self) -> torch.FloatTensor: """ return self.trust + @property + def Cw(self) -> torch.FloatTensor: + """ Weight consensus + """ + return self.weight_consensus + + @property + def Tv(self) -> torch.FloatTensor: + """ Validator trust + """ + return self.validator_trust + @property def D(self) -> torch.FloatTensor: """ Dividends @@ -296,6 +310,8 @@ def load_from_state_dict(self, state_dict:dict ) -> 'Metagraph': self.ranks = torch.nn.Parameter( state_dict['ranks'], requires_grad=False ) self.trust = torch.nn.Parameter( state_dict['trust'], requires_grad=False ) self.consensus = torch.nn.Parameter( state_dict['consensus'], requires_grad=False ) + self.validator_trust = torch.nn.Parameter( state_dict['validator_trust'], requires_grad=False ) + self.weight_consensus = torch.nn.Parameter( state_dict['weight_consensus'], requires_grad=False ) self.incentive = torch.nn.Parameter( state_dict['incentive'], requires_grad=False ) self.emission = torch.nn.Parameter( state_dict['emission'], requires_grad=False ) self.dividends = torch.nn.Parameter( state_dict['dividends'], requires_grad=False ) @@ -333,7 +349,7 @@ def sync ( self, netuid: int, subtensor: 'bittensor.Subtensor' = None, block: Op def to_dataframe(self): try: index = self.uids.tolist() - columns = [ 'uid', 'active', 'stake', 'rank', 'trust', 'consensus', 'incentive', 'dividends', 'emission'] + columns = [ 'uid', 'active', 'stake', 'rank', 'trust', 'consensus', 'validator_trust', 'weight_consensus', 'incentive', 'dividends', 'emission'] dataframe = pandas.DataFrame(columns = columns, index = index) for uid in self.uids.tolist(): v = { @@ -342,7 +358,9 @@ def to_dataframe(self): 'stake': self.stake[uid].item(), 'rank': self.ranks[uid].item(), 'trust': self.trust[uid].item(), - 'consensus': self.consensus[uid].item(), + 'consensus': self.consensus[uid].item(), + 'validator_trust': self.validator_trust[uid].item(), + 'weight_consensus': self.weight_consensus[uid].item(), 'incentive': self.incentive[uid].item(), 'dividends': self.dividends[uid].item(), 'emission': self.emission[uid].item() diff --git a/bittensor/_metagraph/metagraph_mock.py b/bittensor/_metagraph/metagraph_mock.py index 572c25c505..a62951aab5 100644 --- a/bittensor/_metagraph/metagraph_mock.py +++ b/bittensor/_metagraph/metagraph_mock.py @@ -48,6 +48,8 @@ def __init__( self ): tranks = torch.tensor( [1.0/2000 for _ in range (2000) ], dtype=torch.float32 ) ttrust = torch.tensor( [ 1.0 for _ in range (2000) ], dtype=torch.float32 ) tconsensus = torch.tensor( [1.0 for _ in range (2000) ], dtype=torch.float32 ) + tvalidator_trust = torch.tensor( [ 1.0 for _ in range (2000) ], dtype=torch.float32 ) + tweight_consensus = torch.tensor( [1.0 for _ in range (2000) ], dtype=torch.float32 ) tincentive = torch.tensor( [1.0/2000 for _ in range (2000) ], dtype=torch.float32 ) temission = torch.tensor( [1.0/2000 for _ in range (2000) ], dtype=torch.float32 ) tdividends = torch.tensor( [1.0/2000 for _ in range (2000) ], dtype=torch.float32 ) @@ -64,6 +66,8 @@ def __init__( self ): self.ranks = torch.nn.Parameter( tranks, requires_grad=False ) self.trust = torch.nn.Parameter( ttrust, requires_grad=False ) self.consensus = torch.nn.Parameter( tconsensus, requires_grad=False ) + self.validator_trust = torch.nn.Parameter( tvalidator_trust, requires_grad=False ) + self.weight_consensus = torch.nn.Parameter( tweight_consensus, requires_grad=False ) self.incentive = torch.nn.Parameter( tincentive, requires_grad=False ) self.emission = torch.nn.Parameter( temission, requires_grad=False ) self.dividends = torch.nn.Parameter( tdividends, requires_grad=False ) @@ -87,6 +91,8 @@ def clear( self ) -> 'Metagraph': self.ranks = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.trust = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.consensus = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) + self.validator_trust = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) + self.weight_consensus = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.incentive = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.emission = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) self.dividends = torch.nn.Parameter( torch.tensor( [], dtype=torch.float32), requires_grad=False ) diff --git a/bittensor/_neuron/text/core_server/run.py b/bittensor/_neuron/text/core_server/run.py index 675b1797a7..0de1d5b666 100644 --- a/bittensor/_neuron/text/core_server/run.py +++ b/bittensor/_neuron/text/core_server/run.py @@ -431,6 +431,8 @@ def backward_callback(inputs_x:torch.FloatTensor, grads_dy:torch.FloatTensor, sy 'rank': nn.rank, 'trust': nn.trust, 'consensus': nn.consensus, + 'validator_trust': nn.validator_trust, + 'weight_consensus': nn.weight_consensus, 'incentive': nn.incentive, 'emission': nn.emission, } @@ -451,6 +453,8 @@ def backward_callback(inputs_x:torch.FloatTensor, grads_dy:torch.FloatTensor, sy prometheus_guages.labels("rank").set( nn.rank ) prometheus_guages.labels("trust").set( nn.trust ) prometheus_guages.labels("consensus").set( nn.consensus ) + prometheus_guages.labels("validator_trust").set( nn.validator_trust ) + prometheus_guages.labels("weight_consensus").set( nn.weight_consensus ) prometheus_guages.labels("incentive").set( nn.incentive ) prometheus_guages.labels("emission").set( nn.emission ) diff --git a/bittensor/_subtensor/chain_data.py b/bittensor/_subtensor/chain_data.py index 1ef805f6e9..d23c30663d 100644 --- a/bittensor/_subtensor/chain_data.py +++ b/bittensor/_subtensor/chain_data.py @@ -45,6 +45,8 @@ class NeuronInfo: incentive: float consensus: float trust: float + weight_consensus: float + validator_trust: float dividends: float last_update: int validator_permit: bool @@ -71,6 +73,8 @@ def from_json(cls, json: Dict) -> 'NeuronInfo': incentive = json['incentive'] / U16_MAX, consensus = json['consensus'] / U16_MAX, trust = json['trust'] / U16_MAX, + weight_consensus = json['weight_consensus'] / U16_MAX, + validator_trust = json['validator_trust'] / U16_MAX, dividends = json['dividends'] / U16_MAX, last_update = json['last_update'], validator_permit = json['validator_permit'], @@ -93,6 +97,8 @@ def _null_neuron() -> 'NeuronInfo': incentive = 0, consensus = 0, trust = 0, + weight_consensus = 0, + validator_trust = 0, dividends = 0, last_update = 0, validator_permit = False, @@ -116,6 +122,8 @@ def _neuron_dict_to_namespace(neuron_dict) -> 'NeuronInfo': neuron.rank = neuron.rank / U64_MAX neuron.trust = neuron.trust / U64_MAX neuron.consensus = neuron.consensus / U64_MAX + neuron.validator_trust = neuron.validator_trust / U64_MAX + neuron.weight_consensus = neuron.weight_consensus / U64_MAX neuron.incentive = neuron.incentive / U64_MAX neuron.dividends = neuron.dividends / U64_MAX neuron.emission = neuron.emission / RAOPERTAO diff --git a/bittensor/_subtensor/subtensor_impl.py b/bittensor/_subtensor/subtensor_impl.py index 11f857231a..3a28fc687a 100644 --- a/bittensor/_subtensor/subtensor_impl.py +++ b/bittensor/_subtensor/subtensor_impl.py @@ -840,6 +840,8 @@ def _null_neuron() -> NeuronInfo: incentive = 0, consensus = 0, trust = 0, + weight_consensus = 0, + validator_trust = 0, dividends = 0, last_update = 0, validator_permit = False, diff --git a/bittensor/_subtensor/subtensor_mock.py b/bittensor/_subtensor/subtensor_mock.py index 05ab402acc..b69246576f 100644 --- a/bittensor/_subtensor/subtensor_mock.py +++ b/bittensor/_subtensor/subtensor_mock.py @@ -49,6 +49,8 @@ ["rank", "u64"], ["trust", "u64"], ["consensus", "u64"], + ["validator_trust", "u64"], + ["weight_consensus", "u64"], ["incentive", "u64"], ["dividends", "u64"], ["emission", "u64"], diff --git a/bittensor/_wallet/wallet_impl.py b/bittensor/_wallet/wallet_impl.py index 0c278c378b..9649a1a19b 100644 --- a/bittensor/_wallet/wallet_impl.py +++ b/bittensor/_wallet/wallet_impl.py @@ -87,6 +87,9 @@ def neuron(self, netuid: int) -> SimpleNamespace: def trust(self, netuid: int) -> SimpleNamespace: return self.get_neuron(netuid = netuid).trust + def validator_trust(self, netuid: int) -> SimpleNamespace: + return self.get_neuron(netuid = netuid).validator_trust + def rank(self, netuid: int) -> SimpleNamespace: return self.get_neuron(netuid = netuid).rank @@ -99,6 +102,9 @@ def dividends(self, netuid: int) -> SimpleNamespace: def consensus(self, netuid: int) -> SimpleNamespace: return self.get_neuron(netuid = netuid).consensus + def weight_consensus(self, netuid: int) -> SimpleNamespace: + return self.get_neuron(netuid = netuid).weight_consensus + def ip(self, netuid: int) -> SimpleNamespace: return self.get_neuron(netuid = netuid).ip From 1c9198b8e40c6301fdde4816f0735a89e7dc9396 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 26 Jan 2023 19:51:26 +0200 Subject: [PATCH 2/4] Change some neuron stats from u64 to u16 --- bittensor/_subtensor/chain_data.py | 14 +++++++------- bittensor/_subtensor/subtensor_mock.py | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bittensor/_subtensor/chain_data.py b/bittensor/_subtensor/chain_data.py index d23c30663d..646bb3f781 100644 --- a/bittensor/_subtensor/chain_data.py +++ b/bittensor/_subtensor/chain_data.py @@ -119,13 +119,13 @@ def _neuron_dict_to_namespace(neuron_dict) -> 'NeuronInfo': else: neuron = NeuronInfo( **neuron_dict ) neuron.stake = neuron.stake / RAOPERTAO - neuron.rank = neuron.rank / U64_MAX - neuron.trust = neuron.trust / U64_MAX - neuron.consensus = neuron.consensus / U64_MAX - neuron.validator_trust = neuron.validator_trust / U64_MAX - neuron.weight_consensus = neuron.weight_consensus / U64_MAX - neuron.incentive = neuron.incentive / U64_MAX - neuron.dividends = neuron.dividends / U64_MAX + neuron.rank = neuron.rank / U16_MAX + neuron.trust = neuron.trust / U16_MAX + neuron.consensus = neuron.consensus / U16_MAX + neuron.validator_trust = neuron.validator_trust / U16_MAX + neuron.weight_consensus = neuron.weight_consensus / U16_MAX + neuron.incentive = neuron.incentive / U16_MAX + neuron.dividends = neuron.dividends / U16_MAX neuron.emission = neuron.emission / RAOPERTAO return neuron diff --git a/bittensor/_subtensor/subtensor_mock.py b/bittensor/_subtensor/subtensor_mock.py index b69246576f..79c587830b 100644 --- a/bittensor/_subtensor/subtensor_mock.py +++ b/bittensor/_subtensor/subtensor_mock.py @@ -46,13 +46,13 @@ ["validator_permit", "bool"], ["priority", "u64"], ["stake", "u64"], - ["rank", "u64"], - ["trust", "u64"], - ["consensus", "u64"], - ["validator_trust", "u64"], - ["weight_consensus", "u64"], - ["incentive", "u64"], - ["dividends", "u64"], + ["rank", "u16"], + ["trust", "u16"], + ["consensus", "u16"], + ["validator_trust", "u16"], + ["weight_consensus", "u16"], + ["incentive", "u16"], + ["dividends", "u16"], ["emission", "u64"], ["bonds", "Vec<(u32, u64)>"], ["weights", "Vec<(u32, u32)>"] From 6ec1a5c60dba614d49a5cb6befc353d4d4d8f81b Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 26 Jan 2023 20:41:56 +0200 Subject: [PATCH 3/4] Correct type hints in wallet Return wallet field None when neuron is None. --- bittensor/_wallet/wallet_impl.py | 96 ++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/bittensor/_wallet/wallet_impl.py b/bittensor/_wallet/wallet_impl.py index 9649a1a19b..3a90a9315f 100644 --- a/bittensor/_wallet/wallet_impl.py +++ b/bittensor/_wallet/wallet_impl.py @@ -81,54 +81,90 @@ def __str__(self): def __repr__(self): return self.__str__() - def neuron(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid) + def neuron(self, netuid: int) -> Optional['bittensor.NeuronInfo']: + return self.get_neuron(netuid=netuid) - def trust(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).trust + def trust(self, netuid: int) -> Optional[float]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.trust - def validator_trust(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).validator_trust + def validator_trust(self, netuid: int) -> Optional[float]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.validator_trust - def rank(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).rank + def rank(self, netuid: int) -> Optional[float]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.rank - def incentive(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).incentive + def incentive(self, netuid: int) -> Optional[float]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.incentive - def dividends(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).dividends + def dividends(self, netuid: int) -> Optional[float]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.dividends - def consensus(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).consensus + def consensus(self, netuid: int) -> Optional[float]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.consensus - def weight_consensus(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).weight_consensus + def weight_consensus(self, netuid: int) -> Optional[float]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.weight_consensus - def ip(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).ip + def ip(self, netuid: int) -> Optional[SimpleNamespace]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.ip - def last_update(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).last_update + def last_update(self, netuid: int) -> Optional[int]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.last_update - def validator_permit(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).validator_permit + def validator_permit(self, netuid: int) -> Optional[bool]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.validator_permit - def weights(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).weights + def weights(self, netuid: int) -> Optional[list[list[int]]]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.weights - def bonds(self, netuid: int) -> SimpleNamespace: - return self.get_neuron(netuid = netuid).bonds + def bonds(self, netuid: int) -> Optional[list[list[int]]]: + neuron = self.get_neuron(netuid=netuid) + if neuron is None: + return None + return neuron.bonds - def uid(self, netuid: int) -> SimpleNamespace: - return self.get_uid(netuid = netuid) + def uid(self, netuid: int) -> int: + return self.get_uid(netuid=netuid) @property - def stake(self) -> SimpleNamespace: + def stake(self) -> 'bittensor.Balance': return self.get_stake() @property - def balance(self) -> SimpleNamespace: + def balance(self) -> 'bittensor.Balance': return self.get_balance() def is_registered( self, subtensor: Optional['bittensor.Subtensor'] = None, netuid: Optional[int] = None ) -> bool: From 72e92bfe465b25dc5752e5e93b7b283358d8bb67 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 26 Jan 2023 20:43:24 +0200 Subject: [PATCH 4/4] Remove wallet.ip NeuronInfo doesn't seem to have an ip field anymore. --- bittensor/_wallet/wallet_impl.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bittensor/_wallet/wallet_impl.py b/bittensor/_wallet/wallet_impl.py index 3a90a9315f..0d9d9b5179 100644 --- a/bittensor/_wallet/wallet_impl.py +++ b/bittensor/_wallet/wallet_impl.py @@ -126,12 +126,6 @@ def weight_consensus(self, netuid: int) -> Optional[float]: return None return neuron.weight_consensus - def ip(self, netuid: int) -> Optional[SimpleNamespace]: - neuron = self.get_neuron(netuid=netuid) - if neuron is None: - return None - return neuron.ip - def last_update(self, netuid: int) -> Optional[int]: neuron = self.get_neuron(netuid=netuid) if neuron is None: