Skip to content

Commit 734e41d

Browse files
committed
setup improvements
1 parent 8ad05f7 commit 734e41d

3 files changed

Lines changed: 103 additions & 247 deletions

File tree

‎.github/copilot-instructions.md‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
# Trading Analytics - AI Agent Instructions
22

3+
## Quick Reference
4+
5+
**Start Here:**
6+
- Run analysis: `python web_server_parallel.py` → http://localhost:8080
7+
- Single script: `python gpu_wavelet_gpu_plot.py BTC 5m`
8+
- Setup: `./setup_env.sh` (creates .venv, installs deps, detects GPU)
9+
10+
**Key Constraints:**
11+
- LSTM scaling: Always use `MinMaxScaler(feature_range=(-1, 1))` - never [0,1]
12+
- Data loading: Adaptive date ranges by timeframe (see pattern below)
13+
- OpenCL: Auto-detect best platform with scoring (NVIDIA>AMD>ARM)
14+
- Pi Zero: Use `--demo --no-plots` flag (ccxt causes bus errors)
15+
16+
**File Organization:**
17+
- Notebooks: Monolithic, state-dependent (must run sequentially)
18+
- GPU scripts: Accept `<CURRENCY> <TIMEFRAME>` CLI args
19+
- Parallel system: `prepare_data.py` → 6 plot processes (3.5x speedup)
20+
321
## Project Overview
4-
Cryptocurrency trading toolkit targeting **Orange Pi and embedded systems**. Performs BTC/ETH/SOL price prediction and anomaly detection using LSTM networks and GPU-accelerated wavelet transforms. Real-time data from Binance via CCXT.
22+
Cryptocurrency trading toolkit for **Orange Pi and embedded systems**. Performs BTC/ETH/SOL price prediction and anomaly detection using LSTM networks and GPU-accelerated wavelet transforms. Real-time data from Binance via CCXT.
523

624
**Key Design Goals:**
7-
- Multi-platform GPU support (OpenCL → CUDA → Vulkan → OpenGL → CPU)
8-
- Graceful degradation (demo mode, lazy imports)
9-
- Parallel processing optimization for multi-core ARM devices
10-
- Publication-quality plot generation (300 DPI PNG)
25+
- Multi-platform GPU support (OpenCL → CUDA → Vulkan → OpenGL → CPU fallback)
26+
- Graceful degradation (demo mode, lazy imports, error handling)
27+
- Parallel processing (3.5x speedup via OS-level subprocess spawning)
28+
- Publication-quality plot generation (300 DPI PNG, 6 plots per analysis)
1129

1230
## Architecture
1331

@@ -17,14 +35,14 @@ Jupyter Notebooks (btc-prediction.ipynb, wave_nada.ipynb)
1735
↓ LSTM training, interactive analysis
1836
1937
GPU Wavelet Scripts (5 variants: opencl/cuda/vulkan/opengl/cpu)
20-
↓ Batch processing with command-line args
38+
↓ Batch processing with CLI args: python <script>.py <CURRENCY> <TIMEFRAME>
2139
2240
Web Servers (3 variants: standard/parallel/vulkan)
23-
↓ HTTP interface with async job tracking
41+
↓ HTTP interface (port 8080) with async job tracking
2442
25-
Parallel Plot System (NEW)
43+
Parallel Plot System (PRODUCTION)
2644
prepare_data.py → [plot_01.py, plot_template.py × 5] (subprocess.Popen)
27-
↓ 3.5x speedup via OS-level parallelism
45+
↓ 3.5x speedup via OS-level parallelism (13s vs 45s)
2846
```
2947

3048
### Core Files
@@ -45,9 +63,9 @@ Parallel Plot System (NEW)
4563
- `web_server_parallel.py`: **PREFERRED** - parallel plot generation (3.5x faster)
4664
- `web_server_vulkan.py`: Vulkan backend variant
4765

48-
**Parallel System** (NEW):
66+
**Parallel System** (PRODUCTION):
4967
- `prepare_data.py`: Data load + GPU wavelet → `wavelet_data.pkl` cache
50-
- `plot_common.py`: Shared utilities (`gpu_convolve`, `load_wavelet_data`)
68+
- `plot_common.py`: Shared utilities (`gpu_convolve`, `load_wavelet_data`, `save_wavelet_data`)
5169
- `plot_01.py`: Main 4-panel overview (full implementation)
5270
- `plot_template.py`: Simplified plots 02a-05 (accepts plot ID arg)
5371

@@ -60,7 +78,7 @@ python gpu_wavelet_gpu_plot.py BTC 5m # Generates 6 PNG plots
6078
./run_all_currencies.sh # 18 plots (BTC/ETH/SOL × 6)
6179
./run_all_currencies_console.sh # Console output with ASCII
6280

63-
# Web interface
81+
# Web interface (RECOMMENDED)
6482
python web_server_parallel.py # http://localhost:8080 (parallel)
6583
python web_server.py # http://localhost:8080 (sequential)
6684

@@ -75,7 +93,7 @@ python gpu_wavelet_cpu_plot.py --demo --no-plots
7593

7694
## Critical Code Patterns
7795

78-
### 1. Data Loading (MANDATORY for all scripts)
96+
### 1. Data Loading (Adaptive Date Ranges)
7997
**Pattern:** Adaptive date range based on timeframe to get ~700-1000 candles consistently.
8098

8199
```python

‎setup_env.sh‎

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# ===========================================
44
# Automatic setup: Creates .venv and installs all dependencies + GPU support
55

6-
set -e # Exit on error
6+
# Don't exit on error for optional components
7+
set +e
78

89
# Colors for output
910
GREEN='\033[0;32m'
@@ -70,44 +71,63 @@ echo -e "${GREEN}✓${NC} Activated"
7071

7172
# Upgrade pip
7273
echo ""
73-
echo -e "${BLUE}[3/6]${NC} Upgrading pip..."
74+
echo -e "${BLUE}[3/7]${NC} Upgrading pip..."
7475
pip install --upgrade pip -q
7576
echo -e "${GREEN}✓${NC} pip upgraded"
7677

77-
# Install all dependencies
78+
# Install system dependencies for Python packages
7879
echo ""
79-
echo -e "${BLUE}[4/6]${NC} Installing all dependencies from requirements.txt..."
80-
echo "This may take several minutes..."
81-
pip install -r requirements.txt
80+
echo -e "${BLUE}[4/7]${NC} Installing system dependencies..."
81+
echo "This requires sudo privileges..."
82+
83+
# Python development headers (required for pyopencl)
84+
sudo apt update -qq
85+
sudo apt install -y python3-dev python3-pip build-essential cmake ocl-icd-opencl-dev clinfo >/dev/null 2>&1 || echo -e "${YELLOW}⚠${NC} Some system packages may not be available"
86+
echo -e "${GREEN}✓${NC} System dependencies installed"
87+
88+
# Install core dependencies (without pyopencl)
8289
echo ""
83-
echo -e "${GREEN}✓${NC} All dependencies installed
90+
echo -e "${BLUE}[5/7]${NC} Installing core Python dependencies..."
91+
echo "This may take several minutes..."
8492

85-
# GPU Setup (OpenCL & Vulkan)
93+
# Create temporary requirements without pyopencl
94+
grep -v "^pyopencl" requirements.txt > /tmp/requirements_core.txt
95+
96+
pip install -r /tmp/requirements_core.txt
8697
echo ""
87-
echo -e "${BLUE}[5/6]${NC} Setting up GPU support (OpenCL & Vulkan)..."
98+
echo -e "${GREEN}✓${NC} Core dependencies installed"
99+
100+
# Try to install pyopencl (optional)
88101
echo ""
102+
echo -e "${BLUE}[6/7]${NC} Installing GPU support (pyopencl - optional)..."
103+
if pip install pyopencl==2025.2.7 2>&1 | tee /tmp/pyopencl_install.log; then
104+
echo -e "${GREEN}✓${NC} pyopencl installed successfully"
105+
else
106+
echo -e "${YELLOW}⚠${NC} pyopencl installation failed (GPU acceleration disabled)"
107+
echo " CPU fallback will be used. Check /tmp/pyopencl_install.log for details."
108+
echo " The project will still work with gpu_wavelet_cpu_plot.py"
109+
fi
89110

90-
# Install OpenCL support
91-
echo "Installing OpenCL runtime..."
92-
sudo apt update -qq
93-
sudo apt install -y ocl-icd-libopencl1 mesa-opencl-icd clinfo >/dev/null 2>&1
94-
echo -e "${GREEN}✓${NC} OpenCL installed"
111+
# GPU Runtime Setup (Vulkan & Mesa)
112+
echo ""
113+
echo -e "${BLUE}[7/7]${NC} Setting up GPU runtime (Vulkan & Mesa)..."
114+
echo ""
95115

96-
# Install Vulkan support
97-
echo "Installing Vulkan runtime..."
98-
sudo apt install -y vulkan-tools mesa-vulkan-drivers libvulkan1 >/dev/null 2>&1
99-
echo -e "${GREEN}✓${NC} Vulkan installed"
116+
# Install Vulkan support (optional)
117+
echo "Installing Vulkan runtime (optional)..."
118+
sudo apt install -y vulkan-tools mesa-vulkan-drivers libvulkan1 >/dev/null 2>&1 || echo -e "${YELLOW}⚠${NC} Vulkan packages not available"
119+
echo -e "${GREEN}✓${NC} Vulkan setup complete"
100120

101-
# Install Mesa utilities
102-
echo "Installing Mesa GPU utilities..."
103-
sudo apt install -y mesa-utils libgl1-mesa-dri >/dev/null 2>&1
121+
# Install Mesa utilities (optional)
122+
echo "Installing Mesa GPU utilities (optional)..."
123+
sudo apt install -y mesa-utils libgl1-mesa-dri mesa-opencl-icd >/dev/null 2>&1 || echo -e "${YELLOW}⚠${NC} Mesa packages not available"
104124
echo -e "${GREEN}✓${NC} Mesa utilities installed"
105125

106-
# Load panfrost GPU driver
107-
echo "Loading panfrost GPU driver..."
108-
sudo modprobe panfrost 2>/dev/null || echo -e "${YELLOW}⚠${NC} Panfrost module not loaded (enable GPU in orangepi-config)"
109-
echo "panfrost" | sudo tee /etc/modules-load.d/panfrost.conf >/dev/null
110-
echo -e "${GREEN}✓${NC} Panfrost configured to load on boot"
126+
# Load panfrost GPU driver (Orange Pi specific)
127+
echo "Loading panfrost GPU driver (Orange Pi specific)..."
128+
sudo modprobe panfrost 2>/dev/null || echo -e "${YELLOW}⚠${NC} Panfrost module not loaded (enable GPU in orangepi-config if on Orange Pi)"
129+
echo "panfrost" | sudo tee /etc/modules-load.d/panfrost.conf >/dev/null 2>&1 || true
130+
echo -e "${GREEN}✓${NC} Panfrost configured"
111131

112132
# Set GPU permissions
113133
echo "Configuring GPU permissions..."
@@ -117,7 +137,7 @@ echo -e "${GREEN}✓${NC} User added to render and video groups"
117137

118138
# Configure environment
119139
echo ""
120-
echo -e "${BLUE}[6/6]${NC} Configuring GPU environment..."
140+
echo "Configuring GPU environment variables..."
121141

122142
# Add to venv activation
123143
echo 'export RUSTICL_ENABLE=panfrost' >> "$VENV_DIR/bin/activate"
@@ -147,6 +167,10 @@ else
147167
echo -e "${YELLOW}⚠${NC} GPU device not found - enable in orangepi-config and reboot"
148168
fi"
149169
170+
# Check what was installed
171+
PYOPENCL_INSTALLED=false
172+
$VENV_DIR/bin/python -c "import pyopencl" 2>/dev/null && PYOPENCL_INSTALLED=true
173+
150174
# Summary
151175
echo ""
152176
echo "======================================================================"
@@ -155,13 +179,30 @@ echo "======================================================================"
155179
echo ""
156180
echo "Virtual environment: $VENV_DIR/"
157181
echo ""
182+
echo "Python Packages:"
183+
echo -e " ${GREEN}✓${NC} Core dependencies (numpy, pandas, torch, etc.)"
184+
if [ "$PYOPENCL_INSTALLED" = true ]; then
185+
echo -e " ${GREEN}✓${NC} pyopencl (GPU acceleration via OpenCL)"
186+
else
187+
echo -e " ${YELLOW}⚠${NC} pyopencl not installed (CPU fallback available)"
188+
fi
189+
echo ""
158190
echo "GPU Status:"
159191
if [ -e /dev/dri/card0 ]; then
160-
echo -e " ${GREEN}✓${NC} GPU device detected"
161-
echo " To use GPU acceleration: RUSTICL_ENABLE=panfrost python script.py"
162-
echo " (automatically set when activating venv)"
192+
echo -e " ${GREEN}✓${NC} GPU device detected: /dev/dri/card0"
193+
if [ "$PYOPENCL_INSTALLED" = true ]; then
194+
echo -e " ${GREEN}✓${NC} OpenCL GPU acceleration available"
195+
echo " To use GPU: RUSTICL_ENABLE=panfrost python script.py"
196+
echo " (automatically set when activating venv)"
197+
else
198+
echo -e " ${YELLOW}⚠${NC} GPU detected but pyopencl not installed"
199+
echo " Run: source .venv/bin/activate && pip install pyopencl"
200+
fi
163201
else
164-
echo -e " ${YELLOW}⚠${NC} GPU not detected - run 'sudo orangepi-config' to enable"
202+
echo -e " ${YELLOW}⚠${NC} GPU device not detected"
203+
if [[ "$MODEL" == *"OrangePi"* ]]; then
204+
echo " Enable GPU in orangepi-config and reboot"
205+
fi
165206
fi
166207
echo ""
167208
echo "To activate the environment manually:"

0 commit comments

Comments
 (0)