Skip to content

Commit 920a1e7

Browse files
authored
Merge pull request #2870 from opentensor/fix/roman/selective-metagraph
Selective-metagraph -> MetagraphInfo
2 parents 3835390 + 850170b commit 920a1e7

File tree

5 files changed

+409
-464
lines changed

5 files changed

+409
-464
lines changed

bittensor/core/async_subtensor.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
NeuronInfo,
2424
ProposalVoteData,
2525
StakeInfo,
26-
SelectiveMetagraphIndex,
2726
SubnetHyperparameters,
2827
SubnetIdentity,
2928
SubnetInfo,
@@ -1543,59 +1542,32 @@ async def get_minimum_required_stake(self):
15431542
async def get_metagraph_info(
15441543
self,
15451544
netuid: int,
1546-
field_indices: Optional[list["SelectiveMetagraphIndex"]] = None,
15471545
block: Optional[int] = None,
15481546
block_hash: Optional[str] = None,
15491547
reuse_block: bool = False,
15501548
) -> Optional[MetagraphInfo]:
15511549
"""
1552-
Retrieves full or partial metagraph information for the specified subnet (netuid).
1550+
Retrieves the MetagraphInfo dataclass from the node for a single subnet (netuid)
15531551
15541552
Arguments:
1555-
netuid: The NetUID of the subnet to query.
1556-
field_indices: An optional list of SelectiveMetagraphIndex values specifying which fields to retrieve. If
1557-
not provided, all available fields will be returned.
1553+
netuid: The NetUID of the subnet.
15581554
block: the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or
15591555
reuse_block
15601556
block_hash: The hash of blockchain block number for the query. Do not specify if using
15611557
block or reuse_block
15621558
reuse_block: Whether to reuse the last-used block hash. Do not set if using block_hash or block.
15631559
15641560
Returns:
1565-
Optional[MetagraphInfo]: A MetagraphInfo object containing the requested subnet data, or None if the subnet
1566-
with the given netuid does not exist.
1567-
1568-
Example:
1569-
meta_info = await subtensor.get_metagraph_info(netuid=2)
1570-
1571-
partial_meta_info = await subtensor.get_metagraph_info(
1572-
netuid=2,
1573-
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
1574-
)
1561+
MetagraphInfo dataclass
15751562
"""
1576-
indexes = SelectiveMetagraphIndex.all_indices()
1577-
1578-
if field_indices:
1579-
if isinstance(field_indices, list) and all(
1580-
isinstance(f, (SelectiveMetagraphIndex, int)) for f in field_indices
1581-
):
1582-
indexes = [
1583-
f.value if isinstance(f, SelectiveMetagraphIndex) else f
1584-
for f in field_indices
1585-
]
1586-
else:
1587-
raise ValueError(
1588-
"`field_indices` must be a list of SelectiveMetagraphIndex items."
1589-
)
1590-
15911563
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
15921564
if not block_hash and reuse_block:
15931565
block_hash = self.substrate.last_block_hash
15941566

15951567
query = await self.substrate.runtime_call(
15961568
"SubnetInfoRuntimeApi",
1597-
"get_selective_metagraph",
1598-
params=[netuid, indexes if 0 in indexes else [0] + indexes],
1569+
"get_metagraph",
1570+
params=[netuid],
15991571
block_hash=block_hash,
16001572
)
16011573
if query.value is None:

bittensor/core/subtensor.py

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
MetagraphInfo,
2222
NeuronInfo,
2323
NeuronInfoLite,
24-
SelectiveMetagraphIndex,
2524
StakeInfo,
2625
SubnetInfo,
2726
SubnetIdentity,
@@ -1190,53 +1189,24 @@ def get_minimum_required_stake(self) -> Balance:
11901189
return Balance.from_rao(getattr(result, "value", 0))
11911190

11921191
def get_metagraph_info(
1193-
self,
1194-
netuid: int,
1195-
field_indices: Optional[list[Union["SelectiveMetagraphIndex", int]]] = None,
1196-
block: Optional[int] = None,
1192+
self, netuid: int, block: Optional[int] = None
11971193
) -> Optional[MetagraphInfo]:
11981194
"""
1199-
Retrieves full or partial metagraph information for the specified subnet (netuid).
1195+
Retrieves the MetagraphInfo dataclass from the node for a single subnet (netuid)
12001196
12011197
Arguments:
1202-
netuid: The NetUID of the subnet to query.
1203-
field_indices: An optional list of SelectiveMetagraphIndex values specifying which fields to retrieve. If
1204-
not provided, all available fields will be returned.
1205-
block: The block number at which to query the data. If not specified, the current block or one determined
1206-
via reuse_block or block_hash will be used.
1198+
netuid: The NetUID of the subnet.
1199+
block: the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or
1200+
reuse_block
12071201
12081202
Returns:
1209-
Optional[MetagraphInfo]: A MetagraphInfo object containing the requested subnet data, or None if the subnet
1210-
with the given netuid does not exist.
1211-
1212-
Example:
1213-
meta_info = subtensor.get_metagraph_info(netuid=2)
1214-
1215-
partial_meta_info = subtensor.get_metagraph_info(
1216-
netuid=2,
1217-
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
1218-
)
1203+
MetagraphInfo dataclass
12191204
"""
1220-
indexes = SelectiveMetagraphIndex.all_indices()
1221-
1222-
if field_indices:
1223-
if isinstance(field_indices, list) and all(
1224-
isinstance(f, (SelectiveMetagraphIndex, int)) for f in field_indices
1225-
):
1226-
indexes = [
1227-
f.value if isinstance(f, SelectiveMetagraphIndex) else f
1228-
for f in field_indices
1229-
]
1230-
else:
1231-
raise ValueError(
1232-
"`field_indices` must be a list of SelectiveMetagraphIndex items."
1233-
)
1234-
12351205
block_hash = self.determine_block_hash(block)
12361206
query = self.substrate.runtime_call(
12371207
"SubnetInfoRuntimeApi",
1238-
"get_selective_metagraph",
1239-
params=[netuid, indexes if 0 in indexes else [0] + indexes],
1208+
"get_metagraph",
1209+
params=[netuid],
12401210
block_hash=block_hash,
12411211
)
12421212
if query.value is None:

0 commit comments

Comments
 (0)