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 = [
@@ -258,6 +259,11 @@ class MetagraphMixin(ABC):
258
259
_dtype_registry = {"int64" : np .int64 , "float32" : np .float32 , "bool" : bool }
259
260
260
261
# metagraph_info fields
262
+ name : str
263
+ symbol : str
264
+ network_registered_at : int
265
+ num_uids : int
266
+ max_uids : int
261
267
identities : list [Optional ["ChainIdentity" ]]
262
268
identity : Optional ["SubnetIdentity" ]
263
269
pruning_score : list [float ]
@@ -537,6 +543,15 @@ def __init__(
537
543
538
544
metagraph = Metagraph(netuid=123, network="finney", lite=True, sync=True)
539
545
"""
546
+ self .lite = lite
547
+ self .subtensor = subtensor
548
+ self .should_sync = sync
549
+ self .netuid = netuid
550
+ self .network , self .chain_endpoint = determine_chain_endpoint_and_network (
551
+ network
552
+ )
553
+ self .neurons = []
554
+ self .axons : list [AxonInfo ] = []
540
555
541
556
def __str__ (self ) -> str :
542
557
"""
@@ -937,6 +952,11 @@ def _apply_metagraph_info_mixin(self, metagraph_info: "MetagraphInfo"):
937
952
metagraph_info (MetagraphInfo): An instance of the MetagraphInfo class containing the data to be applied to
938
953
the current object.
939
954
"""
955
+ self .name = metagraph_info .name
956
+ self .symbol = metagraph_info .symbol
957
+ self .network_registered_at = metagraph_info .network_registered_at
958
+ self .num_uids = metagraph_info .num_uids
959
+ self .max_uids = metagraph_info .max_uids
940
960
self .identities = metagraph_info .identities
941
961
self .identity = metagraph_info .identity
942
962
self .pruning_score = metagraph_info .pruning_score
@@ -1043,10 +1063,6 @@ def __init__(
1043
1063
"""
1044
1064
BaseClass .__init__ (self )
1045
1065
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
1066
self ._dtype_registry = {
1051
1067
"int64" : torch .int64 ,
1052
1068
"float32" : torch .float32 ,
@@ -1107,10 +1123,6 @@ def __init__(
1107
1123
self .uids = torch .nn .Parameter (
1108
1124
torch .tensor ([], dtype = torch .int64 ), requires_grad = False
1109
1125
)
1110
- self .axons : list [AxonInfo ] = []
1111
- self .neurons = []
1112
- self .subtensor = subtensor
1113
- self .should_sync = sync
1114
1126
self .alpha_stake = torch .nn .Parameter (
1115
1127
torch .tensor ([], dtype = torch .float32 ), requires_grad = False
1116
1128
)
@@ -1239,9 +1251,6 @@ def __init__(
1239
1251
self .tao_stake : Tensor = np .array ([], dtype = np .int64 )
1240
1252
self .stake : Tensor = np .array ([], dtype = np .int64 )
1241
1253
self .total_stake : Tensor = np .array ([], dtype = np .int64 )
1242
-
1243
- self .axons : list [AxonInfo ] = []
1244
- self .neurons = []
1245
1254
self .subtensor = subtensor
1246
1255
self .should_sync = sync
1247
1256
@@ -1343,7 +1352,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
1343
1352
async def sync (
1344
1353
self ,
1345
1354
block : Optional [int ] = None ,
1346
- lite : bool = True ,
1355
+ lite : Optional [ bool ] = None ,
1347
1356
subtensor : Optional ["AsyncSubtensor" ] = None ,
1348
1357
):
1349
1358
"""
@@ -1354,8 +1363,9 @@ async def sync(
1354
1363
Args:
1355
1364
block (Optional[int]): A specific block number to synchronize with. If None, the metagraph syncs with the
1356
1365
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
1366
+ lite (Optional[ bool] ): If True, a lite version of the metagraph is used for quicker synchronization. This is
1358
1367
beneficial when full detail is not necessary, allowing for reduced computational and time overhead.
1368
+ Defaults to `True`.
1359
1369
subtensor (Optional[bittensor.core.subtensor.Subtensor]): An instance of the subtensor class from Bittensor,
1360
1370
providing an interface to the underlying blockchain data. If provided, this instance is used for data
1361
1371
retrieval during synchronization.
@@ -1390,6 +1400,9 @@ async def sync(
1390
1400
1391
1401
metagraph.sync(block=history_block, lite=False, subtensor=subtensor)
1392
1402
"""
1403
+ if lite is None :
1404
+ lite = self .lite
1405
+
1393
1406
subtensor = await self ._initialize_subtensor (subtensor )
1394
1407
1395
1408
if (
@@ -1608,8 +1621,14 @@ async def _get_all_stakes_from_chain(self):
1608
1621
)
1609
1622
return subnet_state
1610
1623
1611
- self .alpha_stake = subnet_state .alpha_stake
1612
- self .tao_stake = [b * 0.018 for b in subnet_state .tao_stake ]
1624
+ self .alpha_stake = self ._create_tensor (
1625
+ [b .tao for b in subnet_state .alpha_stake ],
1626
+ dtype = self ._dtype_registry ["float32" ],
1627
+ )
1628
+ self .tao_stake = self ._create_tensor (
1629
+ [b .tao * ROOT_TAO_STAKES_WEIGHT for b in subnet_state .tao_stake ],
1630
+ dtype = self ._dtype_registry ["float32" ],
1631
+ )
1613
1632
self .total_stake = self .stake = self ._create_tensor (
1614
1633
[stake .tao for stake in subnet_state .total_stake ],
1615
1634
dtype = self ._dtype_registry ["float32" ],
@@ -1641,7 +1660,7 @@ def __init__(
1641
1660
def sync (
1642
1661
self ,
1643
1662
block : Optional [int ] = None ,
1644
- lite : bool = True ,
1663
+ lite : Optional [ bool ] = None ,
1645
1664
subtensor : Optional ["Subtensor" ] = None ,
1646
1665
):
1647
1666
"""
@@ -1652,8 +1671,9 @@ def sync(
1652
1671
Args:
1653
1672
block (Optional[int]): A specific block number to synchronize with. If None, the metagraph syncs with the
1654
1673
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
1674
+ lite (Optional[ bool] ): If True, a lite version of the metagraph is used for quicker synchronization. This is
1656
1675
beneficial when full detail is not necessary, allowing for reduced computational and time overhead.
1676
+ Defaults to `True`.
1657
1677
subtensor (Optional[bittensor.core.subtensor.Subtensor]): An instance of the subtensor class from Bittensor,
1658
1678
providing an interface to the underlying blockchain data. If provided, this instance is used for data
1659
1679
retrieval during synchronization.
@@ -1688,6 +1708,8 @@ def sync(
1688
1708
1689
1709
metagraph.sync(block=history_block, lite=False, subtensor=subtensor)
1690
1710
"""
1711
+ if lite is None :
1712
+ lite = self .lite
1691
1713
1692
1714
# Initialize subtensor
1693
1715
subtensor = self ._initialize_subtensor (subtensor = subtensor )
@@ -1908,7 +1930,7 @@ def _get_all_stakes_from_chain(self):
1908
1930
dtype = self ._dtype_registry ["float32" ],
1909
1931
)
1910
1932
self .tao_stake = self ._create_tensor (
1911
- [b .tao * 0.018 for b in subnet_state .tao_stake ],
1933
+ [b .tao * ROOT_TAO_STAKES_WEIGHT for b in subnet_state .tao_stake ],
1912
1934
dtype = self ._dtype_registry ["float32" ],
1913
1935
)
1914
1936
self .total_stake = self .stake = self ._create_tensor (
0 commit comments