gaurv007 commited on
Commit
1f8ffc4
Β·
verified Β·
1 Parent(s): 8eafc02

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -42
README.md CHANGED
@@ -26,10 +26,12 @@ The pipeline runs:
26
  3. **Static lint** β€” validates BRAIN syntax (operator arity, look-ahead, parentheses)
27
  4. **Deduplication** β€” SHA256 hash to avoid duplicates
28
  5. **Store** β€” persists to DuckDB for review
29
- 6. **Crowd Scout** β€” novelty assessment (LLM or heuristic)
30
- 7. **Performance Surgeon** β€” diagnoses weak alphas, suggests mutations
31
- 8. **Gatekeeper** β€” final go/no-go (LLM)
32
  9. **BRAIN submission** β€” live submission (requires `BRAIN_SESSION_TOKEN`)
 
 
33
 
34
  ## Quick Start
35
 
@@ -81,8 +83,8 @@ BRAIN uses **session-based authentication** (browser cookies), not API keys. The
81
  ## Architecture
82
 
83
  ```
84
- Theme Sampler β†’ Expression Generation β†’ Static Lint β†’ Dedup β†’ Store
85
- ↓ (Templates or LLM) ↓ ↓
86
  Crowd Scout β†’ Performance Surgeon β†’ Gatekeeper β†’ BRAIN Submit
87
  ↓ (iteration queue)
88
  Winner Memory ← Mutator ← Performance Surgeon
@@ -100,8 +102,8 @@ Winner Memory ← Mutator ← Performance Surgeon
100
  | `performance_surgeon.py` | Diagnose failures, suggest mutations | βœ… Working |
101
  | `gatekeeper.py` | Final go/no-go memo | βœ… Working |
102
  | `wq_client.py` | BRAIN API submission | ⚠️ Needs `BRAIN_SESSION_TOKEN` |
103
- | `brain_sim.py` | Local numpy backtest | ⚠️ Not wired to pipeline |
104
- | `regime_tagger.py` | Vol/trend/rate/style regimes | ⚠️ Not wired to pipeline |
105
 
106
  ## Key Features
107
 
@@ -113,16 +115,16 @@ Winner Memory ← Mutator ← Performance Surgeon
113
  - **Winner memory**: Tracks which field/archetype combinations work, feeds back to generation.
114
  - **Expression mutator**: Auto-generates decay, horizon, neutralization, and sign-flip variants.
115
  - **DuckDB store**: Persistent history of all alphas, metrics, and verdicts.
116
- - **Retry logic**: LLM client retries transient failures (429, 502, 503, 504, timeout) with exponential backoff.
 
117
 
118
  ## Known Limitations
119
 
120
  1. **BRAIN auth is session-based**: Token expires. No automatic refresh. You must re-copy from browser.
121
- 2. **Local simulation is not wired**: `brain_sim.py` exists but is not integrated into the pipeline. It needs price data (yfinance) and produces approximate results.
122
- 3. **Regime tagger not wired**: `regime_tagger.py` exists but is not used by the Performance Surgeon.
123
- 4. **LLM generation can hallucinate fields**: Static lint catches most errors, but field names from LLMs may not exist on BRAIN.
124
- 5. **Weights inside `rank()` are decorative**: `rank(0.6*a + 0.4*b)` is monotonic β€” coefficients don't linearly combine. The signal comes from which fields are combined.
125
- 6. **Not a guarantee of profitable alphas**: This generates candidates. BRAIN's simulation is the ground truth.
126
 
127
  ## Configuration
128
 
@@ -154,7 +156,7 @@ python -m alpha_factory.run --proven --batch-size 10 --enable-brain
154
  ```
155
  alpha_factory/
156
  β”œβ”€β”€ config.py # All settings (Pydantic v2)
157
- β”œβ”€β”€ run.py # Entry point
158
  β”œβ”€β”€ schemas/ # Typed Pydantic contracts
159
  β”œβ”€β”€ deterministic/
160
  β”‚ β”œβ”€β”€ lint.py # Static pre-flight (Layer 2)
@@ -162,23 +164,25 @@ alpha_factory/
162
  β”‚ β”œβ”€β”€ fitness.py # Composite scoring
163
  β”‚ β”œβ”€β”€ proven_templates.py # Deterministic generation
164
  β”‚ β”œβ”€β”€ expression_mutator.py # Evolutionary variants
165
- β”‚ └── regime_tagger.py # Vol/trend/rate/style regimes (not wired)
 
 
166
  β”œβ”€β”€ infra/
167
  β”‚ β”œβ”€β”€ model_manager.py # Ollama + HF auto-detection
168
  β”‚ β”œβ”€β”€ llm_client.py # Unified LLM interface (token budget + retry)
169
- β”‚ β”œβ”€β”€ factor_store.py # DuckDB persistence
170
- β”‚ β”œβ”€β”€ wq_client.py # BRAIN API wrapper (session auth)
171
  β”‚ └── winner_memory.py # Feedback loop
172
  β”œβ”€β”€ local/
173
- β”‚ └── brain_sim.py # Local BRAIN simulator (not wired)
174
  β”œβ”€β”€ personas/
175
- β”‚ β”œβ”€β”€ hypothesis_hunter.py # Persona 1
176
- β”‚ β”œβ”€β”€ expression_compiler.py # Persona 2
177
- β”‚ β”œβ”€β”€ crowd_scout.py # Persona 4
178
- β”‚ β”œβ”€β”€ performance_surgeon.py # Persona 5
179
- β”‚ └── gatekeeper.py # Persona 6
180
  └── orchestration/
181
- └── pipeline.py # Full DAG
182
  ```
183
 
184
  ## Changelog v0.2.0
@@ -191,16 +195,29 @@ alpha_factory/
191
  - **Fixed**: Expression compiler sign logic β€” now per-component, no global blind negation
192
  - **Fixed**: LLM client stops error amplification (no more 3x API calls on auth/network failures)
193
  - **Fixed**: LLM client enforces token budget (was declared but never checked)
194
- - **Fixed**: LLM client adds retry logic with exponential backoff for transient failures (429, 502, 503, 504, timeout)
195
- - **Fixed**: Removed dead `enable_local_sim` config field and `--local-sim` CLI flag (local sim exists but is not wired)
 
 
 
 
 
 
 
 
 
 
 
196
  - **Fixed**: Removed orphan `rag.py` (arXiv retrieval not wired, will be re-added when integrated)
197
- - **Fixed**: Added missing `local/__init__.py` for proper package structure
198
- - **Fixed**: Added GitHub Actions CI workflow (`.github/workflows/ci.yml`)
199
  - **New**: Proven template mode (`--proven`) generates expressions without any LLM
200
  - **New**: Winner memory integration in pipeline (records winners/failures/iterations)
201
  - **New**: Expression mutator integration (auto-generates decay/horizon/group/sign variants)
 
202
  - **New**: Parallel batch processing with `max_parallel_candidates` semaphore
203
- - **New**: 32 comprehensive tests covering templates, lint, mutations, config, fitness, fields, groups
 
204
  - **Updated**: Honest README that accurately describes what works and what doesn't
205
 
206
  ## License
@@ -210,19 +227,7 @@ MIT β€” use at your own risk. This is not financial advice. BRAIN simulations ar
210
  <!-- ml-intern-provenance -->
211
  ## Generated by ML Intern
212
 
213
- This model repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.
214
 
215
  - Try ML Intern: https://smolagents-ml-intern.hf.space
216
  - Source code: https://github.com/huggingface/ml-intern
217
-
218
- ## Usage
219
-
220
- ```python
221
- from transformers import AutoModelForCausalLM, AutoTokenizer
222
-
223
- model_id = 'gaurv007/alpha-factory'
224
- tokenizer = AutoTokenizer.from_pretrained(model_id)
225
- model = AutoModelForCausalLM.from_pretrained(model_id)
226
- ```
227
-
228
- For non-causal architectures, replace `AutoModelForCausalLM` with the appropriate `AutoModel` class.
 
26
  3. **Static lint** β€” validates BRAIN syntax (operator arity, look-ahead, parentheses)
27
  4. **Deduplication** β€” SHA256 hash to avoid duplicates
28
  5. **Store** β€” persists to DuckDB for review
29
+ 6. **Local sim** β€” lightweight numpy backtest as triage (lenient thresholds, never blocks)
30
+ 7. **Acceptance checklist** β€” 14-point pre-submission gate
31
+ 8. **Crowd Scout** β€” novelty assessment (LLM or heuristic)
32
  9. **BRAIN submission** β€” live submission (requires `BRAIN_SESSION_TOKEN`)
33
+ 10. **Performance Surgeon** β€” diagnoses weak alphas, suggests mutations
34
+ 11. **Gatekeeper** β€” final go/no-go (LLM)
35
 
36
  ## Quick Start
37
 
 
83
  ## Architecture
84
 
85
  ```
86
+ Theme Sampler β†’ Expression Generation β†’ Static Lint β†’ Dedup β†’ Store β†’ Local Sim β†’ Checklist
87
+ ↓ (Templates or LLM) ↓ ↓ ↓ ↓
88
  Crowd Scout β†’ Performance Surgeon β†’ Gatekeeper β†’ BRAIN Submit
89
  ↓ (iteration queue)
90
  Winner Memory ← Mutator ← Performance Surgeon
 
102
  | `performance_surgeon.py` | Diagnose failures, suggest mutations | βœ… Working |
103
  | `gatekeeper.py` | Final go/no-go memo | βœ… Working |
104
  | `wq_client.py` | BRAIN API submission | ⚠️ Needs `BRAIN_SESSION_TOKEN` |
105
+ | `brain_sim.py` | Local numpy backtest (triage, lenient) | βœ… Wired (never blocks) |
106
+ | `regime_tagger.py` | Vol/trend/rate/style regimes | βœ… Wired via Performance Surgeon |
107
 
108
  ## Key Features
109
 
 
115
  - **Winner memory**: Tracks which field/archetype combinations work, feeds back to generation.
116
  - **Expression mutator**: Auto-generates decay, horizon, neutralization, and sign-flip variants.
117
  - **DuckDB store**: Persistent history of all alphas, metrics, and verdicts.
118
+ - **Retry logic**: LLM client retries transient failures (429, 502, 503, 504, timeout) with exponential backoff. Non-retryable errors (401, 400, OOM) abort immediately.
119
+ - **Unified pipeline**: Both proven and LLM paths flow through `_process_candidate()` β€” no code duplication.
120
 
121
  ## Known Limitations
122
 
123
  1. **BRAIN auth is session-based**: Token expires. No automatic refresh. You must re-copy from browser.
124
+ 2. **Local simulation is triage-only**: `brain_sim.py` runs with lenient thresholds (min_sharpe=0.3) and prints warnings but **never blocks** a candidate. It's for sanity checking, not filtering.
125
+ 3. **LLM generation can hallucinate fields**: Static lint catches most errors, but field names from LLMs may not exist on BRAIN.
126
+ 4. **Weights inside `rank()` are decorative**: `rank(0.6*a + 0.4*b)` is monotonic β€” coefficients don't linearly combine. The signal comes from which fields are combined.
127
+ 5. **Not a guarantee of profitable alphas**: This generates candidates. BRAIN's simulation is the ground truth.
 
128
 
129
  ## Configuration
130
 
 
156
  ```
157
  alpha_factory/
158
  β”œβ”€β”€ config.py # All settings (Pydantic v2)
159
+ β”œβ”€β”€ run.py # Entry point (single asyncio.run)
160
  β”œβ”€β”€ schemas/ # Typed Pydantic contracts
161
  β”œβ”€β”€ deterministic/
162
  β”‚ β”œβ”€β”€ lint.py # Static pre-flight (Layer 2)
 
164
  β”‚ β”œβ”€β”€ fitness.py # Composite scoring
165
  β”‚ β”œβ”€β”€ proven_templates.py # Deterministic generation
166
  β”‚ β”œβ”€β”€ expression_mutator.py # Evolutionary variants
167
+ β”‚ β”œβ”€β”€ acceptance_checklist.py # 14-point pre-submission gate
168
+ β”‚ β”œβ”€β”€ brain_sim.py # Local numpy backtest (triage)
169
+ β”‚ └── regime_tagger.py # IQR-based regime detection
170
  β”œβ”€β”€ infra/
171
  β”‚ β”œβ”€β”€ model_manager.py # Ollama + HF auto-detection
172
  β”‚ β”œβ”€β”€ llm_client.py # Unified LLM interface (token budget + retry)
173
+ β”‚ β”œβ”€β”€ factor_store.py # DuckDB persistence (parameterized SQL)
174
+ β”‚ β”œβ”€β”€ wq_client.py # BRAIN API wrapper (session auth, circuit breaker)
175
  β”‚ └── winner_memory.py # Feedback loop
176
  β”œβ”€β”€ local/
177
+ β”‚ └── brain_sim.py # (identical, part of deterministic)
178
  β”œβ”€β”€ personas/
179
+ β”‚ β”œβ”€β”€ hypothesis_hunter.py # Persona 1 (LLM)
180
+ β”‚ β”œβ”€β”€ expression_compiler.py # Persona 2 (templates + LLM fallback)
181
+ β”‚ β”œβ”€β”€ crowd_scout.py # Persona 4 (heuristic + LLM)
182
+ β”‚ β”œβ”€β”€ performance_surgeon.py # Persona 5 (heuristic + LLM)
183
+ β”‚ └── gatekeeper.py # Persona 6 (LLM)
184
  └── orchestration/
185
+ └── pipeline.py # Full DAG (unified _process_candidate)
186
  ```
187
 
188
  ## Changelog v0.2.0
 
195
  - **Fixed**: Expression compiler sign logic β€” now per-component, no global blind negation
196
  - **Fixed**: LLM client stops error amplification (no more 3x API calls on auth/network failures)
197
  - **Fixed**: LLM client enforces token budget (was declared but never checked)
198
+ - **Fixed**: LLM client adds retry logic with exponential backoff for transient failures
199
+ - **Fixed**: LLM client JSON parsing regex no longer strips all whitespace (was mangling responses)
200
+ - **Fixed**: `pipeline.py` `NameError: max_corr` β€” correlation is now computed before checklist call
201
+ - **Fixed**: `pipeline.py` `_submit_or_dryrun` reuses `self.brain` instead of creating new clients
202
+ - **Fixed**: `run.py` uses single `asyncio.run()` β€” no more session leak
203
+ - **Fixed**: `acceptance_checklist.py` RETURNS-CORR check no longer always fails (lowered from 0.05 to 0.95)
204
+ - **Fixed**: `factor_store.py` uses DuckDB transaction context manager instead of string-based BEGIN/COMMIT
205
+ - **Fixed**: `ui.py` SQL uses parameterized LIMIT instead of f-string injection
206
+ - **Fixed**: `expression_compiler.py` `_validate_expression` is now called, issues logged
207
+ - **Fixed**: `expression_mutator.py` regex now handles uppercase field IDs (e.g., `mdl77_2GlobalDev...`)
208
+ - **Fixed**: `proven_templates.py` decay parameter is now passed through (was hardcoded to 5)
209
+ - **Fixed**: `theme_sampler.py` `pick_theme()` has alive-theme fallback when all themes exhausted
210
+ - **Fixed**: Removed dead `enable_local_sim` config field and `--local-sim` CLI flag
211
  - **Fixed**: Removed orphan `rag.py` (arXiv retrieval not wired, will be re-added when integrated)
212
+ - **Fixed**: Added missing `local/__init__.py` and `orchestration/__init__.py`
213
+ - **Fixed**: `pyproject.toml` version bumped to 0.2.0, removed unused `scipy` dependency
214
  - **New**: Proven template mode (`--proven`) generates expressions without any LLM
215
  - **New**: Winner memory integration in pipeline (records winners/failures/iterations)
216
  - **New**: Expression mutator integration (auto-generates decay/horizon/group/sign variants)
217
+ - **New**: Acceptance checklist (14 checks, wired before BRAIN submission)
218
  - **New**: Parallel batch processing with `max_parallel_candidates` semaphore
219
+ - **New**: 64+ comprehensive tests covering templates, lint, mutations, config, fitness, fields, groups
220
+ - **New**: `_process_candidate()` unified path β€” both proven and LLM candidates flow through same pipeline
221
  - **Updated**: Honest README that accurately describes what works and what doesn't
222
 
223
  ## License
 
227
  <!-- ml-intern-provenance -->
228
  ## Generated by ML Intern
229
 
230
+ This repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.
231
 
232
  - Try ML Intern: https://smolagents-ml-intern.hf.space
233
  - Source code: https://github.com/huggingface/ml-intern