19
19
MetagraphInfoPool ,
20
20
MetagraphInfoParams ,
21
21
)
22
-
22
+ from bittensor . utils import determine_chain_endpoint_and_network
23
23
from bittensor .utils .btlogging import logging
24
24
from bittensor .utils .registration import torch , use_torch
25
25
from bittensor .utils .weight_utils import (
42
42
43
43
44
44
Tensor = Union ["torch.nn.Parameter" , NDArray ]
45
+ ROOT_TAO_STAKES_WEIGHT = 0.018
45
46
46
47
47
48
METAGRAPH_STATE_DICT_NDARRAY_KEYS = [
@@ -142,26 +143,6 @@ def latest_block_path(dir_path: str) -> str:
142
143
return latest_file_full_path
143
144
144
145
145
- def determine_chain_endpoint_and_network (network : str ) -> tuple [str , str ]:
146
- """
147
- Determine the chain endpoint and network name from the passed arg
148
-
149
- Args:
150
- network: The network name (e.g. 'finney', 'test') or
151
- chain endpoint (e.g. wss://entrypoint-finney.opentensor.ai:443)
152
-
153
- Returns:
154
- (network name, chain endpoint)
155
- """
156
- pathless_network = network [:- 1 ] if network .endswith ("/" ) else network
157
- if pathless_network in settings .NETWORK_MAP :
158
- return pathless_network , settings .NETWORK_MAP [pathless_network ]
159
- elif pathless_network in settings .REVERSE_NETWORK_MAP :
160
- return settings .REVERSE_NETWORK_MAP [pathless_network ], pathless_network
161
- else :
162
- return "unknown" , network
163
-
164
-
165
146
class MetagraphMixin (ABC ):
166
147
"""
167
148
The metagraph class is a core component of the Bittensor network, representing the neural graph that forms the
@@ -258,6 +239,11 @@ class MetagraphMixin(ABC):
258
239
_dtype_registry = {"int64" : np .int64 , "float32" : np .float32 , "bool" : bool }
259
240
260
241
# metagraph_info fields
242
+ name : str
243
+ symbol : str
244
+ network_registered_at : int
245
+ num_uids : int
246
+ max_uids : int
261
247
identities : list [Optional ["ChainIdentity" ]]
262
248
identity : Optional ["SubnetIdentity" ]
263
249
pruning_score : list [float ]
@@ -537,6 +523,15 @@ def __init__(
537
523
538
524
metagraph = Metagraph(netuid=123, network="finney", lite=True, sync=True)
539
525
"""
526
+ self .lite = lite
527
+ self .subtensor = subtensor
528
+ self .should_sync = sync
529
+ self .netuid = netuid
530
+ self .network , self .chain_endpoint = determine_chain_endpoint_and_network (
531
+ network
532
+ )
533
+ self .neurons = []
534
+ self .axons : list [AxonInfo ] = []
540
535
541
536
def __str__ (self ) -> str :
542
537
"""
@@ -937,6 +932,11 @@ def _apply_metagraph_info_mixin(self, metagraph_info: "MetagraphInfo"):
937
932
metagraph_info (MetagraphInfo): An instance of the MetagraphInfo class containing the data to be applied to
938
933
the current object.
939
934
"""
935
+ self .name = metagraph_info .name
936
+ self .symbol = metagraph_info .symbol
937
+ self .network_registered_at = metagraph_info .network_registered_at
938
+ self .num_uids = metagraph_info .num_uids
939
+ self .max_uids = metagraph_info .max_uids
940
940
self .identities = metagraph_info .identities
941
941
self .identity = metagraph_info .identity
942
942
self .pruning_score = metagraph_info .pruning_score
@@ -1043,10 +1043,6 @@ def __init__(
1043
1043
"""
1044
1044
BaseClass .__init__ (self )
1045
1045
MetagraphMixin .__init__ (self , netuid , network , lite , sync , subtensor )
1046
- self .netuid = netuid
1047
- self .network , self .chain_endpoint = determine_chain_endpoint_and_network (
1048
- network
1049
- )
1050
1046
self ._dtype_registry = {
1051
1047
"int64" : torch .int64 ,
1052
1048
"float32" : torch .float32 ,
@@ -1107,10 +1103,6 @@ def __init__(
1107
1103
self .uids = torch .nn .Parameter (
1108
1104
torch .tensor ([], dtype = torch .int64 ), requires_grad = False
1109
1105
)
1110
- self .axons : list [AxonInfo ] = []
1111
- self .neurons = []
1112
- self .subtensor = subtensor
1113
- self .should_sync = sync
1114
1106
self .alpha_stake = torch .nn .Parameter (
1115
1107
torch .tensor ([], dtype = torch .float32 ), requires_grad = False
1116
1108
)
@@ -1239,9 +1231,6 @@ def __init__(
1239
1231
self .tao_stake : Tensor = np .array ([], dtype = np .int64 )
1240
1232
self .stake : Tensor = np .array ([], dtype = np .int64 )
1241
1233
self .total_stake : Tensor = np .array ([], dtype = np .int64 )
1242
-
1243
- self .axons : list [AxonInfo ] = []
1244
- self .neurons = []
1245
1234
self .subtensor = subtensor
1246
1235
self .should_sync = sync
1247
1236
@@ -1343,7 +1332,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
1343
1332
async def sync (
1344
1333
self ,
1345
1334
block : Optional [int ] = None ,
1346
- lite : bool = True ,
1335
+ lite : Optional [ bool ] = None ,
1347
1336
subtensor : Optional ["AsyncSubtensor" ] = None ,
1348
1337
):
1349
1338
"""
@@ -1354,8 +1343,9 @@ async def sync(
1354
1343
Args:
1355
1344
block (Optional[int]): A specific block number to synchronize with. If None, the metagraph syncs with the
1356
1345
latest block. This allows for historical analysis or specific state examination of the network.
1357
- lite (bool): If True, a lite version of the metagraph is used for quicker synchronization. This is
1346
+ lite (Optional[ bool] ): If True, a lite version of the metagraph is used for quicker synchronization. This is
1358
1347
beneficial when full detail is not necessary, allowing for reduced computational and time overhead.
1348
+ Defaults to `True`.
1359
1349
subtensor (Optional[bittensor.core.subtensor.Subtensor]): An instance of the subtensor class from Bittensor,
1360
1350
providing an interface to the underlying blockchain data. If provided, this instance is used for data
1361
1351
retrieval during synchronization.
@@ -1390,6 +1380,9 @@ async def sync(
1390
1380
1391
1381
metagraph.sync(block=history_block, lite=False, subtensor=subtensor)
1392
1382
"""
1383
+ if lite is None :
1384
+ lite = self .lite
1385
+
1393
1386
subtensor = await self ._initialize_subtensor (subtensor )
1394
1387
1395
1388
if (
@@ -1608,8 +1601,14 @@ async def _get_all_stakes_from_chain(self):
1608
1601
)
1609
1602
return subnet_state
1610
1603
1611
- self .alpha_stake = subnet_state .alpha_stake
1612
- self .tao_stake = [b * 0.018 for b in subnet_state .tao_stake ]
1604
+ self .alpha_stake = self ._create_tensor (
1605
+ [b .tao for b in subnet_state .alpha_stake ],
1606
+ dtype = self ._dtype_registry ["float32" ],
1607
+ )
1608
+ self .tao_stake = self ._create_tensor (
1609
+ [b .tao * ROOT_TAO_STAKES_WEIGHT for b in subnet_state .tao_stake ],
1610
+ dtype = self ._dtype_registry ["float32" ],
1611
+ )
1613
1612
self .total_stake = self .stake = self ._create_tensor (
1614
1613
[stake .tao for stake in subnet_state .total_stake ],
1615
1614
dtype = self ._dtype_registry ["float32" ],
@@ -1641,7 +1640,7 @@ def __init__(
1641
1640
def sync (
1642
1641
self ,
1643
1642
block : Optional [int ] = None ,
1644
- lite : bool = True ,
1643
+ lite : Optional [ bool ] = None ,
1645
1644
subtensor : Optional ["Subtensor" ] = None ,
1646
1645
):
1647
1646
"""
@@ -1652,8 +1651,9 @@ def sync(
1652
1651
Args:
1653
1652
block (Optional[int]): A specific block number to synchronize with. If None, the metagraph syncs with the
1654
1653
latest block. This allows for historical analysis or specific state examination of the network.
1655
- lite (bool): If True, a lite version of the metagraph is used for quicker synchronization. This is
1654
+ lite (Optional[ bool] ): If True, a lite version of the metagraph is used for quicker synchronization. This is
1656
1655
beneficial when full detail is not necessary, allowing for reduced computational and time overhead.
1656
+ Defaults to `True`.
1657
1657
subtensor (Optional[bittensor.core.subtensor.Subtensor]): An instance of the subtensor class from Bittensor,
1658
1658
providing an interface to the underlying blockchain data. If provided, this instance is used for data
1659
1659
retrieval during synchronization.
@@ -1688,6 +1688,8 @@ def sync(
1688
1688
1689
1689
metagraph.sync(block=history_block, lite=False, subtensor=subtensor)
1690
1690
"""
1691
+ if lite is None :
1692
+ lite = self .lite
1691
1693
1692
1694
# Initialize subtensor
1693
1695
subtensor = self ._initialize_subtensor (subtensor = subtensor )
@@ -1908,7 +1910,7 @@ def _get_all_stakes_from_chain(self):
1908
1910
dtype = self ._dtype_registry ["float32" ],
1909
1911
)
1910
1912
self .tao_stake = self ._create_tensor (
1911
- [b .tao * 0.018 for b in subnet_state .tao_stake ],
1913
+ [b .tao * ROOT_TAO_STAKES_WEIGHT for b in subnet_state .tao_stake ],
1912
1914
dtype = self ._dtype_registry ["float32" ],
1913
1915
)
1914
1916
self .total_stake = self .stake = self ._create_tensor (
0 commit comments