1
+ import asyncio
1
2
import copy
2
3
import os
3
4
import pickle
@@ -1397,13 +1398,13 @@ async def sync(
1397
1398
1398
1399
# If not a 'lite' version, compute and set weights and bonds for each neuron
1399
1400
if not lite :
1400
- await self ._set_weights_and_bonds (subtensor = subtensor )
1401
+ await self ._set_weights_and_bonds (subtensor = subtensor , block = block )
1401
1402
1402
1403
# Fills in the stake associated attributes of a class instance from a chain response.
1403
1404
await self ._get_all_stakes_from_chain (block = block )
1404
1405
1405
1406
# apply MetagraphInfo data to instance
1406
- await self ._apply_metagraph_info ()
1407
+ await self ._apply_metagraph_info (block = block )
1407
1408
1408
1409
async def _initialize_subtensor (
1409
1410
self , subtensor : "AsyncSubtensor"
@@ -1476,9 +1477,7 @@ async def _assign_neurons(
1476
1477
self .neurons = await subtensor .neurons (block = block , netuid = self .netuid )
1477
1478
self .lite = lite
1478
1479
1479
- async def _set_weights_and_bonds (
1480
- self , subtensor : Optional ["AsyncSubtensor" ] = None
1481
- ):
1480
+ async def _set_weights_and_bonds (self , subtensor : "AsyncSubtensor" , block : int ):
1482
1481
"""
1483
1482
Computes and sets the weights and bonds for each neuron in the metagraph. This method is responsible for
1484
1483
processing the raw weight and bond data obtained from the network and converting it into a structured format
@@ -1499,6 +1498,7 @@ async def _set_weights_and_bonds(
1499
1498
[neuron .weights for neuron in self .neurons ],
1500
1499
"weights" ,
1501
1500
subtensor ,
1501
+ block = block ,
1502
1502
)
1503
1503
else :
1504
1504
self .weights = self ._process_weights_or_bonds (
@@ -1509,7 +1509,7 @@ async def _set_weights_and_bonds(
1509
1509
)
1510
1510
1511
1511
async def _process_root_weights (
1512
- self , data : list , attribute : str , subtensor : "AsyncSubtensor"
1512
+ self , data : list , attribute : str , subtensor : "AsyncSubtensor" , block : int
1513
1513
) -> Union [NDArray , "torch.nn.Parameter" ]:
1514
1514
"""
1515
1515
Specifically processes the root weights data for the metagraph. This method is similar to :func:`_process_weights_or_bonds`
@@ -1530,8 +1530,10 @@ async def _process_root_weights(
1530
1530
self.root_weights = self._process_root_weights(raw_root_weights_data, "weights", subtensor)
1531
1531
"""
1532
1532
data_array = []
1533
- n_subnets = await subtensor .get_total_subnets () or 0
1534
- subnets = await subtensor .get_subnets ()
1533
+ n_subnets_ , subnets = await asyncio .gather (
1534
+ subtensor .get_total_subnets (block = block ), subtensor .get_subnets (block = block )
1535
+ )
1536
+ n_subnets = n_subnets_ or 0
1535
1537
for item in data :
1536
1538
if len (item ) == 0 :
1537
1539
if use_torch ():
@@ -1612,9 +1614,11 @@ async def _get_all_stakes_from_chain(self, block: int):
1612
1614
except (SubstrateRequestException , AttributeError ) as e :
1613
1615
logging .debug (e )
1614
1616
1615
- async def _apply_metagraph_info (self ):
1617
+ async def _apply_metagraph_info (self , block : int ):
1616
1618
"""Retrieves metagraph information for a specific subnet and applies it using a mixin."""
1617
- metagraph_info = await self .subtensor .get_metagraph_info (self .netuid )
1619
+ metagraph_info = await self .subtensor .get_metagraph_info (
1620
+ self .netuid , block = block
1621
+ )
1618
1622
if metagraph_info :
1619
1623
self ._apply_metagraph_info_mixin (metagraph_info = metagraph_info )
1620
1624
@@ -1711,13 +1715,13 @@ def sync(
1711
1715
1712
1716
# If not a 'lite' version, compute and set weights and bonds for each neuron
1713
1717
if not lite :
1714
- self ._set_weights_and_bonds (subtensor = subtensor )
1718
+ self ._set_weights_and_bonds (subtensor = subtensor , block = block )
1715
1719
1716
1720
# Fills in the stake associated attributes of a class instance from a chain response.
1717
1721
self ._get_all_stakes_from_chain (block = block )
1718
1722
1719
1723
# apply MetagraphInfo data to instance
1720
- self ._apply_metagraph_info ()
1724
+ self ._apply_metagraph_info (block = block )
1721
1725
1722
1726
def _initialize_subtensor (self , subtensor : "Subtensor" ) -> "Subtensor" :
1723
1727
"""
@@ -1787,7 +1791,7 @@ def _assign_neurons(self, block: int, lite: bool, subtensor: "Subtensor"):
1787
1791
self .neurons = subtensor .neurons (block = block , netuid = self .netuid )
1788
1792
self .lite = lite
1789
1793
1790
- def _set_weights_and_bonds (self , subtensor : Optional [ "Subtensor" ] = None ):
1794
+ def _set_weights_and_bonds (self , block : int , subtensor : "Subtensor" ):
1791
1795
"""
1792
1796
Computes and sets the weights and bonds for each neuron in the metagraph. This method is responsible for
1793
1797
processing the raw weight and bond data obtained from the network and converting it into a structured format
@@ -1804,9 +1808,7 @@ def _set_weights_and_bonds(self, subtensor: Optional["Subtensor"] = None):
1804
1808
"""
1805
1809
if self .netuid == 0 :
1806
1810
self .weights = self ._process_root_weights (
1807
- [neuron .weights for neuron in self .neurons ],
1808
- "weights" ,
1809
- subtensor ,
1811
+ [neuron .weights for neuron in self .neurons ], "weights" , subtensor , block
1810
1812
)
1811
1813
else :
1812
1814
self .weights = self ._process_weights_or_bonds (
@@ -1817,7 +1819,7 @@ def _set_weights_and_bonds(self, subtensor: Optional["Subtensor"] = None):
1817
1819
)
1818
1820
1819
1821
def _process_root_weights (
1820
- self , data : list , attribute : str , subtensor : "Subtensor"
1822
+ self , data : list , attribute : str , subtensor : "Subtensor" , block : int
1821
1823
) -> Union [NDArray , "torch.nn.Parameter" ]:
1822
1824
"""
1823
1825
Specifically processes the root weights data for the metagraph. This method is similar to :func:`_process_weights_or_bonds`
@@ -1838,8 +1840,8 @@ def _process_root_weights(
1838
1840
self.root_weights = self._process_root_weights(raw_root_weights_data, "weights", subtensor)
1839
1841
"""
1840
1842
data_array = []
1841
- n_subnets = subtensor .get_total_subnets () or 0
1842
- subnets = subtensor .get_subnets ()
1843
+ n_subnets = subtensor .get_total_subnets (block = block ) or 0
1844
+ subnets = subtensor .get_subnets (block = block )
1843
1845
for item in data :
1844
1846
if len (item ) == 0 :
1845
1847
if use_torch ():
@@ -1920,9 +1922,9 @@ def _get_all_stakes_from_chain(self, block: int):
1920
1922
except (SubstrateRequestException , AttributeError ) as e :
1921
1923
logging .debug (e )
1922
1924
1923
- def _apply_metagraph_info (self ):
1925
+ def _apply_metagraph_info (self , block : int ):
1924
1926
"""Retrieves metagraph information for a specific subnet and applies it using a mixin."""
1925
- metagraph_info = self .subtensor .get_metagraph_info (self .netuid )
1927
+ metagraph_info = self .subtensor .get_metagraph_info (self .netuid , block = block )
1926
1928
if metagraph_info :
1927
1929
self ._apply_metagraph_info_mixin (metagraph_info = metagraph_info )
1928
1930
0 commit comments