4242
4343
4444Tensor = Union ["torch.nn.Parameter" , NDArray ]
45+ ROOT_TAO_STAKES_WEIGHT = 0.018
4546
4647
4748METAGRAPH_STATE_DICT_NDARRAY_KEYS = [
@@ -258,6 +259,11 @@ class MetagraphMixin(ABC):
258259 _dtype_registry = {"int64" : np .int64 , "float32" : np .float32 , "bool" : bool }
259260
260261 # metagraph_info fields
262+ name : str
263+ symbol : str
264+ network_registered_at : int
265+ num_uids : int
266+ max_uids : int
261267 identities : list [Optional ["ChainIdentity" ]]
262268 identity : Optional ["SubnetIdentity" ]
263269 pruning_score : list [float ]
@@ -537,6 +543,15 @@ def __init__(
537543
538544 metagraph = Metagraph(netuid=123, network="finney", lite=True, sync=True)
539545 """
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 ] = []
540555
541556 def __str__ (self ) -> str :
542557 """
@@ -937,6 +952,11 @@ def _apply_metagraph_info_mixin(self, metagraph_info: "MetagraphInfo"):
937952 metagraph_info (MetagraphInfo): An instance of the MetagraphInfo class containing the data to be applied to
938953 the current object.
939954 """
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
940960 self .identities = metagraph_info .identities
941961 self .identity = metagraph_info .identity
942962 self .pruning_score = metagraph_info .pruning_score
@@ -1043,10 +1063,6 @@ def __init__(
10431063 """
10441064 BaseClass .__init__ (self )
10451065 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- )
10501066 self ._dtype_registry = {
10511067 "int64" : torch .int64 ,
10521068 "float32" : torch .float32 ,
@@ -1107,10 +1123,6 @@ def __init__(
11071123 self .uids = torch .nn .Parameter (
11081124 torch .tensor ([], dtype = torch .int64 ), requires_grad = False
11091125 )
1110- self .axons : list [AxonInfo ] = []
1111- self .neurons = []
1112- self .subtensor = subtensor
1113- self .should_sync = sync
11141126 self .alpha_stake = torch .nn .Parameter (
11151127 torch .tensor ([], dtype = torch .float32 ), requires_grad = False
11161128 )
@@ -1239,9 +1251,6 @@ def __init__(
12391251 self .tao_stake : Tensor = np .array ([], dtype = np .int64 )
12401252 self .stake : Tensor = np .array ([], dtype = np .int64 )
12411253 self .total_stake : Tensor = np .array ([], dtype = np .int64 )
1242-
1243- self .axons : list [AxonInfo ] = []
1244- self .neurons = []
12451254 self .subtensor = subtensor
12461255 self .should_sync = sync
12471256
@@ -1343,7 +1352,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
13431352 async def sync (
13441353 self ,
13451354 block : Optional [int ] = None ,
1346- lite : bool = True ,
1355+ lite : Optional [ bool ] = None ,
13471356 subtensor : Optional ["AsyncSubtensor" ] = None ,
13481357 ):
13491358 """
@@ -1354,8 +1363,9 @@ async def sync(
13541363 Args:
13551364 block (Optional[int]): A specific block number to synchronize with. If None, the metagraph syncs with the
13561365 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
13581367 beneficial when full detail is not necessary, allowing for reduced computational and time overhead.
1368+ Defaults to `True`.
13591369 subtensor (Optional[bittensor.core.subtensor.Subtensor]): An instance of the subtensor class from Bittensor,
13601370 providing an interface to the underlying blockchain data. If provided, this instance is used for data
13611371 retrieval during synchronization.
@@ -1390,6 +1400,9 @@ async def sync(
13901400
13911401 metagraph.sync(block=history_block, lite=False, subtensor=subtensor)
13921402 """
1403+ if lite is None :
1404+ lite = self .lite
1405+
13931406 subtensor = await self ._initialize_subtensor (subtensor )
13941407
13951408 if (
@@ -1608,8 +1621,14 @@ async def _get_all_stakes_from_chain(self):
16081621 )
16091622 return subnet_state
16101623
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+ )
16131632 self .total_stake = self .stake = self ._create_tensor (
16141633 [stake .tao for stake in subnet_state .total_stake ],
16151634 dtype = self ._dtype_registry ["float32" ],
@@ -1641,7 +1660,7 @@ def __init__(
16411660 def sync (
16421661 self ,
16431662 block : Optional [int ] = None ,
1644- lite : bool = True ,
1663+ lite : Optional [ bool ] = None ,
16451664 subtensor : Optional ["Subtensor" ] = None ,
16461665 ):
16471666 """
@@ -1652,8 +1671,9 @@ def sync(
16521671 Args:
16531672 block (Optional[int]): A specific block number to synchronize with. If None, the metagraph syncs with the
16541673 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
16561675 beneficial when full detail is not necessary, allowing for reduced computational and time overhead.
1676+ Defaults to `True`.
16571677 subtensor (Optional[bittensor.core.subtensor.Subtensor]): An instance of the subtensor class from Bittensor,
16581678 providing an interface to the underlying blockchain data. If provided, this instance is used for data
16591679 retrieval during synchronization.
@@ -1688,6 +1708,8 @@ def sync(
16881708
16891709 metagraph.sync(block=history_block, lite=False, subtensor=subtensor)
16901710 """
1711+ if lite is None :
1712+ lite = self .lite
16911713
16921714 # Initialize subtensor
16931715 subtensor = self ._initialize_subtensor (subtensor = subtensor )
@@ -1908,7 +1930,7 @@ def _get_all_stakes_from_chain(self):
19081930 dtype = self ._dtype_registry ["float32" ],
19091931 )
19101932 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 ],
19121934 dtype = self ._dtype_registry ["float32" ],
19131935 )
19141936 self .total_stake = self .stake = self ._create_tensor (
0 commit comments