Skip to content

Commit

Permalink
Merge pull request #19 from cybercongress/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
cyborgshead authored Feb 15, 2024
2 parents 6ad50ac + 80c0460 commit 017a7b0
Show file tree
Hide file tree
Showing 59 changed files with 3,646 additions and 1,121 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright © 2023 cyber~Congress
Copyright © 2024 cyber~Congress

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the “Software”), to deal in the Software without restriction, including without limitation
Expand Down
2 changes: 1 addition & 1 deletion bin/ctcli
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if __name__ == '__main__':
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 cyber~Congress
# Copyright © 2024 cyber~Congress

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
Expand Down
58 changes: 28 additions & 30 deletions cybertensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright © 2021 Yuma Rao
# Copyright © 2022-2023 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
# Copyright © 2023 cyber~Congress
# Copyright © 2024 cyber~Congress

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
Expand All @@ -18,7 +18,6 @@
# 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 pathlib import Path
from typing import Optional, Union

# Install and apply nest asyncio to allow the async functions
Expand All @@ -31,14 +30,13 @@
nest_asyncio.apply()

# Cybertensor code and protocol version.
__version__ = "0.1.4"
__version__ = "0.1.5"
version_split = __version__.split(".")
__version_as_int__ = (
(100 * int(version_split[0]))
+ (10 * int(version_split[1]))
+ (1 * int(version_split[2]))
)
__new_signature_version__ = 360

# Rich console.
__console__ = Console()
Expand All @@ -64,7 +62,7 @@ def turn_console_on():
__console__ = Console()


turn_console_off()
turn_console_on()


# Logging helpers.
Expand Down Expand Up @@ -170,37 +168,37 @@ def __init__(
contract_address="pussy1ddwq8rxgdsm27pvpxqdy2ep9enuen6t2yhrqujvj9qwl4dtukx0s8hpka9",
)

__contract_path__ = Path(__file__).home() / ".cybertensor/contract/cybernet.wasm"
__contract_schema_path__ = Path(__file__).home() / ".cybertensor/contract/schema"
__contract_path__ = None
__contract_schema_path__ = "contract/schema"

__default_gas__ = 1_000_000
__default_gas__ = None
__default_transfer_gas__ = 100_000

from .errors import *
from .config import *
from .keyfile import *
from .keypair import *
from .wallet import *
from .utils import *
from .utils.balance import Balance as Balance
from .chain_data import *
from .cwtensor import cwtensor as cwtensor
from .cli import cli as cli, COMMANDS as ALL_COMMANDS
from .ctlogging import logging as logging
from .metagraph import metagraph as metagraph
from .threadpool import PriorityThreadPoolExecutor as PriorityThreadPoolExecutor

from .synapse import *
from .stream import *
from .tensor import *
from .axon import axon as axon
from .dendrite import dendrite as dendrite
from cybertensor.errors import *
from cybertensor.keyfile import keyfile
from cybertensor.keypair import Keypair
from cybertensor.wallet import Wallet
from cybertensor.utils import *
from cybertensor.utils.balance import Balance
from cybertensor.chain_data import AxonInfo, NeuronInfo, NeuronInfoLite, PrometheusInfo, StakeInfo, SubnetInfo, SubnetHyperparameters
from cybertensor.cwtensor import cwtensor
from cybertensor.cli import cli, COMMANDS as ALL_COMMANDS
from cybertensor.ctlogging import logging
from cybertensor.metagraph import metagraph
from cybertensor.threadpool import PriorityThreadPoolExecutor

from cybertensor.synapse import TerminalInfo, Synapse
from cybertensor.stream import StreamingSynapse
from cybertensor.tensor import tensor, Tensor
from cybertensor.axon import axon
from cybertensor.dendrite import dendrite
from cybertensor.config import Config

configs = [
axon.config(),
cybertensor.config(),
Config(),
PriorityThreadPoolExecutor.config(),
wallet.config(),
Wallet.config(),
logging.config(),
]
defaults = config.merge_all(configs)
defaults = Config.merge_all(configs)
24 changes: 13 additions & 11 deletions cybertensor/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
# Copyright © 2023 cyber~Congress
# Copyright © 2024 cyber~Congress

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
Expand Down Expand Up @@ -41,6 +41,8 @@

import cybertensor
from cybertensor.keypair import Keypair
from cybertensor.wallet import Wallet
from cybertensor.config import Config

""" Create and init Axon, which services Forward and Backward requests from other neurons.
"""
Expand Down Expand Up @@ -167,8 +169,8 @@ def info(self) -> "cybertensor.AxonInfo":

def __init__(
self,
wallet: "cybertensor.wallet" = None,
config: Optional["cybertensor.config"] = None,
wallet: "Wallet" = None,
config: Optional["Config"] = None,
port: Optional[int] = None,
ip: Optional[str] = None,
external_ip: Optional[str] = None,
Expand All @@ -177,9 +179,9 @@ def __init__(
) -> "cybertensor.axon":
r"""Creates a new cybertensor.Axon object from passed arguments.
Args:
config (:obj:`Optional[cybertensor.config]`, `optional`):
config (:obj:`Optional[Config]`, `optional`):
cybertensor.axon.config()
wallet (:obj:`Optional[cybertensor.wallet]`, `optional`):
wallet (:obj:`Optional[Wallet]`, `optional`):
cybertensor wallet with hotkey and coldkeypub.
port (:type:`Optional[int]`, `optional`):
Binding port.
Expand Down Expand Up @@ -213,7 +215,7 @@ def __init__(
self.config = config

# Get wallet or use default.
self.wallet = wallet or cybertensor.wallet()
self.wallet = wallet or Wallet()

# Build axon objects.
self.uuid = str(uuid.uuid1())
Expand Down Expand Up @@ -409,16 +411,16 @@ def attach(
return self

@classmethod
def config(cls) -> "cybertensor.config":
def config(cls) -> "Config":
"""
Parses command-line arguments to form a cybertensor configuration object.
Returns:
cybertensor.config: Configuration object with settings from command-line arguments.
Config: Configuration object with settings from command-line arguments.
"""
parser = argparse.ArgumentParser()
axon.add_args(parser) # Add specific axon-related arguments
return cybertensor.config(parser, args=[])
return Config(parser, args=[])

@classmethod
def help(cls):
Expand Down Expand Up @@ -543,12 +545,12 @@ async def some_endpoint(body_dict: dict = Depends(verify_body_integrity)):
return body_dict

@classmethod
def check_config(cls, config: "cybertensor.config"):
def check_config(cls, config: "Config"):
"""
This method checks the configuration for the axon's port and wallet.
Args:
config (cybertensor.config): The config object holding axon settings.
config (Config): The config object holding axon settings.
Raises:
AssertionError: If the axon or external ports are not in range [1024, 65535]
Expand Down
6 changes: 3 additions & 3 deletions cybertensor/chain_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Foundation
# Copyright © 2023 cyber~Congress
# Copyright © 2024 cyber~Congress

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
Expand All @@ -22,8 +22,8 @@

import cybertensor
# from cybertensor import SubnetHyperparameters
from .utils import networking as net, U16_MAX, U16_NORMALIZED_FLOAT, GIGA
from .utils.balance import Balance
from cybertensor.utils import networking as net, U16_MAX, U16_NORMALIZED_FLOAT, GIGA
from cybertensor.utils.balance import Balance


# Dataclasses for chain data.
Expand Down
25 changes: 12 additions & 13 deletions cybertensor/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 cyber~Congress
# Copyright © 2024 cyber~Congress

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
Expand All @@ -21,11 +21,10 @@
from typing import List, Optional

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

# Create a console instance for CLI display.
console = cybertensor.__console__
from cybertensor.commands import *
from cybertensor.commands.network import SubnetSetWeightsCommand, SubnetGetWeightsCommand
from cybertensor.config import Config
from cybertensor import __console__ as console

ALIAS_TO_COMMAND = {
"subnets": "subnets",
Expand Down Expand Up @@ -139,14 +138,14 @@ class cli:

def __init__(
self,
config: Optional["cybertensor.config"] = None,
config: Optional["Config"] = None,
args: Optional[List[str]] = None,
):
"""
Initializes a cybertensor.CLI object.
Args:
config (cybertensor.config, optional): The configuration settings for the CLI.
config (Config, optional): The configuration settings for the CLI.
args (List[str], optional): List of command line arguments.
"""
# Turns on console for cli.
Expand Down Expand Up @@ -214,15 +213,15 @@ def __create_parser__() -> "argparse.ArgumentParser":
return parser

@staticmethod
def create_config(args: List[str]) -> "cybertensor.config":
def create_config(args: List[str]) -> "Config":
"""
From the argument parser, add config to cybertensor.executor and local config
Args:
args (List[str]): List of command line arguments.
Returns:
cybertensor.config: The configuration object for Cybertensor CLI.
Config: The configuration object for Cybertensor CLI.
"""
parser = cli.__create_parser__()

Expand All @@ -231,15 +230,15 @@ def create_config(args: List[str]) -> "cybertensor.config":
parser.print_help()
sys.exit()

return cybertensor.config(parser, args=args)
return Config(parser, args=args)

@staticmethod
def check_config(config: "cybertensor.config"):
def check_config(config: "Config"):
"""
Checks if the essential configuration exists under different command
Args:
config (cybertensor.config): The configuration settings for the CLI.
config (Config): The configuration settings for the CLI.
"""
# Check if command exists, if so, run the corresponding check_config.
# If command doesn't exist, inform user and exit the program.
Expand Down
28 changes: 14 additions & 14 deletions cybertensor/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Technologies Inc
# Copyright © 2023 cyber~Congress
# Copyright © 2024 cyber~Congress

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
Expand Down Expand Up @@ -63,22 +63,22 @@
}
)

from .overview import OverviewCommand
from .stake import StakeCommand, StakeShow
from .unstake import UnStakeCommand
from .register import (
from cybertensor.commands.overview import OverviewCommand
from cybertensor.commands.stake import StakeCommand, StakeShow
from cybertensor.commands.unstake import UnStakeCommand
from cybertensor.commands.register import (
PowRegisterCommand,
RegisterCommand,
# RunFaucetCommand
)
from .delegates import (
from cybertensor.commands.delegates import (
NominateCommand,
ListDelegatesCommand,
DelegateStakeCommand,
DelegateUnstakeCommand,
MyDelegatesCommand,
)
from .wallets import (
from cybertensor.commands.wallets import (
NewColdkeyCommand,
NewHotkeyCommand,
RegenColdkeyCommand,
Expand All @@ -88,20 +88,20 @@
WalletCreateCommand,
WalletBalanceCommand,
)
from .transfer import TransferCommand
from .inspect import InspectCommand
from .metagraph import MetagraphCommand
from .list import ListCommand
# from .misc import UpdateCommand
from .network import (
from cybertensor.commands.transfer import TransferCommand
from cybertensor.commands.inspect import InspectCommand
from cybertensor.commands.metagraph import MetagraphCommand
from cybertensor.commands.list import ListCommand
# from cybertensor.commands.misc import UpdateCommand
from cybertensor.commands.network import (
RegisterSubnetworkCommand,
SubnetLockCostCommand,
SubnetListCommand,
SubnetSudoCommand,
SubnetHyperparamsCommand,
SubnetGetHyperparamsCommand,
)
from .root import (
from cybertensor.commands.root import (
RootRegisterCommand,
RootList,
RootSetWeightsCommand,
Expand Down
Loading

0 comments on commit 017a7b0

Please sign in to comment.