Skip to content

Run the templates as deployed models - #111

Open
chriscoey wants to merge 176 commits into
coey/templates-relationalai-2.1from
coey/templates-deploy-mode-2.1
Open

chriscoey wants to merge 176 commits into
coey/templates-relationalai-2.1from
coey/templates-deploy-mode-2.1

Conversation

@chriscoey

@chriscoey chriscoey commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Runs the templates as deployed models on relationalai 2.1.1, in the layout the docs site's deployed-template pages expect. Stacked on #110 (the move to 2.1.1); review that first.

40 templates are converted. Each ran in its new form on Snowflake (transaction_screening_local on DuckDB), and its results are compared under Results with the same template's run in #110. Not converted lists the rest and why.

To read the diff, start with diet for the layout, subscriber_retention for train.py, and any template's README Quickstart for the steps a user follows.

What changed

  • Layout. Each template's model is a model/ package that rai models deploy --path model deploys: schema.py declares the concepts, source.py loads the data, and reasoning.py holds the rules, graph relations and Problem. problem.solve(<solver>, **opts) becomes problem.configure(<solver>, **opts). Each report becomes queries/<name>.py, run as python -m queries.<name>; it imports from model, declares nothing, and only queries the deployed model. The runner script is gone.
  • GNN templates (datacenter_compute_allocation, demand_forecasting, fraud-detection, subscriber_retention, telco_network_recovery) add train.py, run between the deploy and the query: it trains the GNN over the deployed splits and registers the version that raiconfig.yaml names, and a refresh then predicts with it. Values the script derived from the predictions in pandas and fed back into the model are rules over those predictions now, so the Problem reads them in the same refresh. fraud-detection drops its PaySim-table script and keeps the table loader in model/source.py; datacenter_compute_allocation drops the --no-gnn fallback and its CSV.
  • energy_grid_planning no longer loads a GNN. Its script only checked whether a trained model existed and always read demand_forecasts.csv (the Move the templates to relationalai 2.1.1 #110 run prints GNN model not available ... falling back), so the model now reads that file directly and installs without the gnn extra.
  • Status and objective are published through the template's own relationships, for example SolveStatus and TotalCost in diet, defined from problem.termination_status() and problem.objective_value(). The query prints them in place of the solver-detail block from solve_info(). problem.display() is gone, since printing it from a deployed model needs extra rules deployed with the model.
  • Solve guards. Checks that only guarded the solve are removed, and the query prints the status instead. financial_index_replication, test_data_generation and campaign_roi still stop when the solve returns no solution, since their reports export or build on the solved values; entity_resolution and product_configurator report that no solution was returned. problem.verify(...) returns without error on a deployed model even when the check fails, so it is removed; the constraints it checked are unchanged.
  • Checks on solved results stay where the README teaches them, as an explicit raise SystemExit(...) in the query (never assert, which python -O strips): factory_production's plan and sensitivity checks, defect_root_cause's formulation audit, book_slate_recommendation's per-user candidate floor, planogram_optimization's demand re-check and pod_placement's OPTIMAL check. Input-data checks stop rai models deploy.
  • Queries read the deployment. Importing model also loads the local CSVs, so a report that computed figures from them could disagree with the deployed results once the files change. entity_resolution and financial_index_replication now read records, review pairs, returns, benchmark and previous weights from the deployed model.
  • Facts the template wrote from Python values are rules now, so they are part of the deployed model: bom-reachability's assembly depth, it-dependency-mapping's maximum downstream depth, energy_grid_planning's marginal value per added $M and knee point (the level where that marginal value falls the most, $300M as before), and defect_root_cause's baseline failure rate, which now counts distinct units instead of CSV rows.
  • READMEs follow the deployed-template Quickstart. The grants are schema-wide caller grants to the RAI Native App on an internal schema the model role creates before the first deploy. Every template-docs.yaml except portfolio_balancing's (not converted) sets page.deployment: true and includes the README's Prerequisites in the page's lead.
  • Contributor docs (root README, CONTRIBUTING, the template-authoring skill and prompts, sample-template) describe the model/ and queries/ layout.
  • Streamlit apps (disease-outbreak-prevention, humanitarian-aid-supply-chain, wildlife-conservation-network) query the deployed model, including the connection edges they used to read from the CSVs. Their READMEs run them after the deploy step.
  • fraud_detection_rules.ipynb's last cell returns the suspicious users as a query result instead of writing them to a Snowflake table, which writes nothing on a deployed model.

Three templates call model.deploy() instead and then report:

  • transaction_screening_local deploys into DuckDB, where rai models teardown fails on 2.1.1, so it cannot follow the Quickstart's teardown step.
  • simple-start and fraud-detection's fraud_detection_rules.ipynb are notebooks.

Results

Templates
Same results as in #110 ad_spend_allocation, bom-reachability, campaign_roi, cell_tower_coverage, commercial_underwriting, cybersecurity-attack-paths, defect_root_cause, diet, disease-outbreak-prevention, entity_resolution, factory_production, financial_index_replication, fraud-detection's fraud_detection_rules.ipynb, humanitarian-aid-supply-chain, it-dependency-mapping, network_flow_planning, planogram_optimization, product_configurator, production_planning, retail_markdown, shipment_compliance, simple-start, supply_chain_transport, synthetic_eligibility_records, test_data_generation, transaction_screening_local, traveling_salesman, warehouse_allocation, water_allocation
Another equally valid result energy_grid_planning (Louvain finds 3 regions, as its README says, instead of 4; ties among substations and among equal-load paths break differently; the plan is the same), patient_cohort_recruitment, pod_placement (same objective), shift_assignment, synthetic_order_lifecycle, wildlife-conservation-network (same communities, labels 1 and 2 swapped)
Different result book_slate_recommendation: TIME_LIMIT 613 instead of TIME_LIMIT 557; both runs stop at the 180 s limit with the best slate found so far.
A newly trained GNN, so different predictions and plans datacenter_compute_allocation, demand_forecasting, fraud-detection, subscriber_retention, telco_network_recovery (below)

The GNN templates read the same inputs and print the same data summaries as in #110, except that telco_network_recovery counts 7 advisories, one per equipment model as its GNN reads them, where #110 counted the CSV's 8 rows.

  • datacenter_compute_allocation: TIME_LIMIT 653,035,781 instead of 664,676,160, both at the 240 s limit with 16 of 24 scenario cells planned.
  • demand_forecasting: the same splits as Move the templates to relationalai 2.1.1 #110 (test from 2024-11-01), with test RMSE 7.3313 per sale instead of 7.3167, and 153.2 per city, family and week instead of 162.5.
  • fraud-detection, against Move the templates to relationalai 2.1.1 #110's fraud_detection_local.py, whose loader it keeps: 16 audits in 80 of 80 hours as before, capturing $111,827,688 instead of $60,618,861.
  • subscriber_retention: test RMSE 0.1399 instead of 0.1405.
  • telco_network_recovery: 158 towers are critical instead of 142, and the OPTIMAL plan picks 26 upgrades (179 Gbps) instead of 24 (177 Gbps) within the same budget.

Some tables print their rows in a different order, and product_configurator numbers its builds differently.

Not converted

Templates Why
cicd_runner_allocation, demand_planning_temporal, money_laundering_motif_detection, retail_planning, sprint_scheduling, supplier_reliability, supply_chain_resilience, underwriting_audit A relationalai release that fixes a race: independent solves in one deployed model can race to create the solver's reasoner. A cold deploy of money_laundering_motif_detection failed with "engine already exists".
hospital_staffing, portfolio_balancing Their later solves are built in Python from earlier solve results; converting them means declaring every solve in the model.
memory_supply_allocation A deployed GNN cannot use a node concept identified by two fields, here (supplier_id, period_id). Its what-if rules also derive properties of a concept the GNN reads from the GNN's predictions, which fails deploy planning.
smoker_status_prediction Deploying its bundled people.csv (38,984 rows) inline fails with "View definition too large", and a deployed GNN does not find properties whose names contain spaces or parentheses, such as height(cm).

These templates keep their single-script form and run as in #110.

rai-agent-scaffold is removed in #110.

Known limits

  • Checks on solved results run only in the queries. A refresh started another way (a scheduled refresh, or a refresh call in SQL) runs no check, so anything that reads the published results should read the solve status first.
  • An unchanged redeploy applies 10 updates and refreshes again for bom-reachability, book_slate_recommendation, cybersecurity-attack-paths, defect_root_cause, energy_grid_planning, entity_resolution, humanitarian-aid-supply-chain, it-dependency-mapping, patient_cohort_recruitment, synthetic_order_lifecycle, warehouse_allocation and wildlife-conservation-network. datacenter_compute_allocation, fraud-detection, subscriber_retention and telco_network_recovery do the same, and for them that redeploy is the one python train.py runs.
  • cybersecurity-attack-paths and it-dependency-mapping declare a path result as a Relationship, not a Property, because deploying their path results as Properties fails planning on 2.1.1.
  • telco_network_recovery prints the influence load of its top call path (0.009041, as in Move the templates to relationalai 2.1.1 #110) but no longer the route itself. A query on a deployed model cannot enumerate paths that the model does not declare, so the model enumerates them and publishes the path count, the routing-tower count and the top load.
  • fraud-detection and telco_network_recovery keep the scores derived from the GNN's predictions on a separate concept (AuditCandidate, TowerFailureScore) rather than on the concept the GNN reads, because on 2.1.1 such a model fails deploy planning.
  • book_slate_recommendation, datacenter_compute_allocation, defect_root_cause, energy_grid_planning, entity_resolution, fraud-detection, patient_cohort_recruitment, telco_network_recovery and warehouse_allocation print relationalai's [Unsupported Construct Id Type] warning when they deploy and query. Their results are as listed above.
  • simple-start reads its source table as the model role, so that role needs SELECT on the table; the README says so.

The script declares the solve with problem.configure, deploys the model,
waits for the first refresh and prints the report from the deployed
model. Status and objective are read through the model's own
relationships. The README covers the deployment config, the internal
schema grants made before the first run, and re-running.
The solve, with sensitivity analysis, is declared with
problem.configure and runs on each refresh of the deployed model. The
report reads the plan through Product.x_quantity and checks status,
profit, shadow prices, reduced costs and basis status in Python, since
model.require checks are not evaluated on a deployed model.
Graph results the report reads are declared with the model, the script
deploys it and waits for the first refresh, and the report reads the
deployed model. Assembly depth is computed from the enumerated paths
and printed; it is no longer written back onto SKU, since a rule
defined after the deploy is not part of the deployed model.
Define SKU.assembly_depth at module level as the longest assembly chain
ending at each finished good, so it deploys with the model and stays
queryable after the run. Restores the README and runbook text that
describes the persisted property.
The shadow-price and reduced-cost checks compare the returned key sets
with the expected factories and products, so a missing or duplicated
row fails instead of passing a row count.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads status and objective through the
model's own relationships and the allocation through Allocation.x_spend.
The README covers the deployment config, the internal schema grants made
before the first run, and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads status and total conversions through
the model's own relationships. The README covers the deployment config,
the internal schema grants made before the first run, and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads status and total cost through the
model's own relationships. The README covers the deployment config, the
internal schema grants made before the first run, and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads status and objective through the
model's own relationships and the plan through Production.x_quantity. The
README covers the deployment config, the internal schema grants made
before the first run, and re-running, and its expected output drops the
solver-detail lines the script no longer prints.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads status and total revenue through the
model's own relationships and the schedules through the template's own
variable properties. The README covers the deployment config, the
internal schema grants made before the first run, and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads status and total cost through the
model's own relationships and the plan through the template's own
variable properties. The README covers the deployment config, the
internal schema grants made before the first run, and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads status and objective through the
model's own relationships and keeps the demand-table lookup check. The
problem.verify call is removed; the constraints are unchanged. The README
covers the deployment config, the internal schema grants and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads status and objective through the
model's own relationships and keeps the OPTIMAL check. The problem.verify
call is removed; the constraints are unchanged. The README covers the
deployment config, the internal schema grants and re-running.
The solve, with solution_limit for enumeration, is declared with
problem.configure and runs on each refresh of the deployed model. The
report keeps the per-solution reads and the empty-result branch, and
prints the status and number of builds. The problem.verify call is
removed; the constraints are unchanged. The README covers the deployment
config, the internal schema grants and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The report reads the status through the model's own
relationship and keeps the OPTIMAL check. The problem.verify call is
removed; the constraints are unchanged. The README covers the deployment
config, the internal schema grants and re-running.
The solve, with solution_limit for enumeration, is declared with
problem.configure and runs on each refresh of the deployed model. The
report keeps the per-solution reads (populate=False) and the empty-result
branch, and prints the status and number of records. The README covers
the deployment config, the internal schema grants and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. The derived event type is declared with
model.Relationship at module level so it deploys with the model, and the
report reads status through the model's own relationship and keeps the
OPTIMAL check. The problem.verify call is removed; the constraints are
unchanged. The README covers the deployment config and the internal
schema grants.
The script deploys the model, waits for the first refresh and prints the
report from the deployed model. The README covers the deployment config and
re-running.
The script deploys the model, waits for the first refresh and prints the
report from the deployed model. The README covers the deployment config and
re-running.
The runner deploys the model, waits for the first refresh and prints the item
from the deployed model. The README covers the deployment config, re-running,
and where a template declares its reasoning relative to the deploy.
The graph, rules and reinsurance solve are declared with the model and run on
each refresh of the deployed model; the report reads the cession plan from the
deployed model. The solve status is published through a relationship, and the
README and docs sidecar cover the deployment config and the configured solve.
The script deploys the model, waits for the first refresh and prints the
report from the deployed model. Asset.on_attack_path is now a rule over the
kill-chain paths, declared as a Relationship because a Property defined from
a path rule fails deployment planning. The README covers the deployment
config.
The script deploys the model, waits for the first refresh and prints the
report from the deployed model. Feature.max_downstream_depth is declared as
a Relationship because a Property defined from a path rule fails deployment
planning. The README covers the deployment config.
The script calls model.deploy() on the in-memory DuckDB database before the
report queries, which now run under __main__. The config drops auto_deploy,
so a query never deploys; the README's How it works and troubleshooting
text follow.
Each runner deploys the shared model name with its own motif Problem and
reports from it; status comes from a per-runner SolveStatus relationship
and the solution count from solve_info().num_points. The README says that
running another runner redeploys and replaces the previous runner's motif.
The notebook declares the concepts, the connections relationship, the graph
and its betweenness centrality first, then deploys in one model.deploy()
cell, then runs the query cells. The note about waiting for the initial
sync is gone: the deploy waits for the first refresh. The README covers
the deployment config and the model role's read access to the source table.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. Status and objective are read through the model's own
relationships, and the script keeps accepting OPTIMAL or TIME_LIMIT. The
README covers the deployment config, the internal schema grants and
re-running; the docs sidecar anchors follow the configure call.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. Status and covered population are read through the
model's own relationships, and the script keeps accepting OPTIMAL or
TIME_LIMIT. The README covers the deployment config, the internal schema
grants and re-running.
The solve is declared with problem.configure and runs on each refresh of
the deployed model. Status and total deviation are read through the
model's own relationships, and the model.require status check becomes a
Python check in the report. problem.display() is installed with the
model. The README covers the deployment config, the internal schema
grants and re-running.
entity_resolution and financial_index_replication name their Problem, so
the page anchors match the named constructor. fraud-detection's README
now has the deployment Quickstart with a train step, which its page
renders only with page.deployment set.
financial_index_replication, test_data_generation and campaign_roi stop
when the solve returns no solution instead of exporting, generating
from, or dividing by values that do not exist. energy_grid_planning and
datacenter_compute_allocation give per-portfolio and per-cell totals a
zero default, so a portfolio or cell with no rows in one category keeps
its other results. demand_forecasting reads its split dates from the
deployed model. Correct the telco runbook's score bridge, the fraud
README's setup reference, and outdated comments and README text.
The template pages render only the README lead sections and the generated
Quickstart, so the deployed templates' Prerequisites section never appeared
while their Quickstart pointed to it. List it in the lead for every deployed
template and in the authoring guide.

Also align telco's README, model docstring and runbook with the published
outputs, drop diet's stale solver-details wording, and correct a report
comment in energy_grid_planning.
The deployed model publishes the path count, the routing-tower count and
the top influence load, so the prompt asks for those.
The marginal value per added $M and the knee flag are model properties
again, derived from the solved portfolio rows, so they can be queried
from the deployed model. The knee is the level where the marginal value
falls the most. The report reads both instead of computing them.
…olution

entity_resolution printed a zero cession plan when the solve returned no
solution; it now says there is no plan. product_configurator said no
feasible build exists whatever the status; it now says the solver found
no build and points to the printed status.
…tier

The knee is the level where the marginal value falls the most, with ties
going to the smaller budget; a frontier whose marginal value never falls
has no knee, and the report says so.
@chriscoey
chriscoey requested a balanced review from Copilot November 15, 2026 01:51
@chriscoey
chriscoey marked this pull request as ready for review November 15, 2026 01:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The seven-step contract omits the training-and-refresh variant required by the converted GNN templates, leaving authors without instructions needed to produce predictions before querying.

1 open issue

Review effort: Balanced

GNN templates train between deploy and query, which the docs site's
Quickstart extractor already accepts as an eighth step.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The cross-template deployment and GNN migration relies on connected Snowflake/RelationalAI runtime behavior, including refresh ordering and deployment lifecycle, that cannot be independently verified from this source snapshot.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

The model now publishes each factory capacity's shadow price and each product's reduced cost and
basis status as relationships, so the report selects them instead of reading the solver's
constraint and variable objects.
The model now publishes the options each solution selects as a relationship, so the report
selects it instead of reading the solver's per-solution variable values.
The model now publishes each solution's age bucket, plan, and provider as one relationship, so
the report selects it instead of reading the solver's per-solution variable values.
The model now defines the match graph's node and edge counts into relationships of its own, so
the report selects them instead of reading the graph library's results.
…odel

The model now attaches the community, degree centrality, and degree results to Organization, so
the queries select published properties instead of reading the graph library's results.
The model now attaches the degree centrality and incoming and outgoing edge counts to Facility, so
the queries select published properties instead of reading the graph library's results.
…odel

The model now attaches PageRank, degree centrality, and in- and out-degree to DistributionPoint,
so the queries select published properties instead of reading the graph library's results.
…gh the model

The model now defines the lot genealogy graph's node and edge counts and the diagnosis problem's
variable, constraint, objective, and coverage-constraint counts into relationships of its own,
so the report selects them instead of reading the graph and solver libraries' results.
The model now publishes each corridor's substations in hop order as a relationship, so the report
selects it instead of reading the path search's results.
…h the model

The model now attaches reachability and betweenness to SKU, defines the graph's node and edge
counts into relationships of its own, and publishes each assembly chain's steps as a
relationship, so the report selects them instead of reading the graph and path results.
The model now publishes each kill chain's assets, hops, and total exposure, and each
entry-to-target route's assets, as relationships, so the report selects them instead of reading
the path search's results.
The model now publishes each dependency path's features in order and each feature's count of
downstream paths, so the report selects them instead of reading the path search's results.
The model now defines each site's weakly connected component into a relationship of its own, so
the report selects it instead of reading the graph library's result.

This branch has not been deployed

No deployments
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