Skip to content

Commit

Permalink
Adds btcli + other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheem-opentensor committed Jan 8, 2025
1 parent e46ed1b commit 3051eb9
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bittensor/core/chain_data/subnet_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SubnetState:
def from_vec_u8(cls, vec_u8: list[int]) -> Optional["SubnetState"]:
if len(vec_u8) == 0:
return None
decoded = from_scale_encoding(vec_u8, ChainDataType.SubnetState, is_option=True)
decoded = from_scale_encoding(vec_u8, ChainDataType.SubnetState)
if decoded is None:
return None
return SubnetState.fix_decoded_values(decoded)
Expand Down
7 changes: 2 additions & 5 deletions bittensor/core/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,8 @@ def _get_all_stakes_from_chain(self, subtensor: "Subtensor"):
self.tao_stake = subnet_state.tao_stake
self.stake = subnet_state.total_stake

except (SubstrateRequestException, AttributeError):
logging.debug(
"Fields `alpha_stake`, `tao_stake`, `total_stake` can be obtained only from the RAO network."
)

except (SubstrateRequestException, AttributeError) as e:
logging.debug(e)
def _process_root_weights(
self, data: list, attribute: str, subtensor: "Subtensor"
) -> Union[NDArray, "torch.nn.Parameter"]:
Expand Down
137 changes: 137 additions & 0 deletions bittensor/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,140 @@ def __apply_nest_asyncio():


__apply_nest_asyncio()


units = [
"\u03c4", # τ (tau, 0)
"\u03b1", # α (alpha, 1)
"\u03b2", # β (beta, 2)
"\u03b3", # γ (gamma, 3)
"\u03b4", # δ (delta, 4)
"\u03b5", # ε (epsilon, 5)
"\u03b6", # ζ (zeta, 6)
"\u03b7", # η (eta, 7)
"\u03b8", # θ (theta, 8)
"\u03b9", # ι (iota, 9)
"\u03ba", # κ (kappa, 10)
"\u03bb", # λ (lambda, 11)
"\u03bc", # μ (mu, 12)
"\u03bd", # ν (nu, 13)
"\u03be", # ξ (xi, 14)
"\u03bf", # ο (omicron, 15)
"\u03c0", # π (pi, 16)
"\u03c1", # ρ (rho, 17)
"\u03c3", # σ (sigma, 18)
"t", # t (tau, 19)
"\u03c5", # υ (upsilon, 20)
"\u03c6", # φ (phi, 21)
"\u03c7", # χ (chi, 22)
"\u03c8", # ψ (psi, 23)
"\u03c9", # ω (omega, 24)
# Hebrew letters
"\u05d0", # א (aleph, 25)
"\u05d1", # ב (bet, 26)
"\u05d2", # ג (gimel, 27)
"\u05d3", # ד (dalet, 28)
"\u05d4", # ה (he, 29)
"\u05d5", # ו (vav, 30)
"\u05d6", # ז (zayin, 31)
"\u05d7", # ח (het, 32)
"\u05d8", # ט (tet, 33)
"\u05d9", # י (yod, 34)
"\u05da", # ך (final kaf, 35)
"\u05db", # כ (kaf, 36)
"\u05dc", # ל (lamed, 37)
"\u05dd", # ם (final mem, 38)
"\u05de", # מ (mem, 39)
"\u05df", # ן (final nun, 40)
"\u05e0", # נ (nun, 41)
"\u05e1", # ס (samekh, 42)
"\u05e2", # ע (ayin, 43)
"\u05e3", # ף (final pe, 44)
"\u05e4", # פ (pe, 45)
"\u05e5", # ץ (final tsadi, 46)
"\u05e6", # צ (tsadi, 47)
"\u05e7", # ק (qof, 48)
"\u05e8", # ר (resh, 49)
"\u05e9", # ש (shin, 50)
"\u05ea", # ת (tav, 51)
# Georgian Alphabet (Mkhedruli)
"\u10d0", # ა (Ani, 97)
"\u10d1", # ბ (Bani, 98)
"\u10d2", # გ (Gani, 99)
"\u10d3", # დ (Doni, 100)
"\u10d4", # ე (Eni, 101)
"\u10d5", # ვ (Vini, 102)
# Armenian Alphabet
"\u0531", # Ա (Ayp, 103)
"\u0532", # Բ (Ben, 104)
"\u0533", # Գ (Gim, 105)
"\u0534", # Դ (Da, 106)
"\u0535", # Ե (Ech, 107)
"\u0536", # Զ (Za, 108)
# "\u055e", # ՞ (Question mark, 109)
# Runic Alphabet
"\u16a0", # ᚠ (Fehu, wealth, 81)
"\u16a2", # ᚢ (Uruz, strength, 82)
"\u16a6", # ᚦ (Thurisaz, giant, 83)
"\u16a8", # ᚨ (Ansuz, god, 84)
"\u16b1", # ᚱ (Raidho, ride, 85)
"\u16b3", # ᚲ (Kaunan, ulcer, 86)
"\u16c7", # ᛇ (Eihwaz, yew, 87)
"\u16c9", # ᛉ (Algiz, protection, 88)
"\u16d2", # ᛒ (Berkanan, birch, 89)
# Cyrillic Alphabet
"\u0400", # Ѐ (Ie with grave, 110)
"\u0401", # Ё (Io, 111)
"\u0402", # Ђ (Dje, 112)
"\u0403", # Ѓ (Gje, 113)
"\u0404", # Є (Ukrainian Ie, 114)
"\u0405", # Ѕ (Dze, 115)
# Coptic Alphabet
"\u2c80", # Ⲁ (Alfa, 116)
"\u2c81", # ⲁ (Small Alfa, 117)
"\u2c82", # Ⲃ (Vida, 118)
"\u2c83", # ⲃ (Small Vida, 119)
"\u2c84", # Ⲅ (Gamma, 120)
"\u2c85", # ⲅ (Small Gamma, 121)
# Arabic letters
"\u0627", # ا (alef, 52)
"\u0628", # ب (ba, 53)
"\u062a", # ت (ta, 54)
"\u062b", # ث (tha, 55)
"\u062c", # ج (jeem, 56)
"\u062d", # ح (ha, 57)
"\u062e", # خ (kha, 58)
"\u062f", # د (dal, 59)
"\u0630", # ذ (dhal, 60)
"\u0631", # ر (ra, 61)
"\u0632", # ز (zay, 62)
"\u0633", # س (seen, 63)
"\u0634", # ش (sheen, 64)
"\u0635", # ص (sad, 65)
"\u0636", # ض (dad, 66)
"\u0637", # ط (ta, 67)
"\u0638", # ظ (dha, 68)
"\u0639", # ع (ain, 69)
"\u063a", # غ (ghain, 70)
"\u0641", # ف (fa, 71)
"\u0642", # ق (qaf, 72)
"\u0643", # ك (kaf, 73)
"\u0644", # ل (lam, 74)
"\u0645", # م (meem, 75)
"\u0646", # ن (noon, 76)
"\u0647", # ه (ha, 77)
"\u0648", # و (waw, 78)
"\u0649", # ى (alef maksura, 79)
"\u064a", # ي (ya, 80)
# Ogham Alphabet
"\u1680", #   (Space, 90)
"\u1681", # ᚁ (Beith, birch, 91)
"\u1682", # ᚂ (Luis, rowan, 92)
"\u1683", # ᚃ (Fearn, alder, 93)
"\u1684", # ᚄ (Sail, willow, 94)
"\u1685", # ᚅ (Nion, ash, 95)
"\u169b", # ᚛ (Forfeda, 96)
# Tifinagh Alphabet
"\u2d30", # ⴰ (Ya, 127)
"\u2d31", # ⴱ (Yab, 128)
]
19 changes: 19 additions & 0 deletions bittensor/utils/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,22 @@ def from_rao(amount: int):
A Balance object representing the given amount.
"""
return Balance(amount)

@staticmethod
def get_unit(netuid: int):
units = settings.units
base = len(units)
if netuid < base:
return units[netuid]
else:
result = ""
while netuid > 0:
result = units[netuid % base] + result
netuid //= base
return result

def set_unit(self, netuid: int):
self.unit = Balance.get_unit(netuid)
self.rao_unit = Balance.get_unit(netuid)
return self

9 changes: 9 additions & 0 deletions bittensor/utils/mock/subtensor_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,15 @@ def query_map_subtensor(
else:
return MockMapResult([])

def query_runtime_api(
self,
runtime_api: str,
method: str,
params: Optional[Union[list[int], dict[str, int]]],
block: Optional[int] = None,
) -> Optional[str]:
return None

def query_constant(
self, module_name: str, constant_name: str, block: Optional[int] = None
) -> Optional[object]:
Expand Down
2 changes: 1 addition & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ wheel
setuptools~=70.0.0
aiohttp~=3.9
async-property==0.2.2
bittensor-cli
bittensor-cli==8.2.0rc5
bt-decode==0.4.0
colorama~=0.4.6
fastapi~=0.110.1
Expand Down
5 changes: 4 additions & 1 deletion tests/unit_tests/test_metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from unittest.mock import Mock

import numpy as np
Expand Down Expand Up @@ -47,6 +47,8 @@ def mock_environment():
validator_trust=i + 0.6,
total_stake=Mock(tao=i + 0.7),
stake=i + 0.8,
alpha_stake=i + 0.9,
tao_stake=i + 1.0,
axon_info=f"axon_info_{i}",
weights=[(j, j + 0.1) for j in range(5)],
bonds=[(j, j + 0.2) for j in range(5)],
Expand Down Expand Up @@ -143,6 +145,7 @@ def metagraph_instance():
metagraph._assign_neurons = MagicMock()
metagraph._set_metagraph_attributes = MagicMock()
metagraph._set_weights_and_bonds = MagicMock()
metagraph._get_all_stakes_from_chain = MagicMock()
return metagraph


Expand Down

0 comments on commit 3051eb9

Please sign in to comment.