Skip to content

[truealpha-factors] Implement safe Qlib expression contract - #194

Merged
wangzitian0 merged 5 commits into
mainfrom
batch/s8-qlib-expression-e0
Jul 14, 2026
Merged

[truealpha-factors] Implement safe Qlib expression contract#194
wangzitian0 merged 5 commits into
mainfrom
batch/s8-qlib-expression-e0

Conversation

@wangzitian0

@wangzitian0 wangzitian0 commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Scope

Implement E0 for #189 over the frozen S8 corpus. This PR accepts experimental code only; it leaves #189 open and approves no product factor, real data, provider, replay, persistence, or release path.

The slice adds:

  • Qlib-independent frozen typed AST, feature-binding, builtin operator-registry, compiled-expression, and execution-binding contracts;
  • deterministic Decimal rendering, content-addressed identities, AST/node/lookback/resource limits, and stale-reference rejection;
  • a compiler that emits canonical Qlib syntax only from approved typed nodes;
  • a runtime adapter with no raw string input, no custom operators, and pinned Qlib 0.9.7 parsing;
  • an independent evaluator that matches actual Qlib output for arithmetic, Ref, Mean, and null behavior on the frozen matrix.

The Gate 0-frozen truealpha_contracts/__init__.py remains unchanged. Provisional callers import the dedicated module directly; public re-export waits for a stable handoff and Gate 0 candidate rebind.

Verification

  • uv sync --project libs/factors/qlib-runtime --all-groups --frozen
  • uv run pytest libs/contracts/tests/test_qlib_expression.py -q (14 passed)
  • uv run --project libs/factors/qlib-runtime pytest libs/factors/tests/batches/qlib_expression_contract_tiny -q (15 passed)
  • targeted Ruff passed
  • uv run mypy passed (95 source files)
  • make issue-graph-check passed
  • pre-rebase fresh-database make check passed (714 passed, 5 skipped); exact rebased head is covered by PR CI

Issue: #189

Copilot AI review requested due to automatic review settings July 14, 2026 13:29
@wangzitian0

Copy link
Copy Markdown
Owner Author

@copilot review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a Qlib-independent, content-addressed typed expression contract and a “safe compiler boundary” that emits canonical Qlib syntax only from approved typed AST nodes, then validates parity against pinned Qlib behavior using the frozen S8 synthetic corpus.

Changes:

  • Add truealpha_contracts.qlib_expression models for typed AST nodes, operator registry, compiled expressions, and execution bindings/evidence (all strict/frozen and content-addressed).
  • Add the S8 tiny runtime compiler/adapter in libs/factors plus a Qlib-parity test suite (including an independent evaluator oracle).
  • Advance S8 batch governance metadata to reflect E0 acceptance and move the batch forward to E1 work.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
libs/contracts/src/truealpha_contracts/qlib_expression.py Defines the Qlib-independent typed AST + operator registry + identity/binding contracts with strict validation and hashing.
libs/contracts/tests/test_qlib_expression.py Validates contract canonicalization, injection resistance, limits, and identity stability against a frozen corpus.
libs/factors/src/factors/batches/qlib_expression_contract_tiny/compiler.py Implements the compiler boundary (typed AST → canonical Qlib field) and execution evidence binding.
libs/factors/src/factors/batches/qlib_expression_contract_tiny/init.py Exposes the S8 compiler/evidence surface for provisional callers without changing the Gate 0 export.
libs/factors/tests/batches/qlib_expression_contract_tiny/test_compiler.py Tests compiler rejection paths, lookback validation, and execution-vs-semantic identity separation.
libs/factors/tests/batches/qlib_expression_contract_tiny/test_qlib_runtime.py Validates oracle parity vs Qlib runtime and ensures Qlib sees only compiler output.
governance/batches/S8-qlib-factor-expression.v1.json Updates batch status/revision and records E0 acceptance state plus acceptance commands.
governance/vision-issue-graph.json Updates the Vision graph batch entry to match the new manifest hash/status/target rung.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libs/factors/tests/batches/qlib_expression_contract_tiny/test_qlib_runtime.py Outdated
Comment thread libs/factors/tests/batches/qlib_expression_contract_tiny/test_qlib_runtime.py Outdated
Comment thread libs/factors/tests/batches/qlib_expression_contract_tiny/test_qlib_runtime.py Outdated
Comment thread libs/factors/tests/batches/qlib_expression_contract_tiny/test_compiler.py Outdated
Comment thread libs/factors/tests/batches/qlib_expression_contract_tiny/test_compiler.py Outdated
Comment thread libs/contracts/tests/test_qlib_expression.py Outdated
Comment thread libs/contracts/tests/test_qlib_expression.py Outdated
@wangzitian0
wangzitian0 force-pushed the batch/s8-qlib-expression-e0 branch from 9ad1972 to d9f90d9 Compare July 14, 2026 13:35
@wangzitian0
wangzitian0 merged commit 462977a into main Jul 14, 2026
11 checks passed
@wangzitian0
wangzitian0 deleted the batch/s8-qlib-expression-e0 branch July 14, 2026 13:39
@wangzitian0 wangzitian0 changed the title [truealpha-data] [S8:E0] Implement safe Qlib expression contract [truealpha-factors] Implement safe Qlib expression contract Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants