Skip to content

Commit

Permalink
Merge pull request #43 from coinmetrics/bittensor-8.5.1
Browse files Browse the repository at this point in the history
Revert config fix to align better with bittensor standards
  • Loading branch information
peterc-yuma authored Jan 9, 2025
2 parents 3882d36 + 3dc24ef commit 55b4125
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 216 deletions.
3 changes: 1 addition & 2 deletions .env.miner.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ MINER_HOTKEY=default
# Node Configuration
MINER_NAME=miner
MINER_PORT=8092
AXON_IP=127.0.0.1
AXON_EXTERNAL_IP=127.0.0.1


# Miner Settings
TIMEOUT=16
Expand Down
3 changes: 1 addition & 2 deletions .env.validator.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ VALIDATOR_HOTKEY=default
# Node Configuration
VALIDATOR_NAME=validator
VALIDATOR_PORT=8091
AXON_IP=127.0.0.1
AXON_EXTERNAL_IP=127.0.0.1


# Logging
LOGGING_LEVEL=info # Options: info, debug, trace
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ENV_FILE ?= .env

include $(ENV_FILE)
export

Expand Down Expand Up @@ -27,28 +25,26 @@ register:
}

validator:
python start_validator.py \
pm2 start --name $(VALIDATOR_NAME) python3 -- precog/validators/validator.py \
--neuron.name $(VALIDATOR_NAME) \
--wallet.name $(COLDKEY) \
--wallet.hotkey $(VALIDATOR_HOTKEY) \
--subtensor.chain_endpoint $($(NETWORK)) \
--axon.port $(VALIDATOR_PORT) \
--axon.ip $(AXON_IP) \
--axon.external_ip $(AXON_EXTERNAL_IP) \
--netuid $(netuid) \
--logging.level $(LOGGING_LEVEL)
--logging.level $(LOGGING_LEVEL) \
--wandb.off

miner:
python start_miner.py \
pm2 start --name $(MINER_NAME) python3 -- precog/miners/miner.py \
--neuron.name $(MINER_NAME) \
--wallet.name $(COLDKEY) \
--wallet.hotkey $(MINER_HOTKEY) \
--subtensor.chain_endpoint $($(NETWORK)) \
--axon.port $(MINER_PORT) \
--axon.ip $(AXON_IP) \
--axon.external_ip $(AXON_EXTERNAL_IP) \
--netuid $(netuid) \
--logging.level $(LOGGING_LEVEL) \
--timeout $(TIMEOUT) \
--vpermit_tao_limit $(VPERMIT_TAO_LIMIT) \
--forward_function $(FORWARD_FUNCTION)
--forward_function $(FORWARD_FUNCTION) \
--wandb.off
10 changes: 4 additions & 6 deletions precog/miners/miner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import asyncio
import importlib
import time
Expand All @@ -10,8 +11,7 @@

from precog.protocol import Challenge
from precog.utils.bittensor import print_info, setup_bittensor_objects
from precog.utils.classes import Config
from precog.utils.general import parse_arguments
from precog.utils.config import config


class Miner:
Expand All @@ -20,8 +20,6 @@ class Miner:
"""

def __init__(self, config=None):
args = parse_arguments()
config = Config(args)
self.forward_module = importlib.import_module(f"precog.miners.{config.forward_function}")
self.config = config
self.config.neuron.type = "Miner"
Expand Down Expand Up @@ -216,7 +214,7 @@ def _to_seconds(self, nano: int) -> int:

# Run the miner
if __name__ == "__main__":
args = parse_arguments()
config = Config(args)
parser = argparse.ArgumentParser()
config = config(parser, neuron_type="miner")
miner = Miner(config=config)
miner.loop.run_forever()
8 changes: 7 additions & 1 deletion precog/utils/bittensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ def setup_bittensor_objects(self):
)[1]
else:
# if chain endpoint is set, overwrite network arg
self.config.subtensor.network = self.config.subtensor.chain_endpoint
if "test" in self.config.subtensor.chain_endpoint:
self.config.subtensor.network = "test"
elif "finney" in self.config.subtensor.chain_endpoint:
self.config.subtensor.network = "finney"
else:
self.config.subtensor.network = self.config.subtensor.chain_endpoint
# Initialize subtensor.
self.subtensor = bt.subtensor(config=self.config, network=self.config.subtensor.chain_endpoint)
self.metagraph = self.subtensor.metagraph(self.config.netuid)
Expand Down Expand Up @@ -68,6 +73,7 @@ def setup_bittensor_objects(self):
).expanduser()
full_path.mkdir(parents=True, exist_ok=True)
self.config.full_path = str(full_path)
bt.logging.info(f"Config: {self.config}")


def print_info(self) -> None:
Expand Down
49 changes: 0 additions & 49 deletions precog/utils/classes.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,9 @@
import argparse
from datetime import datetime, timedelta
from typing import List

from precog.utils.timestamp import get_now, get_timezone, round_minute_down, to_datetime


class Config:
def __init__(self, args):
# Add command-line arguments to the Config object
for key, value in vars(args).items():
setattr(self, key, value)

def get(self, key, default=None):
return getattr(self, key, default)

def to_str(self):
arguments = ""
for key, value in vars(self).items():
if isinstance(value, bool):
if value:
arguments = arguments + f" --{key}"
else:
try:
if isinstance(value, NestedNamespace):
for key_2, value_2 in vars(value).items():
if isinstance(value_2, bool):
if value_2:
arguments = arguments + f" --{key}.{key_2}"
else:
arguments = arguments + f" --{key}.{key_2} {value_2}"
else:
arguments = arguments + (f" --{key} {value}")
except Exception:
continue
return arguments


class NestedNamespace(argparse.Namespace):
def __setattr__(self, name, value):
if "." in name:
group, name = name.split(".", 1)
ns = getattr(self, group, NestedNamespace())
setattr(ns, name, value)
self.__dict__[group] = ns
else:
self.__dict__[name] = value

def get(self, key, default=None):
if "." in key:
group, key = key.split(".", 1)
return getattr(self, group, NestedNamespace()).get(key, default)
return self.__dict__.get(key, default)


class MinerHistory:
"""This class is used to store miner predictions along with their timestamps.
Allows for easy formatting, filtering, and lookup of predictions by timestamp.
Expand Down
Loading

0 comments on commit 55b4125

Please sign in to comment.