Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions neurons/backtest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from vali_objects.utils.challengeperiod_manager import ChallengePeriodManager # noqa: E402
from vali_objects.utils.elimination_manager import EliminationManager # noqa: E402
from vali_objects.utils.live_price_fetcher import LivePriceFetcher # noqa: E402
from vali_objects.utils.plagiarism_detector import PlagiarismDetector # noqa: E402
from vali_objects.utils.position_lock import PositionLocks # noqa: E402
from vali_objects.utils.position_manager import PositionManager # noqa: E402
from vali_objects.utils.price_slippage_model import PriceSlippageModel # noqa: E402
Expand Down Expand Up @@ -167,11 +166,9 @@ def __init__(self, positions_at_t_f, start_time_ms, secrets, scoring_func,

self.weight_setter = SubtensorWeightSetter(self.metagraph, position_manager=self.position_manager, is_backtesting=True)
self.position_locks = PositionLocks(hotkey_to_positions=positions_at_t_f, is_backtesting=True)
self.plagiarism_detector = PlagiarismDetector(self.metagraph)
self.miner_statistics_manager = MinerStatisticsManager(
position_manager=self.position_manager,
subtensor_weight_setter=self.weight_setter,
plagiarism_detector=self.plagiarism_detector
subtensor_weight_setter=self.weight_setter
)
self.psm = PriceSlippageModel(self.live_price_fetcher, is_backtesting=True, fetch_slippage_data=fetch_slippage_data,
recalculate_slippage=recalculate_slippage, capital=capital)
Expand Down
12 changes: 2 additions & 10 deletions neurons/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
from vali_objects.utils.vali_utils import ValiUtils
from vali_objects.vali_config import ValiConfig

from vali_objects.utils.plagiarism_detector import PlagiarismDetector
from vali_objects.utils.validator_contract_manager import ValidatorContractManager

# Global flag used to indicate shutdown
Expand Down Expand Up @@ -346,11 +345,6 @@ def rc_priority_fn(synapse: template.protocol.ValidatorCheckpoint) -> float:
# Eliminations are written in elimination_manager, mdd_checker
# Since the mainloop is run synchronously, we just need to lock eliminations when writing to them and when
# reading outside of the mainloop (validator).
self.plagiarism_detector = PlagiarismDetector(self.metagraph, shutdown_dict=shutdown_dict,
position_manager=self.position_manager)
# Start the plagiarism detector in its own thread
self.plagiarism_thread = Process(target=self.plagiarism_detector.run_update_loop, daemon=True)
self.plagiarism_thread.start()

self.mdd_checker = MDDChecker(self.metagraph, self.position_manager, live_price_fetcher=self.live_price_fetcher,
shutdown_dict=shutdown_dict, compaction_enabled=True)
Expand All @@ -363,8 +357,8 @@ def rc_priority_fn(synapse: template.protocol.ValidatorCheckpoint) -> float:
weight_request_queue=weight_request_queue # Same queue as MetagraphUpdater
)

self.request_core_manager = RequestCoreManager(self.position_manager, self.weight_setter, self.plagiarism_detector, self.contract_manager)
self.miner_statistics_manager = MinerStatisticsManager(self.position_manager, self.weight_setter, self.plagiarism_detector)
self.request_core_manager = RequestCoreManager(self.position_manager, self.weight_setter, self.contract_manager)
self.miner_statistics_manager = MinerStatisticsManager(self.position_manager, self.weight_setter)

# Start the perf ledger updater loop in its own process. Make sure it happens after the position manager has chances to make any fixes
self.perf_ledger_updater_thread = Process(target=self.perf_ledger_manager.run_update_loop, daemon=True)
Expand Down Expand Up @@ -559,8 +553,6 @@ def check_shutdown(self):
if hasattr(self, 'weight_processing_thread'):
bt.logging.warning("Stopping weight processing thread...")
self.weight_processing_thread.join()
bt.logging.warning("Stopping plagiarism detector...")
self.plagiarism_thread.join()
if self.rog_thread:
bt.logging.warning("Stopping request output generator...")
self.rog_thread.join()
Expand Down
6 changes: 3 additions & 3 deletions restore_validator_from_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def regenerate_miner_positions(perform_backup=True, backup_from_data_dir=False,
return False

bt.logging.info("Found validator backup file with the following attributes:")
# Log every key and value apir in the data except for positions, eliminations, and plagiarism scores
# Log every key and value apir in the data except for positions and eliminations
for key, value in data.items():
# Check is the value is of type dict or list. If so, print the size of the dict or list
if isinstance(value, dict) or isinstance(value, list):
# Log the size of the positions, eliminations, and plagiarism scores
# Log the size of the positions and eliminations
bt.logging.info(f" {key}: {len(value)} entries")
else:
bt.logging.info(f" {key}: {value}")
Expand Down Expand Up @@ -142,7 +142,7 @@ def regenerate_miner_positions(perform_backup=True, backup_from_data_dir=False,
msg = (f"Detected {n_existing_position} hotkeys with positions, {n_existing_eliminations} eliminations")
bt.logging.info(msg)

bt.logging.info("Overwriting all existing positions, eliminations, and plagiarism scores.")
bt.logging.info("Overwriting all existing positions and eliminations.")
if perform_backup:
backup_validation_directory()

Expand Down
5 changes: 2 additions & 3 deletions runnable/generate_request_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
assert sorted(PERCENT_NEW_POSITIONS_TIERS, reverse=True) == PERCENT_NEW_POSITIONS_TIERS, 'needs to be sorted for efficient pruning'

class RequestCoreManager:
def __init__(self, position_manager, subtensor_weight_setter, plagiarism_detector, contract_manager=None):
def __init__(self, position_manager, subtensor_weight_setter, contract_manager=None):
self.position_manager = position_manager
self.perf_ledger_manager = position_manager.perf_ledger_manager
self.elimination_manager = position_manager.elimination_manager
self.challengeperiod_manager = position_manager.challengeperiod_manager
self.subtensor_weight_setter = subtensor_weight_setter
self.plagiarism_detector = plagiarism_detector
self.contract_manager = contract_manager

def hash_string_to_int(self, s: str) -> int:
Expand Down Expand Up @@ -257,7 +256,7 @@ def generate_request_core(self, get_dash_data_hotkey: str | None = None, write_a
assert n_orders_original == n_positions_new, f"n_orders_original: {n_orders_original}, n_positions_new: {n_positions_new}"

challengeperiod_dict = self.challengeperiod_manager.to_checkpoint_dict()

# Get miner account sizes if contract manager is available
miner_account_sizes_dict = {}
if self.contract_manager:
Expand Down
19 changes: 5 additions & 14 deletions runnable/generate_request_minerstatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from time_util.time_util import TimeUtil
from vali_objects.utils.challengeperiod_manager import ChallengePeriodManager
from vali_objects.utils.elimination_manager import EliminationManager
from vali_objects.utils.plagiarism_detector import PlagiarismDetector
from vali_objects.utils.position_manager import PositionManager
from vali_objects.utils.validator_contract_manager import ValidatorContractManager
from vali_objects.vali_config import ValiConfig, TradePair
Expand Down Expand Up @@ -154,15 +153,13 @@ def __init__(
self,
position_manager: PositionManager,
subtensor_weight_setter: SubtensorWeightSetter,
plagiarism_detector: PlagiarismDetector,
metrics: Dict[str, MetricsCalculator] = None
):
self.position_manager = position_manager
self.perf_ledger_manager = position_manager.perf_ledger_manager
self.elimination_manager = position_manager.elimination_manager
self.challengeperiod_manager = position_manager.challengeperiod_manager
self.subtensor_weight_setter = subtensor_weight_setter
self.plagiarism_detector = plagiarism_detector
self.contract_manager = self.perf_ledger_manager.contract_manager

self.metrics_calculator = MetricsCalculator(metrics=metrics)
Expand Down Expand Up @@ -456,7 +453,7 @@ def calculate_pnl_info(self, filtered_ledger: Dict[str, Dict[str, PerfLedger]],

raw_pnl_values = []
account_sizes = []

# Calculate raw PnL for each miner
for hotkey, ledgers in filtered_ledger.items():
portfolio_ledger = ledgers.get(TP_ID_PORTFOLIO)
Expand All @@ -473,7 +470,7 @@ def calculate_pnl_info(self, filtered_ledger: Dict[str, Dict[str, PerfLedger]],
else:
account_size = max(account_size, ValiConfig.CAPITAL_FLOOR)
account_sizes.append((hotkey, account_size))

# Calculate rankings and percentiles
ranks = self.rank_dictionary(raw_pnl_values)
percentiles = self.percentile_rank_dictionary(raw_pnl_values)
Expand All @@ -482,7 +479,7 @@ def calculate_pnl_info(self, filtered_ledger: Dict[str, Dict[str, PerfLedger]],
account_size_ranks = self.rank_dictionary(account_sizes)
account_size_percentiles = self.percentile_rank_dictionary(account_sizes)
account_sizes_dict = dict(account_sizes)

# Build result dictionary
result = {}
for hotkey in values_dict:
Expand All @@ -498,7 +495,7 @@ def calculate_pnl_info(self, filtered_ledger: Dict[str, Dict[str, PerfLedger]],
"percentile": percentiles[hotkey]
}
}

return result

# -------------------------------------------
Expand Down Expand Up @@ -642,8 +639,6 @@ def generate_miner_statistics_data(
weights_rank = self.rank_dictionary(combined_weights_list)
weights_percentile = self.percentile_rank_dictionary(combined_weights_list)

# Load plagiarism once
plagiarism_scores = self.plagiarism_detector.get_plagiarism_scores_from_disk()

# Prepare data for each miner
miner_data = {}
Expand Down Expand Up @@ -739,8 +734,6 @@ def build_scores_dict(metric_set: Dict[str, Dict[str, ScoreResult]]) -> Dict[str
}
# Raw PnL
raw_pnl_info = raw_pnl_dict.get(hotkey, {"value": 0.0, "rank": None, "percentile": 0.0})
# Plagiarism
plagiarism_val = plagiarism_scores.get(hotkey)

# Weight
w_val = weights_dict.get(hotkey)
Expand Down Expand Up @@ -768,7 +761,6 @@ def build_scores_dict(metric_set: Dict[str, Dict[str, ScoreResult]]) -> Dict[str
"daily_returns": daily_returns_list,
"volatility": volatility_subdict,
"drawdowns": drawdowns_subdict,
"plagiarism": plagiarism_val,
"engagement": engagement_subdict,
"risk_profile": risk_profile_single_dict,
"asset_subcategory_performance": asset_subcategory_performance,
Expand Down Expand Up @@ -884,9 +876,8 @@ def generate_request_minerstatistics(self, time_now: int, checkpoints: bool = Tr
running_unit_tests=False,
position_manager=position_manager,
)
plagiarism_detector = PlagiarismDetector(metagraph, None, position_manager=position_manager)

msm = MinerStatisticsManager(position_manager, subtensor_weight_setter, plagiarism_detector)
msm = MinerStatisticsManager(position_manager, subtensor_weight_setter)
pwd = os.getcwd()
custom_output_path = os.path.join(pwd, 'debug_miner_statistics.json')
msm.generate_request_minerstatistics(TimeUtil.now_in_millis(), True, custom_output_path=custom_output_path)
Expand Down
10 changes: 0 additions & 10 deletions tests/shared_objects/mock_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from vali_objects.utils.challengeperiod_manager import ChallengePeriodManager
from vali_objects.utils.live_price_fetcher import LivePriceFetcher
from vali_objects.utils.mdd_checker import MDDChecker
from vali_objects.utils.plagiarism_detector import PlagiarismDetector
from vali_objects.utils.position_manager import PositionManager
from vali_objects.utils.price_slippage_model import PriceSlippageModel
from vali_objects.vali_config import TradePair
Expand Down Expand Up @@ -41,15 +40,6 @@ def __init__(self, metagraph):
super().__init__(metagraph, running_unit_tests=True)


class MockPlagiarismDetector(PlagiarismDetector):
def __init__(self, metagraph, position_manager):
super().__init__(metagraph, running_unit_tests=True, position_manager=position_manager)

# Lets us bypass the wait period in PlagiarismDetector
def get_last_update_time_ms(self):
return 0


class MockChallengePeriodManager(ChallengePeriodManager):
def __init__(self, metagraph, position_manager):
super().__init__(metagraph, running_unit_tests=True, position_manager=position_manager)
Expand Down
Loading
Loading