Skip to content

Update v1 templates for PyRel PR #730 API changes#28

Merged
chriscoey merged 16 commits intomainfrom
update-v1-pr730-api-changes
Mar 27, 2026
Merged

Update v1 templates for PyRel PR #730 API changes#28
chriscoey merged 16 commits intomainfrom
update-v1-pr730-api-changes

Conversation

@chriscoey
Copy link
Copy Markdown
Member

@chriscoey chriscoey commented Mar 19, 2026

Summary

  • Migrates all 22 prescriptive templates to the new result accessor API from PyRel PR #730 (available in PyRel v1.0.6)
  • Adds engine-side model.require() ICs for solve status validation — avoids querying data to the client
  • Adds p.verify() constraint checking pattern to shift_assignment
  • Fixes demand_planning_temporal README {{name:float}}{Float:name} Property syntax

API migration (all 22 templates)

Before After
p.display_solve_info() p.solve_info().display()
p.termination_status (property) p.termination_status() (Relationship)
p.objective_value (property) p.objective_value() (Relationship)
{{name:float}} Property shorthand {Float:name} PyRel type syntax

Pattern diversity across templates

Pattern Templates
IC-heavy (structural checks + solution validation + .inspect()) diet, network_flow, traveling_salesman, production_planning
IC + solve_info() (termination IC + Python-side formatted output) 11 templates (hospital_staffing, machine_maintenance, etc.)
IC + solve_info() + .inspect() (single solve) ad_spend_allocation, portfolio_balancing, grid_interconnection
p.verify() (post-solve constraint checking) shift_assignment
solve_info() in scenario loops (need Python scalars per iteration) factory_production, supplier_reliability, demand_planning_temporal, sprint_scheduling

Additional changes

  • Scenario-loop templates now guard against None objective_value on non-OPTIMAL solves
  • Display-only .to_df() + print replaced with .inspect() in 7 templates

Test plan

🤖 Generated with Claude Code

Copy link
Copy Markdown
Collaborator

@cafzal cafzal left a comment

Choose a reason for hiding this comment

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

looks good, thanks. we should wait to merge until the new release and update minimum version guidance

@chriscoey
Copy link
Copy Markdown
Member Author

new release is v1.0.6 and was released today

@chriscoey
Copy link
Copy Markdown
Member Author

The preview CI failure is unrelated to this PR's changes — it's a credentials issue.

The workflow checks out relationalai/relationalai-docs using the DOCS_REPO_TOKEN secret, which is returning "Bad credentials". The job retries three times and then fails:

Retrieving the default branch name
Bad credentials - https://docs.github.com/rest
Waiting 15 seconds before trying again
...
##[error]Bad credentials - https://docs.github.com/rest

The DOCS_REPO_TOKEN repo secret likely needs to be rotated by a repo admin. This would affect any PR on this repo, not just this one.

@somacdivad
Copy link
Copy Markdown
Collaborator

@chriscoey I'm looking in to the credentials issue

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

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

✅ Preview: https://relationalai-docs-7g5f4k4lj-relationalai.vercel.app/early-access/pyrel/templates
🔍 Inspect: https://vercel.com/relationalai/relationalai-docs/FgQrSePWRb2HRNoth2eCLAZmxn6z

Copy link
Copy Markdown
Collaborator

@somacdivad somacdivad left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @chriscoey. I got the preview working again and everything passes there. My one concern is that the README files may need to be updated so that any code changes made here are reflected in any code shown in the READMEs.

Early feedback I got about templates indicated that people want to see some code on the website, but I'm thinking about removing raw code blocks from the READMEs because of the maintenance annoyance.

I haven't settled on a solution yet, though, so I think that for now we just need to keep the README's in sync. There's a prompt in .github/prompts that I've used in the past to easily sync READMEs with an agent.

I'll work on a solution for showing code on the website without having to keep anything in sync so future updates are easier.

chriscoey and others added 2 commits March 23, 2026 16:19
Migrate all 22 prescriptive templates to the new result accessor API:
- p.display_solve_info() → p.solve_info().display()
- p.termination_status/p.objective_value properties → p.termination_status()/p.objective_value() Relationships
- Add model.require(p.termination_status() == "OPTIMAL") engine-side ICs to 18 templates
- Add structural ICs (num_variables, num_objectives) to network_flow and traveling_salesman
- Add p.verify() constraint checking to shift_assignment (MiniZinc)
- Replace display-only .to_df()+print with .inspect() in 7 templates
- Guard loop-based scenario templates against None objective_value
- Fix pre-existing NameError in grid_interconnection (build_formulation)

Tested: 20/21 templates pass locally (demand_planning_temporal has pre-existing type issue).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update code snippet to match the {Type:name} syntax used in the .py file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chriscoey chriscoey force-pushed the update-v1-pr730-api-changes branch from f4361ed to bc76267 Compare March 23, 2026 23:46
@chriscoey
Copy link
Copy Markdown
Member Author

Rebased onto main (picking up PR #29's scenario restructuring), resolved conflicts in grid_interconnection, demand_planning_temporal, and sprint_scheduling.

All 22 templates (21 HiGHS + 1 MiniZinc) run successfully against PyRel v1.0.6 after the rebase.

chriscoey and others added 11 commits March 24, 2026 12:21
Update code blocks and expected output in 4 template READMEs to
reflect the solve_info() API migration and scenario restructuring:

- grid_interconnection: scenario loop → single solve with
  scenario-indexed variables; all code blocks updated
- demand_planning_temporal: scenario loop added for planning_end
  sweep; date filtering/period mapping sections updated
- sprint_scheduling: capacity_multiplier scenario loop added;
  named constraint variables; expected output updated
- shift_assignment: constraints extracted to named variables
  (coverage_ic, workload_ic); p.verify() documented

The remaining 15 templates' READMEs don't show any code that was
changed (solve_info, .inspect patterns), so no update is needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sections 3-5 referenced `s.solve_for()`, `s.satisfy()`, `s.minimize()`
but the code uses `p = Problem(...)`. Fixed to match.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- sprint_scheduling: fix scenario order (0.5, 0.75, 1.0 not reversed)
- machine_maintenance: fix s. → p. in solve/verify code block
- shift_assignment: fix s.solve/minimize refs in prose, add solve+verify
  code block, update infeasibility docs for single-solve approach
- demand_planning: fix expected output format (status/cost on separate
  lines), add planning_end= prefix to summary
- grid_interconnection: add explanatory prose to step 5

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codex found s.solve_for() and s.minimize() in sections 3-4 that
were not covered by the earlier fix. All code blocks now use p.
to match the actual code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- sprint_scheduling: start_epoch was computed but unused — now used
  in filter so planning_start actually narrows the backlog
- shift_assignment: Shift.capacity loaded from CSV but never used
  in any constraint — removed dead property to avoid confusion
- demand_planning: add comment that SCENARIO_VALUES must be in
  increasing date order (data accumulates across iterations);
  clarify safety_stock_weeks is an extension point, not wired in

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- shift_assignment: restore Shift.capacity and add capacity_ic
  constraint (max workers per shift from CSV). The property was
  loaded since the template was created but never enforced.
- demand_planning: wire safety_stock_weeks into a constraint
  requiring inventory >= avg_weekly_demand × safety_stock_weeks
  per site-SKU pair per week. Previously defined but unused.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- shifts.csv: increase capacity to 4/5/4 so all scenarios (including
  coverage_3) are feasible with the new capacity constraint
- shift_assignment README: add capacity troubleshooting bullet
- demand_planning README: add safety_stock_weeks to INFEASIBLE hint

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Capacity should actually constrain the solution: 3 on Morning/Night
means the constraint binds at coverage_3 (exactly 3 assigned).
4 on Afternoon allows slight headroom. Previous 4/5/4 was too loose
to demonstrate the constraint's effect.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The sprint_scheduling code and README described pre-planning_start
issues as "backlog items eligible from Sprint 1" — but the
start_epoch filter now excludes them. Updated both.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All .py files use p = Problem(model, ...) but 16 READMEs still
showed s.solve_for(), s.satisfy(), s.minimize(), etc. in code
blocks. Renamed all to p. for consistency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Change SCENARIO_VALUES from [0.5, 0.75, 1.0] to [0.35, 0.5, 1.0].
At 0.35x capacity the problem is INFEASIBLE (per-developer limits
too tight for 139 story points), demonstrating the scenario sweep's
value in finding the breaking point. The code correctly handles
infeasibility: prints status, skips results, shows N/A in summary.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chriscoey
Copy link
Copy Markdown
Member Author

@somacdivad Good call on the README sync — synced all code blocks across all 21 template READMEs.

What was done:

  • All READMEs now use p. (matching the .py files) instead of the old s. convention — 16 READMEs were out of sync
  • Code blocks for grid_interconnection, demand_planning_temporal, sprint_scheduling, and shift_assignment updated to match the scenario restructuring from PR clean up scenario logic in three prescriptive templates #29
  • Expected output sections updated for the new scenario patterns
  • Wired two previously-unused parameters into constraints: Shift.capacity (max workers per shift) and safety_stock_weeks (inventory floor)
  • Fixed start_epoch in sprint_scheduling (was computed but never used in the filter)
  • Tuned scenario values so the sweep actually demonstrates differentiation (sprint_scheduling now shows an infeasible boundary)

All 21 modified templates verified passing against PyRel v1 on latest.

Re: your longer-term plan for showing code on the website without maintenance burden — happy to help when you have a direction.

Copy link
Copy Markdown
Collaborator

@somacdivad somacdivad left a comment

Choose a reason for hiding this comment

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

Thanks @chriscoey. Looks great!

chriscoey and others added 2 commits March 27, 2026 13:20
Resolve conflict in network_flow.py: keep `count` import (used by
model.require IC on line 70).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- production_planning: rewrite section 2 to describe Scenario-concept
  single-solve pattern (was incorrectly describing a loop pattern)
- supplier_reliability: fix s → p variable name in README snippet
- sprint_scheduling: fix scenario values 0.25 → 0.35 to match code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chriscoey chriscoey merged commit 5ac323e into main Mar 27, 2026
3 checks passed
@chriscoey chriscoey deleted the update-v1-pr730-api-changes branch March 27, 2026 21:00
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