Skip to content

Commit

Permalink
Merge pull request #15 from cybercongress/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
cyborgshead authored Jan 5, 2024
2 parents a6530f5 + 7783a6c commit d3c3a79
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cyber keys add validator --recover --home ./home
```
3. Deploy code and instantiate contract:
```bash
cyber tx wasm store cybernet.wasm --from validator --home ./home --chain-id localbostrom --gas 7000000 --broadcast-mode block -y --keyring-backend test
cyber tx wasm store cybernet.wasm --from validator --home ./home --chain-id localbostrom --gas 8000000 --broadcast-mode block -y --keyring-backend test
cyber tx wasm instantiate 1 "{}" --from validator --home ./home --chain-id localbostrom --gas 5000000 --label cybernet1 --admin bostrom1phaxpevm5wecex2jyaqty2a4v02qj7qm5n94ug --broadcast-mode block -y --keyring-backend test
```
4. Send tokens to contract and activate (with dmn):
Expand Down
8 changes: 0 additions & 8 deletions cybertensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,11 @@ class SubnetInfo:
max_allowed_validators: int
min_allowed_weights: int
max_weight_limit: float
scaling_law_power: float
subnetwork_n: int
max_n: int
blocks_since_epoch: int
tempo: int
modality: int
# netuid -> topk percentile prunning score requirement (u16:MAX normalized.)
connection_requirements: Dict[str, float]
emission_value: float
burn: Balance
owner: str
Expand Down Expand Up @@ -608,16 +605,11 @@ def fix_decoded_values(cls, decoded: Dict) -> "SubnetInfo":
max_allowed_validators=decoded["max_allowed_validators"],
min_allowed_weights=decoded["min_allowed_weights"],
max_weight_limit=decoded["max_weights_limit"],
scaling_law_power=decoded["scaling_law_power"],
subnetwork_n=decoded["subnetwork_n"],
max_n=decoded["max_allowed_uids"],
blocks_since_epoch=decoded["blocks_since_last_step"],
tempo=decoded["tempo"],
modality=decoded["network_modality"],
connection_requirements={
str(int(netuid)): U16_NORMALIZED_FLOAT(int(req))
for netuid, req in decoded["network_connect"]
},
emission_value=decoded["emission_values"],
burn=Balance.from_boot(decoded["burn"]),
owner=decoded["owner"],
Expand Down
2 changes: 2 additions & 0 deletions cybertensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import cybertensor
from .commands import *
from .commands.network import SubnetSetWeightsCommand

# Create a console instance for CLI display.
console = cybertensor.__console__
Expand Down Expand Up @@ -58,6 +59,7 @@
"pow_register": PowRegisterCommand,
"register": RegisterCommand,
"hyperparameters": SubnetHyperparamsCommand,
"weights": SubnetSetWeightsCommand,
},
},
"root": {
Expand Down
2 changes: 1 addition & 1 deletion cybertensor/commands/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def run(cli):
if not wallet.coldkeypub_file.exists_on_device():
continue
delegates = cwtensor.get_delegated(
coldkey=wallet.coldkeypub.address
delegatee=wallet.coldkeypub.address
)

my_delegates = {} # hotkey, amount
Expand Down
65 changes: 65 additions & 0 deletions cybertensor/commands/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# DEALINGS IN THE SOFTWARE.

import argparse
import re
from typing import List, Optional, Dict

from rich.prompt import Prompt
Expand All @@ -25,6 +26,7 @@
import cybertensor
from . import defaults
from .utils import DelegatesDetails, check_netuid_set
import torch

console = cybertensor.__console__

Expand Down Expand Up @@ -491,3 +493,66 @@ def add_args(parser: argparse.ArgumentParser):
"--netuid", dest="netuid", type=int, required=False, default=False
)
cybertensor.cwtensor.add_args(parser)

class SubnetSetWeightsCommand:
"""
Optional arguments:
- --uids (str): A comma-separated list of uids for which weights are to be set.
- --weights (str): Corresponding weights for the specified netuids, in comma-separated format.
- --netuid (str): Corresponding subnet for which weights are to be set.
Example usage:
>>> ctcli subnet weights --uids 1,2,3 --weights 0.3,0.3,0.4
"""

@staticmethod
def run(cli):
r"""Set weights for root network."""
wallet = cybertensor.wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=cli.config)

# Parse from string
uids = torch.tensor(
list(map(int, re.split(r"[ ,]+", cli.config.uids))), dtype=torch.long
)
weights = torch.tensor(
list(map(float, re.split(r"[ ,]+", cli.config.weights))),
dtype=torch.float32,
)

# Run the set weights operation.
cwtensor.set_weights(
wallet=wallet,
netuid=cli.config.netuid,
uids=uids,
weights=weights,
version_key=0,
prompt=not cli.config.no_prompt,
wait_for_finalization=True,
)

@staticmethod
def add_args(parser: argparse.ArgumentParser):
parser = parser.add_parser("weights", help="""Set weights for subnet.""")
parser.add_argument("--uids", dest="uids", type=str, required=False)
parser.add_argument("--weights", dest="weights", type=str, required=False)
parser.add_argument(
"--netuid", dest="netuid", type=int, required=False, default=False
)

cybertensor.wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)

@staticmethod
def check_config(config: "cybertensor.config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)

if not config.is_set("wallet.hotkey") and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default=defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

if not config.is_set("netuid") and not config.no_prompt:
check_netuid_set(config, cybertensor.cwtensor(config=config))
2 changes: 1 addition & 1 deletion cybertensor/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def get_stakes_from_delegates(
A dictionary of stakes related to delegates.
"""
delegates = cwtensor.get_delegated(
coldkey=wallet.coldkeypub.address
delegatee=wallet.coldkeypub.address
)
stakes = {}
for dele, staked in delegates:
Expand Down

0 comments on commit d3c3a79

Please sign in to comment.