Skip to content

[GGGP M2] Archimedes strategy_spec Target adapter (first DSL) #3

Description

@mnemonik-dev

Summary

Milestone M2: the first concrete Target — the Archimedes strategy_spec DSL — used to prove the
whole pipeline against a real validity oracle. Implements the DSL grammar (BNF), the derivation→spec
builder, semantic repair, a Rust validity check mirroring validate_strategy_spec, and the
enum-conformance guard (D6) so the grammar can't drift from strategy_dsl.py. Fitness is
synthetic/Rust in this phase (the real backtrader + rigor-gate fitness arrives with the later
Python-bridge phase, D7).

Spec: https://github.com/mnemonik-dev/genetic_algorithms/blob/main/docs/technical-reference/gggp-implementation-spec.md (§5)
DSL source of truth: Archimedes backend/archimedes/services/strategy_dsl.py. BNF: gggp-grammar-tech-review.md §3.

Scope

  • src/targets/archimedes.rs implementing Target:
    • grammar() — the DSL CFG: indicators {sma,ema,rsi,realized_vol,momentum}, cmp {gt,lt,gte,lte},
      logic {and,or,not}, rebalance {daily,weekly,monthly}, sizing
      {full_invested_when_in_market, equal_weight, inverse_vol, volatility_target}, price operands,
      period Int[1,10000], annual_pct Float(0,1], tickers via FromSet.
    • build() — derivation → exact strategy_spec JSON; inject source_arxiv_ids from
      GrammarConfig.metadata (provenance carried, not searched); set look_ahead_safe = true.
    • repair() — clamp period→[1,10000], ensure ≥1 asset, annual_pct>0, parameter_variants len∈[2,8], dedupe.
    • validate() — Rust port of the structural checks in validate_strategy_spec.
  • examples/evolve_faber.rs — evolve with the Archimedes target + a synthetic fitness.
  • Tests: validity-invariant, mapping-roundtrip (Faber), repair, enum-conformance.

Acceptance criteria

  • cargo test -p evoforge-grammar0 failed.
  • Validity invariant: 5_000 random + 5_000 evolved genomes → every built artifact passes
    ArchimedesTarget::validate (100%, 0 failures).
  • Mapping roundtrip: hand-written codons reproduce FABER_2007_SPEC exactly.
  • Repair: injected out-of-bounds period / empty asset_universe / annual_pct<=0 are repaired
    to specs that then validate.
  • Enum conformance: a test asserts the grammar's terminal sets equal the DSL's frozensets
    (INDICATOR_NAMES, COMPARISON_OPS, LOGIC_OPS, REBALANCE_FREQUENCIES, POSITION_SIZING_TYPES).
    The expected values are pinned in the test (with a comment pointing at strategy_dsl.py); the test
    fails if the grammar diverges. (Since Python isn't imported here, the DSL values are mirrored as
    constants — divergence from the real file is caught at review against the cited source.)
  • Convergence on the synthetic fitness; cargo fmt --check + clippy -D warnings clean.

Verify

cargo test -p evoforge-grammar
cargo run -p evoforge-grammar --example evolve_faber

Anti-goals (do NOT)

  • Do not call Python or import the real backtest/rigor gate (D7 → later phase); fitness is synthetic.
  • Do not widen the DSL's indicator/operator set (that touches the live Archimedes interpreter — separate, review-gated change).
  • Do not add NSGA-II (D5), one-point crossover (D2 → M3), resume (D4), or PyO3 (D7).
  • Do not modify evoforge core or strategy_dsl.py.

Notes

Depends on M1 (#2). After this, the GE pipeline is end-to-end provable in pure Rust; M3 (operators)
and M4 (release) follow, then the separate Python-bridge phase wires the real Archimedes fitness.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions