Skip to content

retail_planning: align to predictive skills PR #21 + add registry split - #45

Merged
cafzal merged 7 commits into
mainfrom
retail_planning_pr21_alignment
Apr 24, 2026
Merged

retail_planning: align to predictive skills PR #21 + add registry split#45
cafzal merged 7 commits into
mainfrom
retail_planning_pr21_alignment

Conversation

@cafzal

@cafzal cafzal commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Why

Goal: give users a runnable, adaptable predict-then-optimize example they can actually exercise the predictive reasoners on. Before this PR, retail_planning.py required the full H&M dataset loaded in Snowflake + a GPU engine just to see the pipeline run — most users would never get past setup. This PR adds a zero-external-data local path, aligns both paths to rai-agent-skills PR #21, and reframes the README so users start locally and treat the Snowflake version as the reference for adapting to their own data.

Two non-duplicative entrypoints:

  1. retail_planning_local.py (primary, CPU, no external data). Trains a real sales-regression GNN on a bundled HM_MINI subset (~10K customers / 5K articles / 9.6K transactions), aggregates predictions per article, and runs both optimizers. End-to-end in ~5 min.
  2. retail_planning.py (reference pattern, GPU, full H&M). Trains all three GNNs (sales, churn, purchase) on Kaggle H&M + RelBench task splits. Not intended to be run as-is by most users — it's the worked example for adapting this pipeline to their own Snowflake data.

Changes

Skill alignment (applied to retail_planning.py)

  • pt=ptproperty_transformer=pt; drop deprecated database= / schema= args.
  • Bump sales n_epochs 5 → 20; print target distribution and baseline-mean RMSE before training.
  • temporal_strategy="last" on sales/churn (previously only on purchase).
  • _report(gnn) helper prints gnn.dataset.print_data_config() + optional visualize_dataset(), gated by VERBOSE_DATASET.
  • stream_logs=False default avoids non-TTY spinner flood; seed=42 for reproducibility.
  • Explicit drop=[] for PKs/FKs; integer=[] for new graph-derived features.
  • New Article.popularity_count / Customer.activity_count derived features demonstrating the rai-graph-analysisrai-predictive-* cross-skill pattern.
  • README troubleshooting expanded: regression under-fitting, has_time_column edge-intermediary limitation, non-TTY spinner.

Local entrypoint

  • retail_planning_local.py — real sales-regression GNN on bundled HM_MINI CSVs (CPU) + both optimizers. Self-contained.

Data

  • data/hm_mini/ (new) — HM_MINI customers/articles/transactions + sales task splits, plus 12-article articles_inventory / production_capacity keyed to real HM_MINI IDs.

README (reframed local-first)

  • "What this template is for" names the local runner as the starting point and the full pipeline as the adaptation reference for the user's own Snowflake data.
  • "What's included" surfaces primary (local) vs reference (full) explicitly.
  • Prerequisites splits "to run the local demo" vs "to adapt to your own Snowflake pipeline."
  • Quickstart ends at python retail_planning_local.py; adapting to your own Snowflake data is a separate follow-on section.
  • Expected output now shows the local run's actual numbers.
  • Template-structure block annotates local as primary, full as reference.

Test plan

  • python retail_planning_local.py on bundled HM_MINI CSVs. Ran end-to-end: GNN trained (CPU) in ~1 min, predicted in ~2 min. Markdown MILP → OPTIMAL at $62,096.89. Demand Planning LP → OPTIMAL at $8,985.53. Process exited cleanly.
  • python retail_planning.py on the full Kaggle H&M dataset + GPU engine — not executed in this PR (compute cost). Aligned in code and py_compile passes; meant as an adaptation reference rather than a regression-test target.
  • VERBOSE_DATASET=True run — verify print_data_config() surfaces expected feature types.

Related

…t workflow

Aligns retail_planning.py to the predictive skills from rai-agent-skills PR #21
(rai-predictive-modeling + rai-predictive-training):

- rename pt=pt to property_transformer=pt (SDK alignment)
- drop deprecated database=/schema= args from GNN constructor
- add stream_logs=False (default) to avoid non-TTY spinner flood
- add seed for reproducible training
- bump sales n_epochs from 5 to 20 per regression-tuning guidance;
  add target-distribution profile (min/max/mean/stddev) before training
- add temporal_strategy="last" to sales and churn GNNs
- add _report(gnn) helper for gnn.dataset.print_data_config() and
  gnn.visualize_dataset(), gated by VERBOSE_DATASET
- explicit drop=[] for PK/FK columns in PropertyTransformer
- add graph-derived features (Article.popularity_count,
  Customer.activity_count) demonstrating the cross-skill pattern from
  rai-graph-analysis; surfaced via integer=[] in PropertyTransformer

Adds a split workflow for train-once/optimize-many iteration:

- _retail_setup.py: shared model/graph/PT used by train and optimize
- retail_train.py: trains and registers 3 GNNs to the Snowflake registry
- retail_optimize.py: loads registered GNNs, runs markdown + demand planning
- README: documents both workflows; expands troubleshooting with regression
  under-fitting, has_time_column edge-intermediary limitation, non-TTY
  spinner, and registry access grants

retail_planning.py remains the all-in-one single-script entrypoint for users
who don't need the split.
@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown

The docs preview for this pull request has been deployed to Vercel!

✅ Preview: https://relationalai-docs-qzkpfdccu-relationalai.vercel.app/build/templates
🔍 Inspect: https://vercel.com/relationalai/relationalai-docs/CyMEax7Cra85EpjmxNhGKtUBvm2B

Makes the template runnable without Snowflake or a GPU engine. The new script
runs only the prescriptive phases (markdown MILP + demand planning LP) using
pre-computed predictions from data/predictions_sample.csv. Verified end-to-end
against the sandbox raiconfig.yaml -- Demand Planning converged to OPTIMAL.

The full predict-then-optimize pipeline (with GNN training on H&M) remains
retail_planning.py. The local runner is for quick tours and for regression-
testing the prescriptive logic after changes.

- new: retail_planning_local.py (CSV-only optimizer runner)
- new: data/predictions_sample.csv (stub per-article GNN outputs)
- README: adds local run path to quickstart and template structure
…I CSVs

Goal: users should have two real, working paths through the template.

1. **Lightweight template GNN example with CSV data** -- `retail_planning_local.py`
   loads a small HM_MINI subset (~10K customers / 5K articles / 9.6K transactions)
   from bundled CSVs via `model.data()`, trains a transaction-level
   sales-regression GNN on CPU (~5-10 min), aggregates predictions to per-article
   demand, and runs both prescriptive optimizers. No H&M Snowflake data loading
   and no GPU required. Verified end-to-end against a RAI engine -- Markdown
   MILP OPTIMAL at $62,096.89, Demand Planning LP OPTIMAL at $8,985.53.

2. **Full Snowflake-based workflow** -- `retail_planning.py` (+ the
   `retail_train.py` / `retail_optimize.py` split) trains all three GNNs
   (sales, churn, purchase) on the full Kaggle H&M + RelBench task splits with
   GPU. README now names Kaggle as the dataset source explicitly.

Changes:
- `retail_planning_local.py`: rewritten. Previous version was optimizer-only
  with stub predictions (`predictions_sample.csv`); now trains a real GNN on
  HM_MINI CSVs following the rai-predictive-modeling + training skills.
- `data/hm_mini/` (new): customers, articles, transactions, train/val/test
  sales splits (from HM_MINI), plus 12-article articles_inventory and
  production_capacity CSVs keyed by real HM_MINI article IDs.
- `data/predictions_sample.csv` removed (no longer needed).
- README: Prerequisites section distinguishes local (no external data) vs full
  (Kaggle H&M + RelBench + GPU). Quickstart leads with the local runner.
  Template-structure section documents the new data/hm_mini/ subtree.
…entrypoints

The rai-predictive-training skill already ships register_and_load.py as a
focused example of the registry pattern. Reimplementing it here as a third
entrypoint (retail_train.py + retail_optimize.py + _retail_setup.py)
duplicated ~700 lines of setup code for no additional pedagogical value.

Keep the two non-duplicative paths:
- retail_planning_local.py (zero-setup CPU demo on HM_MINI CSVs)
- retail_planning.py (full Snowflake pipeline on Kaggle H&M + RelBench)

README also:
- Surfaces the Option A / Option B split in Quickstart.
- Flags that step 5 (Snowflake settings) applies to Option B only.
- Updates "What's included" to name the HM_MINI subset.
- Refreshes the "How it works" GNN snippet to the aligned API
  (property_transformer=pt, exp_database/exp_schema, stream_logs, seed,
  temporal_strategy, 20 epochs).
- Rewrites the Pipeline Stages block to reflect that the local runner
  only trains the sales GNN.
cafzal added 2 commits April 23, 2026 14:22
…adaptation reference

The Snowflake + GPU path is unlikely to be what most users exercise first.
Reshape the README so:

- "What this template is for" names retail_planning_local.py as the starting
  point and retail_planning.py as the reference pattern for adapting to the
  user's own Snowflake data.
- "What's included" surfaces the primary vs reference split.
- Prerequisites frames Snowflake + GPU as adaptation requirements, not
  template requirements.
- Quickstart ends at "python retail_planning_local.py". Adapting to your own
  Snowflake data is a separate follow-on section.
- Expected output now reflects the local run's actual numbers
  ($62,096.89 markdown revenue, $8,985.53 demand planning cost).
- Template structure annotates local as primary, full as reference.
…ort sort

- README: remove bullets/blocks recommending specific n_epochs / lr /
  train_batch_size / head_layers values; keep descriptive code samples only.
- retail_planning_local.py: merge duplicate relationalai.semantics import line
  (ruff I001).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@somacdivad somacdivad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@cafzal Thanks!

53892,Jade HW Skinny Denim TRS,32.60,13.00,400,0.18
57700,Pour It Up Push Bra,12.92,5.20,600,0.12
64286,Maggie high support,47.40,19.00,250,0.20
66518,Rose thong 7-pack,20.53,8.20,500,0.12

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LOL

@cafzal
cafzal merged commit 1143085 into main Apr 24, 2026
3 checks passed
@cafzal
cafzal deleted the retail_planning_pr21_alignment branch April 24, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants