Package: nimble-api
Nimble APIAPIs for composable AI ProtocolInstallThere are three ways to install nimbleThrough the installer:$/bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/nimble-technology/nimble/master/scripts/install.sh)"With pip:$pip3installnimbleFrom source:$gitclonehttps://github.com/nimble-technology/nimble.git
$cdnimble
$python3-mpipinstall-e./Using Conda (recommended forApple M1):$condaenvcreate-f~/.nimble/nimble/scripts/environments/apple_m1_environment.yml
$condaactivatenimbleTo test your installation, type:$nbcli--helpor using pythonimportnimbleCUDAIf you anticipate using PoW registration for subnets or the faucet (only available on staging), please installcubitas well for your version of python. You can find the Nimble Labs LTD cubit implementation and instructionshere.For example with python 3.10:pipinstallhttps://github.com/nimble-technology/cubit/releases/download/v1.1.2/cubit-1.1.2-cp310-cp310-linux_x86_64.whlWalletsWallets are the core ownership and identity technology around which all functions on nimble are carried out. nimble wallets consists of a coldkey and hotkey where the coldkey may contain many hotkeys, while each hotkey can only belong to a single coldkey. Coldkeys store funds securely, and operate functions such as transfers and staking, while hotkeys are used for all online operations such as signing queries, running miners and validating.Wallets can be created in two ways.Using the python-apiimportnimblewallet=nimble.wallet()wallet.create_new_coldkey()wallet.create_new_hotkey()print(wallet)"Wallet (default, default, ~/.nimble/wallets/)"Or using nbcliUse the subcommandwalletor it's aliasw:$nbcliwalletnew_coldkeyEnterwalletname(default):IMPORTANT:Storethismnemonicinasecure(preferablyofflineplace),asanyonewhohaspossessionofthismnemoniccanuseittoregeneratethekeyandaccessyourtokens.Themnemonictothenewcoldkeyis:*************************************************Youcanusethemnemonictorecreatethekeyincaseitgetslost.Thecommandtousetoregeneratethekeyusingthismnemonicis:nbcliwregen_coldkey--mnemonicpostmaiderodeshycaptainverifyscanshoulderbriskmountainpelicanelbow

$nbcliwalletnew_hotkeyEnterwalletname(default):d1Enterhotkeyname(default):IMPORTANT:Storethismnemonicinasecure(preferablyofflineplace),asanyonewhohaspossessionofthismnemoniccanuseittoregeneratethekeyandaccessyourtokens.Themnemonictothenewhotkeyis:*************************************************Youcanusethemnemonictorecreatethekeyincaseitgetslost.Thecommandtousetoregeneratethekeyusingthismnemonicis:nbcliwregen_hotkey--mnemonictotalsteakhourbirdhedgehogtrimtimbercanfrienddryworrytextIn both cases you should be able to view your keys by navigating to ~/.nimble/wallets or viewed by runningnbcli wallet list$tree~/.nimble/.nimble/# nimble, root directory.wallets/# The folder containing all nimble wallets.default/# The name of your wallet, "default"coldkey# You encrypted coldkey.coldkeypub.txt# Your coldkey public addresshotkeys/# The folder containing all of your hotkeys.default# You unencrypted hotkey information.Your default walletWallet (default, default, ~/.nimble/wallets/)is always used unless you specify otherwise. Be sure to store your mnemonics safely. If you lose your password to your wallet, or the access to the machine where the wallet is stored, you can always regenerate the coldkey using the mnemonic you saved from above.$nbcliwalletregen_coldkey--mnemonic*************************************************Using the cliThe nimble command line interface (nbcli) is the primary command line tool for interacting with the nimble network. It can be used to deploy nodes, manage wallets, stake/unstake, nominate, transfer tokens, and more.Basic UsageTo get the list of all the available commands and their descriptions, you can use:nbcli--help

usage:nbcli<command><commandargs>

nimblecliv{nimble.__version__}commands:subnets(s,subnet)-Commandsformanagingandviewingsubnetworks.root(r,roots)-Commandsformanagingandviewingtherootnetwork.wallet(w,wallets)-Commandsformanagingandviewingwallets.stake(st,stakes)-Commandsforstakingandremovingstakefromhotkeyaccounts.sudo(su,sudos)-Commandsforsubnetmanagement.legacy(l)-Miscellaneouscommands.Example CommandsViewing Senate ProposalsnbclirootproposalsViewing Senate Membersnbclirootlist_delegatesViewing Proposal Votesnbclirootsenate_vote--proposal=[PROPOSAL_HASH]Registering for SenatenbclirootregisterLeaving SenatenbclirootundelegateVoting in Senatenbclirootsenate_vote--proposal=[PROPOSAL_HASH]Miscellaneous Commandsnbclilegacyupdate
nbclilegacyfaucetManaging Subnetsnbclisubnetslist
nbclisubnetscreateManaging Walletsnbcliwalletlist
nbcliwallettransferNotePlease replace the subcommands and arguments as necessary to suit your needs, and always refer tonbcli --helpornbcli <command> --helpfor the most up-to-date and accurate information.For example:nbclisubnets--help

usage:nbcli<command><commandargs>subnets[-h]{list,metagraph,lock_cost,create,register,pow_register,hyperparameters}...

positionalarguments:{list,metagraph,lock_cost,create,register,pow_register,hyperparameters}Commandsformanagingandviewingsubnetworks.listListallsubnetsonthenetwork.metagraphViewasubnetmetagraphinformation.lock_costReturnthelockcosttoregisterasubnet.createCreateanewnimblesubnetworkonthischain.registerRegisterawallettoanetwork.pow_registerRegisterawallettoanetworkusingPoW.hyperparametersViewsubnethyperparameters.

options:-h,--helpshowthishelpmessageandexitPost-Installation StepsTo enable autocompletion for nimble CLI, run the following commands:nbcli--print-completionbash>>~/.bashrc# For Bashnbcli--print-completionzsh>>~/.zshrc# For Zshsource~/.bashrc# Reload Bash configuration to take effectThe nimble PackageThe nimble package contains data structures for interacting with the nimble ecosystem, writing miners, validators and querying the network. Additionally, it provides many utilities for efficient serialization of Tensors over the wire, performing data analysis of the network, and other useful utilities.Wallet: Interface over locally stored nimble hot + coldkey styled wallets.importnimble# nimble's wallet maintenance class.wallet=nimble.wallet()# Access the hotkeywallet.hotkey# Access the coldkeywallet.coldkey(requiresdecryption)# Sign data with the keypair.wallet.coldkey.sign(data)NbNetwork: Interfaces with nimble's blockchain and can perform operations like extracting state information or sending transactions.importnimble# nimble's chain interface.nbnetwork=nimble.nbnetwork()# Get the chain blocknbnetwork.get_current_block()# Transfer Nim to a destination address.nbnetwork.transfer(wallet=wallet,dest="xxxxxxx..xxxxx",amount=10.0)# Register a wallet onto a subnetworknbnetwork.register(wallet=wallet,netuid=1)Metagraph: Encapsulates the chain state of a particular subnetwork at a specific block.importnimble# nimble's chain state object.metagraph=nimble.metagraph(netuid=1)# Resync the graph with the most recent chain statemetagraph.sync()# Get the list of stake valuesprint(metagraph.S)# Get endpoint information for the entire subnetworkprint(metagraph.axons)# Get the hotkey information for the miner in the 10th slotprint(metagraph.hotkeys[10])# Sync the metagraph at another blockmetagraph.sync(block=100000)# Save the metagraphmetagraph.save()# Load the samemetagraph.load()Synapse: Responsible for defining the protocol definition between axon servers and dendrite clientsclassTopk(nimble.Synapse):topk:int=2# Number of "top" elements to selectinput:nimble.Tensor=pydantic.Field(...,allow_mutation=False)# Ensure that input cannot be set on the server side.v:nimble.Tensor=Nonei:nimble.Tensor=Nonedeftopk(synapse:Topk)->Topk:v,i=torch.topk(synapse.input.deserialize(),k=synapse.topk)synapse.v=nimble.Tensor.serialize(v)synapse.i=nimble.Tensor.serialize(i)returnsynapse# Attach the forward function to the axon and start.axon=nimble.axon().attach(topk).start()Axon: Serves Synapse protocols with custom blacklist, priority and verify functions.importnimbleclassMySynapse(nimble.Synapse):input:int=1output:int=None# Define a custom request forwarding functiondefforward(synapse:MySynapse)->MySynapse:# Apply custom logic to synapse and return itsynapse.output=2returnsynapse# Define a custom request verification functiondefverify_my_synapse(synapse:MySynapse):# Apply custom verification logic to synapse# Optionally raise Exception# Define a custom request blacklist functiondefblacklist_my_synapse(synapse:MySynapse)->bool:# Apply custom blacklist# return False ( if non blacklisted ) or True ( if blacklisted )# Define a custom request priority functiondefprioritize_my_synape(synapse:MySynapse)->float:# Apply custom priorityreturn1.0# Initialize Axon object with a custom configurationmy_axon=nimble.axon(config=my_config,wallet=my_wallet,port=9090,ip="192.0.2.0",external_ip="203.0.113.0",external_port=7070)# Attach the endpoint with the specified verification and forwarding functionsmy_axon.attach(forward_fn=forward_my_synapse,verify_fn=verify_my_synapse,blacklist_fn=blacklist_my_synapse,priority_fn=prioritize_my_synape).start()Dendrite: Inheriting from PyTorch's Module class, represents the abstracted implementation of a network client module designed
to send requests to those endpoints to receive inputs.Example:dendrite_obj=dendrite(wallet=nimble.wallet())# pings the axon endpointawaitd(<axon>)# ping multiple axon endpointsawaitd([<axons>])# Send custom synapse request to axon.awaitd(nimble.axon(),nimble.Synapse())# Query all metagraph objects.awaitd(meta.axons,nimble.Synapse())Setting weights on root networkUse therootsubcommand to access setting weights on the network across subnets.nbclirootweights--wallet.name<coldname>--wallet.hotkey<hotname>
Enternetuids(e.g.0,1,2...):# Here enter your selected netuids to set weights on1,2>Enterweights(e.g.0.09,0.09,0.09...):# These do not need to sum to 1, we do normalization on the backend.# Values must be > 00.5,10Normalizedweights:tensor([0.5000,10.0000])->tensor([0.0476,0.9524])Doyouwanttosetthefollowingrootweights?:weights:tensor([0.0476,0.9524])uids:tensor([1,2])?[y/n]:
y

⠏📡Settingrootweightsontest...ReleaseRun the following command to create dist folderpythonsetup.pysdistThen use the following command to publish to pypitwineuploaddist/nimble-api-{version}.tar.gzMake sure you store your credentials at~/.pypircContributionsPlease review thecontributing guidefor more information before making a pull request.