Skip to content

Credit a unit's own salvage and retirement in simulated runs - #509

Merged
derrynknife merged 2 commits into
devfrom
build/own-end-in-runs
Nov 21, 2026
Merged

derrynknife merged 2 commits into
devfrom
build/own-end-in-runs

Conversation

@derrynknife

Copy link
Copy Markdown
Owner

Summary

A UnitPlan, or a component spec, can carry its own salvage and retire_at. expected_npv credited both, but npv_distribution and compare_npv refused them. Now they take them:

  • The runs end at the retirement (min(horizon, retire_at)). The contract periods are cut there too.
  • Every run is credited the salvage at the end, discounted as expected_npv discounts it, growing only by the "salvage" stream. This applies to a salvage given as a number, which is the same whatever happened in the run.
  • NPVDistribution gains salvage, undiscounted_salvage and retire_at. In compare_npv, each plan ends at its own retirement and gets its own credit.
  • One helper, _npv.own_end, does this for both.

Still refused, with messages that name what to give:

  • a salvage by age of the unit in service, which needs each run's age;
  • one unit retiring inside a diagram of several (expected_npv's refusal);
  • a unit's own salvage or retirement in best_switch_time, plan_vs_actual and task_value. best_switch_time's route now refuses this itself, since it no longer inherits the refusal from npv_distribution's route.

Results without these terms are unchanged.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / tooling
  • Breaking change

Checklist

  • Tests added/updated:
    • New test_npv_runs_own_end.py: each run with a salvage equals the run without it plus the salvage, to 1e-9; a retirement equals the run to that time; the credit equals expected_npv's salvage to 1e-12; compare_npv's matched differences equal the salvage; the refusals and their routes.
    • test_plan_alone.py: its test that the runs refuse a salvage now checks that plan_vs_actual still refuses and that npv_distribution is simulated.
  • black, isort, flake8 and mypy on the changed files. Tests, one process:
    • test_npv_runs_own_end and test_plan_alone: 216 passed, re-run after merging dev.
    • Before the merge, these together with test_npv_distribution, test_upgrade_retire_salvage, test_npv_escalation and the npv_distribution, compare_npv and best_switch_time cases of test_analysis_routes: 282 passed, 1 skipped.
    • Doctests of the touched modules: 34 passed.
  • Anything that must agree is updated: analysis_routes (the npv_distribution and best_switch_time routes) and UC-65 in the maintenance README.
  • CHANGELOG.md updated under [Unreleased]
  • Monte-Carlo tests seeded

Notes for reviewers

A first draft of the new retirement test expected a unit's own escalation to grow its salvage. expected_npv grows a salvage only by the "salvage" stream (23.5988 against the 24.7592 the draft expected, for 30 at 240 h with 2e-4 of growth). The test now checks against expected_npv. No tolerance was changed.


Generated by Claude Code

npv_distribution and compare_npv refused a unit's own retire_at and
salvage. The runs now end at the retirement, and every run is credited
the salvage (a number) at the end, discounted as expected_npv discounts
it; the result says so (salvage, undiscounted_salvage, retire_at). A
salvage by age and one of several units retiring are still refused, as
are a unit's own salvage and retirement in best_switch_time,
plan_vs_actual and task_value. Results without them are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
# Conflicts:
#	CHANGELOG.md
@derrynknife
derrynknife merged commit a6f79bb into dev Nov 21, 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