Skip to content

Commit

Permalink
Merge pull request #13 from coinmetrics/Update-Makefile-for-testnet
Browse files Browse the repository at this point in the history
organized parameters in Makefile
  • Loading branch information
mtrudeau-foundry-digital authored Dec 6, 2024
2 parents 6942445 + 189062b commit 63e284c
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 140 deletions.
55 changes: 18 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
network = ws://127.0.0.1:9944
netuid = 1
## Network Parameters ##
finney = wss://entrypoint-finney.opentensor.ai:443
testnet = wss://test.finney.opentensor.ai:443
locanet = ws://127.0.0.1:9944

testnet_netuid = 256
localnet_netuid = 1
logging_level = trace # options= ['info', 'debug', 'trace']
coldkey = cm-owner

netuid = $(testnet_netuid)
network = $(testnet)

## User Parameters
coldkey = default
validator_hotkey = validator
miner_hotkey = miner

metagraph:
btcli subnet metagraph --netuid $(netuid) --subtensor.chain_endpoint $(network)
Expand All @@ -16,32 +28,23 @@ validator:
python start_validator.py \
--neuron.name validator \
--wallet.name $(coldkey) \
--wallet.hotkey validator \
--wallet.hotkey $(validator_hotkey) \
--subtensor.chain_endpoint $(network) \
--axon.port 30335 \
--netuid $(netuid) \
--logging.level $(logging_level)

validator2:
python start_validator.py \
--neuron.name validator2 \
--wallet.name $(coldkey) \
--wallet.hotkey validator2 \
--subtensor.chain_endpoint $(network) \
--axon.port 30339 \
--netuid $(netuid) \
--logging.level $(logging_level)

miner:
python start_miner.py \
--neuron.name miner \
--wallet.name $(coldkey) \
--wallet.hotkey miner \
--wallet.hotkey $(miner_hotkey) \
--subtensor.chain_endpoint $(network) \
--axon.port 30336 \
--netuid $(netuid) \
--logging.level $(logging_level) \
--timeout 16 \
--vpermit_tao_limit 2 \
--forward_function forward

miner2:
Expand All @@ -55,25 +58,3 @@ miner2:
--logging.level $(logging_level) \
--timeout 16 \
--forward_function forward_bad

miner3:
python start_miner.py \
--neuron.name miner3 \
--wallet.name $(coldkey) \
--wallet.hotkey miner3 \
--subtensor.chain_endpoint $(network) \
--axon.port 30338 \
--netuid $(netuid) \
--logging.level $(logging_level) \
--timeout 16 \
--forward_function forward

setup_local:
btcli wallet faucet --wallet.name $(coldkey) --subtensor.chain_endpoint $(network) ;\
btcli subnet create --wallet.name $(coldkey) --subtensor.chain_endpoint $(network) ;\
btcli subnet register \
--wallet.name $(coldkey) \
--wallet.hotkey validator \
--netuid $(netuid)
--subtensor.chain_endpoint $(network) ;\
btcli stake add --wallet.name $(coldkey) --wallet.hotkey validator --amount 1024 ;\
6 changes: 3 additions & 3 deletions precog/utils/bittensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def setup_bittensor_objects(self):
# if chain endpoint is set, overwrite network arg
self.config.subtensor.network = self.config.subtensor.chain_endpoint
# Initialize subtensor.
self.subtensor = bt.subtensor(config=self.config, network=self.config.subtensor.network)
self.subtensor = bt.subtensor(config=self.config, network=self.config.subtensor.chain_endpoint)
self.metagraph = self.subtensor.metagraph(self.config.netuid)
self.wallet = bt.wallet(name=self.config.wallet.name, hotkey=self.config.wallet.hotkey)
self.wallet = bt.wallet(config=self.config)
self.dendrite = bt.dendrite(wallet=self.wallet)
self.axon = bt.axon(wallet=self.wallet, config=self.config, port=self.config.axon.port)
# Connect the validator to the network.
Expand Down Expand Up @@ -46,7 +46,7 @@ def setup_bittensor_objects(self):

def print_info(self) -> None:
if self.config.neuron.type == "Validator":
weight_timing = self.set_weights_rate - self.blocks_since_last_update
weight_timing = self.hyperparameters.weights_rate_limit - self.blocks_since_last_update
if weight_timing <= 0:
weight_timing = "a few" # hashtag aesthetic af
log = (
Expand Down
56 changes: 55 additions & 1 deletion precog/utils/general.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import argparse
import asyncio
import re
from typing import Optional
import time
from typing import Any, Callable, Optional

import bittensor as bt
import git
import requests
from numpy import argsort, array, concatenate, cumsum, empty_like

from precog.utils.classes import NestedNamespace

Expand Down Expand Up @@ -84,3 +87,54 @@ def get_version() -> Optional[str]:
raise Exception("Version information not found")

return version_match.group()


def rank(vector):
if vector is None or len(vector) <= 1:
return array([0])
else:
# Sort the array and get the indices that would sort it
sorted_indices = argsort(vector)
sorted_vector = vector[sorted_indices]
# Create a mask for where each new unique value starts in the sorted array
unique_mask = concatenate(([True], sorted_vector[1:] != sorted_vector[:-1]))
# Use cumulative sum of the unique mask to get the ranks, then assign back in original order
ranks = cumsum(unique_mask) - 1
rank_vector = empty_like(vector, dtype=int)
rank_vector[sorted_indices] = ranks
return rank_vector


async def loop_handler(self, func: Callable, sleep_time: float = 120):
try:
while not self.stop_event.is_set():
async with self.lock:
await func()
await asyncio.sleep(sleep_time)
except asyncio.CancelledError:
bt.logging.error(f"{func.__name__} cancelled")
raise
except KeyboardInterrupt:
raise
except Exception as e:
bt.logging.error(f"{func.__name__} raised error: {e}")
raise e
finally:
async with self.lock:
self.stop_event.set()


def func_with_retry(func: Callable, max_attempts: int = 3, delay: float = 1, *args, **kwargs) -> Any:
attempt = 0
while attempt < max_attempts:
try:
result = func(*args, **kwargs)
return result
except Exception as e:
attempt += 1
bt.logging.debug(f"Function {func} failed: Attempt {attempt} of {max_attempts} with error: {e}")
if attempt == max_attempts:
bt.logging.error(f"Function {func} failed {max_attempts} times, skipping.")
raise
else:
time.sleep(delay)
17 changes: 1 addition & 16 deletions precog/validators/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np

from precog.protocol import Challenge
from precog.utils.general import rank
from precog.utils.timestamp import align_timepoints, get_now, mature_dictionary, round_minute_down


Expand Down Expand Up @@ -49,22 +50,6 @@ def calc_rewards(
return rewards


def rank(vector):
if vector is None or len(vector) <= 1:
return np.array([0])
else:
# Sort the array and get the indices that would sort it
sorted_indices = np.argsort(vector)
sorted_vector = vector[sorted_indices]
# Create a mask for where each new unique value starts in the sorted array
unique_mask = np.concatenate(([True], sorted_vector[1:] != sorted_vector[:-1]))
# Use cumulative sum of the unique mask to get the ranks, then assign back in original order
ranks = np.cumsum(unique_mask) - 1
rank_vector = np.empty_like(vector, dtype=int)
rank_vector[sorted_indices] = ranks
return rank_vector


def interval_error(intervals, cm_prices):
if intervals is None:
return np.array([0])
Expand Down
11 changes: 0 additions & 11 deletions precog/validators/validator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import asyncio
from pathlib import Path

import bittensor as bt

from precog.utils.classes import Config
from precog.utils.general import parse_arguments
from precog.validators.weight_setter import weight_setter
Expand All @@ -22,15 +20,6 @@ def __init__(self):
async def main(self):
loop = asyncio.get_event_loop()
self.weight_setter = weight_setter(config=self.config, loop=loop)
try:
loop.run_forever()
except BrokenPipeError:
bt.logging.error("Recieved a Broken Pipe substrate error")
asyncio.run(self.reset_instance())
except Exception as e:
bt.logging.error(f"Unhandled exception: {e}")
finally:
bt.logging.info("Exiting Validator")

async def reset_instance(self):
self.__init__()
Expand Down
Loading

0 comments on commit 63e284c

Please sign in to comment.