Skip to content

Commit 8929358

Browse files
authored
Merge branch 'staging' into fix/zyzniewski/unittests_warnings
2 parents bcb95b3 + cda1e7c commit 8929358

File tree

13 files changed

+1030
-120
lines changed

13 files changed

+1030
-120
lines changed

.github/workflows/e2e-subtensor-tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
- name: Run tests with retry
108108
run: |
109109
set +e
110-
for i in 1 2; do
110+
for i in 1 2 3; do
111111
echo "🔁 Attempt $i: Running tests"
112112
uv run pytest ${{ matrix.test-file }} -s
113113
status=$?
@@ -116,8 +116,8 @@ jobs:
116116
break
117117
else
118118
echo "❌ Tests failed on attempt $i"
119-
if [ $i -eq 2 ]; then
120-
echo "Tests failed after 2 attempts"
119+
if [ $i -eq 3 ]; then
120+
echo "Tests failed after 3 attempts"
121121
exit 1
122122
fi
123123
echo "Retrying..."
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# This workflow measures the disk size of a virtual environment
2+
# after installing the Bittensor SDK across multiple Python versions.
3+
# It runs only when a new pull request targets the master branch,
4+
# and posts a comment with the results.
5+
name: Monitor SDK Requirements Size
6+
7+
on:
8+
pull_request:
9+
types: [opened]
10+
branches: [master]
11+
12+
permissions:
13+
pull-requests: write
14+
contents: read
15+
16+
jobs:
17+
measure-venv:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
22+
outputs:
23+
py39: ${{ steps.set-output.outputs.py39 }}
24+
py310: ${{ steps.set-output.outputs.py310 }}
25+
py311: ${{ steps.set-output.outputs.py311 }}
26+
py312: ${{ steps.set-output.outputs.py312 }}
27+
py313: ${{ steps.set-output.outputs.py313 }}
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: actions/setup-python@v5
32+
with:
33+
python-version: ${{ matrix.python-version }}
34+
35+
- name: Create virtualenv and install
36+
run: |
37+
python -m venv venv
38+
source venv/bin/activate
39+
pip install --upgrade pip
40+
pip install .
41+
42+
- name: Measure venv size
43+
id: set-output
44+
run: |
45+
SIZE=$(du -sm venv | cut -f1)
46+
VERSION=${{ matrix.python-version }}
47+
echo "Detected size: $SIZE MB for Python $VERSION"
48+
case "$VERSION" in
49+
3.9) echo "py39=$SIZE" >> $GITHUB_OUTPUT ;;
50+
3.10) echo "py310=$SIZE" >> $GITHUB_OUTPUT ;;
51+
3.11) echo "py311=$SIZE" >> $GITHUB_OUTPUT ;;
52+
3.12) echo "py312=$SIZE" >> $GITHUB_OUTPUT ;;
53+
3.13) echo "py313=$SIZE" >> $GITHUB_OUTPUT ;;
54+
esac
55+
56+
comment-on-pr:
57+
if: github.event_name == 'pull_request' && github.base_ref == 'master'
58+
needs: measure-venv
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Post venv size summary to PR
62+
uses: actions/github-script@v7
63+
with:
64+
github-token: ${{ secrets.GITHUB_TOKEN }}
65+
script: |
66+
const sizes = {
67+
"3.9": "${{ needs.measure-venv.outputs.py39 || 'N/A' }}",
68+
"3.10": "${{ needs.measure-venv.outputs.py310 || 'N/A' }}",
69+
"3.11": "${{ needs.measure-venv.outputs.py311 || 'N/A' }}",
70+
"3.12": "${{ needs.measure-venv.outputs.py312 || 'N/A' }}",
71+
"3.13": "${{ needs.measure-venv.outputs.py313 || 'N/A' }}",
72+
};
73+
74+
const body = [
75+
'**Bittensor SDK virtual environment sizes by Python version:**',
76+
'',
77+
'```'
78+
]
79+
.concat(Object.entries(sizes).map(([v, s]) => `Python ${v}: ${s} MB`))
80+
.concat(['```'])
81+
.join('\n');
82+
83+
github.rest.issues.createComment({
84+
issue_number: context.issue.number,
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
body
88+
});

bittensor/core/async_subtensor.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616

1717
from bittensor.core.chain_data import (
1818
DelegateInfo,
19-
StakeInfo,
19+
DynamicInfo,
2020
MetagraphInfo,
2121
NeuronInfoLite,
2222
NeuronInfo,
2323
ProposalVoteData,
24+
StakeInfo,
25+
SelectiveMetagraphIndex,
2426
SubnetHyperparameters,
2527
SubnetIdentity,
2628
SubnetInfo,
2729
WeightCommitInfo,
2830
decode_account_id,
29-
DynamicInfo,
3031
)
3132
from bittensor.core.chain_data.chain_identity import ChainIdentity
3233
from bittensor.core.chain_data.delegate_info import DelegatedInfo
@@ -1470,32 +1471,56 @@ async def get_minimum_required_stake(self):
14701471
async def get_metagraph_info(
14711472
self,
14721473
netuid: int,
1474+
field_indices: Optional[list["SelectiveMetagraphIndex"]] = None,
14731475
block: Optional[int] = None,
14741476
block_hash: Optional[str] = None,
14751477
reuse_block: bool = False,
14761478
) -> Optional[MetagraphInfo]:
14771479
"""
1478-
Retrieves the MetagraphInfo dataclass from the node for a single subnet (netuid)
1480+
Retrieves full or partial metagraph information for the specified subnet (netuid).
14791481
14801482
Arguments:
1481-
netuid: The NetUID of the subnet.
1483+
netuid (int): The NetUID of the subnet to query.
1484+
field_indices (Optional[list[SelectiveMetagraphIndex]]): An optional list of SelectiveMetagraphIndex values
1485+
specifying which fields to retrieve. If not provided, all available fields will be returned.
14821486
block: the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or
14831487
reuse_block
14841488
block_hash: The hash of blockchain block number for the query. Do not specify if using
14851489
block or reuse_block
14861490
reuse_block: Whether to reuse the last-used block hash. Do not set if using block_hash or block.
14871491
14881492
Returns:
1489-
MetagraphInfo dataclass
1493+
Optional[MetagraphInfo]: A MetagraphInfo object containing the requested subnet data, or None if the subnet
1494+
with the given netuid does not exist.
1495+
1496+
Example:
1497+
meta_info = await subtensor.get_metagraph_info(netuid=2)
1498+
1499+
partial_meta_info = await subtensor.get_metagraph_info(
1500+
netuid=2,
1501+
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
1502+
)
14901503
"""
1504+
indexes = SelectiveMetagraphIndex.all_indices()
1505+
1506+
if field_indices:
1507+
if isinstance(field_indices, list) and all(
1508+
isinstance(f, SelectiveMetagraphIndex) for f in field_indices
1509+
):
1510+
indexes = [f.value for f in field_indices]
1511+
else:
1512+
raise ValueError(
1513+
"`field_indices` must be a list of SelectiveMetagraphIndex items."
1514+
)
1515+
14911516
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
14921517
if not block_hash and reuse_block:
14931518
block_hash = self.substrate.last_block_hash
14941519

14951520
query = await self.substrate.runtime_call(
14961521
"SubnetInfoRuntimeApi",
1497-
"get_metagraph",
1498-
params=[netuid],
1522+
"get_selective_metagraph",
1523+
params=[netuid, indexes if 0 in indexes else [0] + indexes],
14991524
block_hash=block_hash,
15001525
)
15011526
if query.value is None:
@@ -4177,7 +4202,7 @@ async def unstake(
41774202
removed.
41784203
hotkey_ss58 (Optional[str]): The ``SS58`` address of the hotkey account to unstake from.
41794204
netuid (Optional[int]): The unique identifier of the subnet.
4180-
amount (Balance): The amount of TAO to unstake. If not specified, unstakes all.
4205+
amount (Balance): The amount of alpha to unstake. If not specified, unstakes all.
41814206
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
41824207
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
41834208
safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The unstake

bittensor/core/chain_data/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
MetagraphInfoEmissions,
1717
MetagraphInfoPool,
1818
MetagraphInfoParams,
19+
SelectiveMetagraphIndex,
1920
)
2021
from .neuron_info import NeuronInfo
2122
from .neuron_info_lite import NeuronInfoLite
@@ -50,6 +51,7 @@
5051
ProposalCallData,
5152
ProposalVoteData,
5253
ScheduledColdkeySwapInfo,
54+
SelectiveMetagraphIndex,
5355
StakeInfo,
5456
SubnetHyperparameters,
5557
SubnetIdentity,

0 commit comments

Comments
 (0)