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 = [
@@ -542,6 +543,15 @@ def __init__(
542
543
543
544
metagraph = Metagraph(netuid=123, network="finney", lite=True, sync=True)
544
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 ] = []
545
555
546
556
def __str__ (self ) -> str :
547
557
"""
@@ -1053,10 +1063,6 @@ def __init__(
1053
1063
"""
1054
1064
BaseClass .__init__ (self )
1055
1065
MetagraphMixin .__init__ (self , netuid , network , lite , sync , subtensor )
1056
- self .netuid = netuid
1057
- self .network , self .chain_endpoint = determine_chain_endpoint_and_network (
1058
- network
1059
- )
1060
1066
self ._dtype_registry = {
1061
1067
"int64" : torch .int64 ,
1062
1068
"float32" : torch .float32 ,
@@ -1117,10 +1123,6 @@ def __init__(
1117
1123
self .uids = torch .nn .Parameter (
1118
1124
torch .tensor ([], dtype = torch .int64 ), requires_grad = False
1119
1125
)
1120
- self .axons : list [AxonInfo ] = []
1121
- self .neurons = []
1122
- self .subtensor = subtensor
1123
- self .should_sync = sync
1124
1126
self .alpha_stake = torch .nn .Parameter (
1125
1127
torch .tensor ([], dtype = torch .float32 ), requires_grad = False
1126
1128
)
@@ -1249,9 +1251,6 @@ def __init__(
1249
1251
self .tao_stake : Tensor = np .array ([], dtype = np .int64 )
1250
1252
self .stake : Tensor = np .array ([], dtype = np .int64 )
1251
1253
self .total_stake : Tensor = np .array ([], dtype = np .int64 )
1252
-
1253
- self .axons : list [AxonInfo ] = []
1254
- self .neurons = []
1255
1254
self .subtensor = subtensor
1256
1255
self .should_sync = sync
1257
1256
@@ -1353,7 +1352,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
1353
1352
async def sync (
1354
1353
self ,
1355
1354
block : Optional [int ] = None ,
1356
- lite : bool = True ,
1355
+ lite : Optional [ bool ] = None ,
1357
1356
subtensor : Optional ["AsyncSubtensor" ] = None ,
1358
1357
):
1359
1358
"""
@@ -1364,8 +1363,9 @@ async def sync(
1364
1363
Args:
1365
1364
block (Optional[int]): A specific block number to synchronize with. If None, the metagraph syncs with the
1366
1365
latest block. This allows for historical analysis or specific state examination of the network.
1367
- 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
1368
1367
beneficial when full detail is not necessary, allowing for reduced computational and time overhead.
1368
+ Defaults to `True`.
1369
1369
subtensor (Optional[bittensor.core.subtensor.Subtensor]): An instance of the subtensor class from Bittensor,
1370
1370
providing an interface to the underlying blockchain data. If provided, this instance is used for data
1371
1371
retrieval during synchronization.
@@ -1400,6 +1400,9 @@ async def sync(
1400
1400
1401
1401
metagraph.sync(block=history_block, lite=False, subtensor=subtensor)
1402
1402
"""
1403
+ if lite is None :
1404
+ lite = self .lite
1405
+
1403
1406
subtensor = await self ._initialize_subtensor (subtensor )
1404
1407
1405
1408
if (
@@ -1618,8 +1621,14 @@ async def _get_all_stakes_from_chain(self):
1618
1621
)
1619
1622
return subnet_state
1620
1623
1621
- self .alpha_stake = subnet_state .alpha_stake
1622
- 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
+ )
1623
1632
self .total_stake = self .stake = self ._create_tensor (
1624
1633
[stake .tao for stake in subnet_state .total_stake ],
1625
1634
dtype = self ._dtype_registry ["float32" ],
@@ -1651,7 +1660,7 @@ def __init__(
1651
1660
def sync (
1652
1661
self ,
1653
1662
block : Optional [int ] = None ,
1654
- lite : bool = True ,
1663
+ lite : Optional [ bool ] = None ,
1655
1664
subtensor : Optional ["Subtensor" ] = None ,
1656
1665
):
1657
1666
"""
@@ -1662,8 +1671,9 @@ def sync(
1662
1671
Args:
1663
1672
block (Optional[int]): A specific block number to synchronize with. If None, the metagraph syncs with the
1664
1673
latest block. This allows for historical analysis or specific state examination of the network.
1665
- 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
1666
1675
beneficial when full detail is not necessary, allowing for reduced computational and time overhead.
1676
+ Defaults to `True`.
1667
1677
subtensor (Optional[bittensor.core.subtensor.Subtensor]): An instance of the subtensor class from Bittensor,
1668
1678
providing an interface to the underlying blockchain data. If provided, this instance is used for data
1669
1679
retrieval during synchronization.
@@ -1698,6 +1708,8 @@ def sync(
1698
1708
1699
1709
metagraph.sync(block=history_block, lite=False, subtensor=subtensor)
1700
1710
"""
1711
+ if lite is None :
1712
+ lite = self .lite
1701
1713
1702
1714
# Initialize subtensor
1703
1715
subtensor = self ._initialize_subtensor (subtensor = subtensor )
@@ -1918,7 +1930,7 @@ def _get_all_stakes_from_chain(self):
1918
1930
dtype = self ._dtype_registry ["float32" ],
1919
1931
)
1920
1932
self .tao_stake = self ._create_tensor (
1921
- [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 ],
1922
1934
dtype = self ._dtype_registry ["float32" ],
1923
1935
)
1924
1936
self .total_stake = self .stake = self ._create_tensor (
0 commit comments