Skip to content

Commit

Permalink
Merge pull request #38 from foundryservices/dev
Browse files Browse the repository at this point in the history
Release v2.2.0
  • Loading branch information
hayden-yuma authored Oct 22, 2024
2 parents 9165571 + 9420af5 commit 3a5f79a
Show file tree
Hide file tree
Showing 48 changed files with 1,016 additions and 494 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copy the contents on this file to a new file called .env

HF_ACCESS_TOKEN = 'REPLACE_WITH_HUGGINGFACE_ACCESS_KEY'
WANDB_API_KEY = 'REPLACE_WITH_WANDB_API_KEY'
WANDB_API_KEY = 'REPLACE_WITH_WANDB_API_KEY'
34 changes: 34 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[flake8]
extend-ignore =
# E203 Whitespace before ":"
E203,

# E266, # E266 Too many leading "###" for block comment

# E501 line too long (XX > 79 characters)
E501

# W503, # W503 Line break before binary operator
# F403, # F403 Used `from module import *`
# F401 # F401 `module` imported but not used
exclude =
# No need to traverse our git directory
.git,

# There's no value in checking cache directories
__pycache__,

# No need to traverse example code
*/examples/*,

# No need to traverse docs
docs,

# Additional folders to skip
mining_models,
contrib,
scripts,
.venv
max-complexity = 10
max-line-length = 79
per-file-ignores = __init__.py:F401
67 changes: 67 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Cache and Load Build

on:
workflow_call:
inputs:
command:
required: true
type: string
name:
required: true
type: string

jobs:
reusable-build:
name: ${{ inputs.name }}
runs-on: ubuntu-latest
steps:

#------------------------------------------------
# Checkout repo and setup python
#------------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.11'

#------------------------------------------------
# Load cached venv if cache exists
#------------------------------------------------
- name: Restore cached virtualenv
uses: actions/cache/restore@v4
id: restore-cache
with:
key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('dev_requirements.txt') }}
path: .venv

#------------------------------------------------
# Install dependencies - if cache does not exist
#------------------------------------------------
- name: Install dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install .[DEV]
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
#------------------------------------------------
# Save venv to cache - if not exists
#------------------------------------------------
- name: Saved cached virtualenv
if: steps.restore-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
path: .venv

#------------------------------------------------
# Run custom command(s) within venv
#------------------------------------------------
- name: Run commands
run: |
source .venv/bin/activate
${{ inputs.command }}
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Continuous Integration

on:
pull_request:
push:
branches: [main, dev]

jobs:
#----------------------------------------------
# Build Environment
#----------------------------------------------
build:
name: Build
uses: ./.github/workflows/build.yml
with:
name: Cache
command: |
python -m pip list
python --version
echo "Build successful"
#----------------------------------------------
# Run Linters
#----------------------------------------------
lint-black:
name: Linter
needs: build
uses: ./.github/workflows/build.yml
with:
name: Black
command: python -m black --check .
lint-isort:
name: Linter
needs: build
uses: ./.github/workflows/build.yml
with:
name: Isort
command: python -m isort --check-only .
lint-mypy:
name: Linter
needs: build
if: false # This condition ensures the job is never executed
uses: ./.github/workflows/build.yml
with:
name: Mypy
command: python -m mypy --verbose 0 .
lint-flake8:
name: Linter
needs: build
uses: ./.github/workflows/build.yml
with:
name: Flake8
command: python -m flake8 .

#----------------------------------------------
# Run Tests
#----------------------------------------------
test-unittest:
name: Tests
needs: [
lint-black,
lint-isort,
lint-mypy,
lint-flake8,
]
# `${{ always() }}` will run the tests regardless of linting success
if: false # This condition ensures the job is never executed
uses: ./.github/workflows/build.yml
with:
name: Unittests
command: pytest tests/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.python-version

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
120 changes: 120 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
repos:
- repo: local
hooks:
##########################
# FORMATTERS #
##########################
- id: black
name: black
description: Format Python code
language: system
types: [python]
entry: black
exclude: |
(?x)^(
.git/.*|
docs/.*|
mining_models/.*|
contrib/.*|
scripts/.*|
.venv/.*
)$
- id: isort
name: isort
description: Format Python import statements
language: system
types: [python]
entry: isort
exclude: |
(?x)^(
.git/.*|
docs/.*|
mining_models/.*|
contrib/.*|
scripts/.*|
.venv/.*
)$
##########################
# LINTERS #
##########################
# - id: mypy
# name: mypy
# description: Enforce correct python type hints
# language: system
# types: [python]
# entry: mypy
- id: flake8
name: flake8
description: Enforce PEP8 Python Style Guide
language: system
types: [python]
entry: flake8
exclude: |
(?x)^(
.git/.*|
docs/.*|
mining_models/.*|
contrib/.*|
scripts/.*|
.venv/.*
)$
##########################
# STANDARD #
##########################
- id: check-added-large-files
name: check for added large files
description: prevents giant files from being committed.
entry: check-added-large-files
language: system
stages: [pre-commit, pre-push, manual]
minimum_pre_commit_version: 3.2.0
args: ['--maxkb=500']
- id: check-ast
name: check python ast
description: simply checks whether the files parse as valid python.
entry: check-ast
language: system
types: [python]
- id: check-merge-conflict
name: check for merge conflicts
description: checks for files that contain merge conflict strings.
entry: check-merge-conflict
language: system
types: [text]
- id: check-toml
name: check toml
description: checks toml files for parseable syntax.
entry: check-toml
language: system
types: [toml]
- id: end-of-file-fixer
name: fix end of files
description: ensures that a file is either empty, or ends with one newline.
entry: end-of-file-fixer
language: system
types: [text]
stages: [pre-commit, pre-push, manual]
minimum_pre_commit_version: 3.2.0
- id: no-commit-to-branch
name: "don't commit to branch"
entry: no-commit-to-branch
language: system
pass_filenames: false
always_run: true
args: [--branch, main, --branch, dev]
- id: requirements-txt-fixer
name: fix requirements.txt
description: sorts entries in requirements.txt.
entry: requirements-txt-fixer
language: system
files: (requirements|dev_requirements).*\.txt$
- id: trailing-whitespace
name: trim trailing whitespace
description: trims trailing whitespace.
entry: trailing-whitespace-fixer
language: system
types: [text]
stages: [pre-commit, pre-push, manual]
minimum_pre_commit_version: 3.2.0
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<img src="accelerate.png" />

# **Foundry S&P 500 Oracle** <!-- omit in toc -->
---
---
Expand All @@ -23,15 +23,15 @@
---
## Introduction

Foundry is launching Foundry S&P 500 Oracle to incentivize miners to make predictions on the S&P 500 price frequently throughout trading hours. Validators send miners a timestamp (a future time), which the miners need to use to make predictions on the close price of the S&P 500 for the next six 5m intervals. Miners need to respond with their prediction for the price of the S&P 500 at the given time. Validators store the miner predictions, and then calculate the scores of the miners after the predictions mature. Miners are ranked against eachother, naturally incentivizing competition between the miners.
Foundry is launching Foundry S&P 500 Oracle to incentivize miners to make predictions on the S&P 500 price frequently throughout trading hours. Validators send miners a timestamp (a future time), which the miners need to use to make predictions on the close price of the S&P 500 for the next six 5m intervals. Miners need to respond with their prediction for the price of the S&P 500 at the given time. Validators store the miner predictions, and then calculate the scores of the miners after the predictions mature. Miners are ranked against eachother, naturally incentivizing competition between the miners.

---
## Design Decisions

A Bittensor integration into financial markets will expose Bittensor to the largest system in the world; the global economy. The S&P 500 serves as a perfect starting place for financial predictions given its utility and name recognition. Financial market predictions were chosen for three main reasons:
1) __Utility:__ financial markets provide a massive userbase of professional traders, wealth managers, and individuals alike
2) __Objective Rewards Mechanism:__ by tying the rewards mechanism to an external source of truth (yahoo finance's S&P Price), the defensibility of the subnet regarding gamification is quite strong.
3) __Adversarial Environment:__ the adversarial environment, especially given the rewards mechanism, will allow for significant diversity of models. Miners will be driven to acquire different datasets, implement different training methods, and utilize different model architectures in order to develop the most performant models.
2) __Objective Rewards Mechanism:__ by tying the rewards mechanism to an external source of truth (yahoo finance's S&P Price), the defensibility of the subnet regarding gamification is quite strong.
3) __Adversarial Environment:__ the adversarial environment, especially given the rewards mechanism, will allow for significant diversity of models. Miners will be driven to acquire different datasets, implement different training methods, and utilize different model architectures in order to develop the most performant models.
---
## Installation
### Install PM2
Expand All @@ -49,8 +49,8 @@ pm2 --version

| Validator | Miner |
|---------- |-----------|
| 8gb RAM | 8gb RAM |
| 2 vCPUs | 2 vCPUs |
| 8gb RAM | 8gb RAM |
| 2 vCPUs | 2 vCPUs |

### Install-Repo

Expand All @@ -69,7 +69,7 @@ pip3 install -e snpOracle
```

### Running a Miner
ecosystem.config.js files have been created to make deployment of miners and validators easier for the node operator. These files are the default configuration files for PM2, and allow the user to define the environment & application in a cleaner way. IMPORTANT: Make sure your have activated your virtual environment before running your validator/miner.
ecosystem.config.js files have been created to make deployment of miners and validators easier for the node operator. These files are the default configuration files for PM2, and allow the user to define the environment & application in a cleaner way. IMPORTANT: Make sure your have activated your virtual environment before running your validator/miner.
First copy the .env.template file to .env
```
cp .env.template .env
Expand All @@ -95,7 +95,7 @@ module.exports = {
};
```
### Running a Validator
ecosystem.config.js files have been created to make deployment of miners and validators easier for the node operator. These files are the default configuration files for PM2, and allow the user to define the environment & application in a cleaner way. IMPORTANT: Make sure your have activated your virtual environment before running your validator/miner.
ecosystem.config.js files have been created to make deployment of miners and validators easier for the node operator. These files are the default configuration files for PM2, and allow the user to define the environment & application in a cleaner way. IMPORTANT: Make sure your have activated your virtual environment before running your validator/miner.

#### Obtain & Setup WandB API Key
Before starting the process, validators would be required to procure a WANDB API Key. Please follow the instructions mentioned below:<br>
Expand All @@ -112,7 +112,7 @@ To run your validator:
pm2 start validator.config.js
```

The validator.config.js has few flags added. Any standard flags can be passed, for example, wallet name and hotkey name will default to "default"; if you have a different configuration, edit your "args" in validator.config.js. Below shows a validator.config.js with extra configuration flags.
The validator.config.js has few flags added. Any standard flags can be passed, for example, wallet name and hotkey name will default to "default"; if you have a different configuration, edit your "args" in validator.config.js. Below shows a validator.config.js with extra configuration flags.
```
module.exports = {
apps: [
Expand Down Expand Up @@ -161,7 +161,7 @@ Once the miners have all been ranked, we convert these ranks to validator weight
```math
W_{m} = e^{-0.05 * rank_m}
```
The constant shown in this equation, −0.05, is a hyperparameter which controls the steepness of the curve (i.e. what proportion of the emissions are allocated to rank 1, 2, 3,... etc.). We chose this value to fairly distribute across miners to mitigate the effect of rank volatility. This ranking system ensures that machine learning or statistical models will inherently perform better than any method of gamification. By effectively performing a commit-reveal on a future S&P Price Prediction, S&P Oracle ensures that only well-tuned models will survive.
The constant shown in this equation, −0.05, is a hyperparameter which controls the steepness of the curve (i.e. what proportion of the emissions are allocated to rank 1, 2, 3,... etc.). We chose this value to fairly distribute across miners to mitigate the effect of rank volatility. This ranking system ensures that machine learning or statistical models will inherently perform better than any method of gamification. By effectively performing a commit-reveal on a future S&P Price Prediction, S&P Oracle ensures that only well-tuned models will survive.

---

Expand Down
Loading

0 comments on commit 3a5f79a

Please sign in to comment.