Repository navigation
Release 0.20 - #516
Merged
Merged
Release 0.20#516
Conversation
Merge main back into dev after 0.19.1
find_optimal_replacement and optimal_replacement_policy take discount_rate (continuous, per unit of the life's time) and choose the age with the least equivalent annual cost; MaintenancePolicy gains discount_rate, npv and eac. optimal_calendar_policy takes discount_rate for a periodic Calendar of a short cycle (discounted value iteration stopped by MacQueen's bounds, on the grid or by quadrature), and a site's discount= without a horizon discounts the exact routes, plain age replacement and the dated window, whose run-on is now valued by the recurring shuts' discounted long run. Routes that give long-run averages (sampling, averaged gaps), given dates in model time, long cycles, duty plans and pricing a given rule refuse a rate, saying what to give instead. At rate 0 every number is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Km2eWBiPJ5JNkme3vRg4B
Discount rate for the long-run replacement policies (Fox, 1966)
An Opportunity says when a stop or shut happens, how long it lasts and what it takes down, with no price; Opportunities collects them, in model time or on real dates. Each NonRepairable brings its own prices (opportunity_cost, opportunity_costs by name or object, checked when the policy runs) and job_duration (an opportunity too short is not used). optimal_opportunity_policy and opportunity_policy_cost replace the calendar names, with where= and the policy's prices (OpportunityPrices). NonRepairable.opportunity_prices works prices out from a replacement's cost and the plant's downtime. Calendar, Shutdown, Shutdowns, prices on opportunities and the old method names still work, with a FutureWarning naming the replacement, for removal in 0.21; the prices are laid on the existing solvers' records, so the numbers are bit-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Km2eWBiPJ5JNkme3vRg4B
Opportunities with the prices on the part (UC-45)
…d (UC-44) The maintainer's decision of 16 Nov 2026: "Exact by default; refuse what can't be done exactly; horizon= never refuses." - Opportunities in model time take horizon= (a number) with discount_rate=: a backward sweep from the horizon over every opportunity as it falls, shared with the real-date horizon (_horizon.backward); npv the net present cost, eac its steady equivalent, basis "horizon". - Every refusal of a discounted long run (long cycle, given dates in model time, shuts that drift, a duty plan, sampling, a rule where nothing repeats) names a ready horizon worked out from the inputs. - A given rule's discounted long run is priced exactly (value iteration with the decisions fixed, grid or quadrature); compare() follows. - method="auto" sampling a long cycle warns with a FutureWarning (refused from 0.21), naming the ready horizon and method='sampling'. - optimal_next_replacement discounts its own choices at a discounted policy's rate, valued at its EAC. - ShutdownPolicy and RuleCost carry eac; horizons state it. Rate 0 and the exact routes give the same numbers bit for bit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Km2eWBiPJ5JNkme3vRg4B
Exact by default, refused with a ready horizon, horizon= never refused (UC-44)
find_optimal_replacement(None) raised before #454 (the old options argument, removed in 0.12) and silently took None as the rate after it. Keyword-only restores the refusal; positional rate calls were only in #454's own unreleased doctests and tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Km2eWBiPJ5JNkme3vRg4B
Make discount_rate keyword-only on the age-replacement optimisers
…-limit plans optimal_overhaul_replace_policy searched only "overhaul every T, replace after K periods", and its best was often beaten by a plan it never priced. It now prices four plans and returns the cheapest: overhaul and replace, overhaul only (the age settles at f T / (1 - f), cost rate in closed form), replace only, and a failure limit at the replacement cost. OverhaulReplacePolicy gains plan, failure_count, alternatives, saving and cycles_limit_reached. The grid search now treats overflow as no plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Km2eWBiPJ5JNkme3vRg4B
Overhaul/replace optimiser: compare against never-replace and failure-limit plans
RepairableRBD.npv_distribution prices each history of simulate_timelines with the diagram's own costs, discounted at the times they fell, less the value earned while the system was up, and returns NPVDistribution: each run's NPV, the mean with its interval, P10/P50/P90 with binomial intervals, the chance below a hurdle and the CVaR. Costs the histories do not record refuse the diagram, naming the cost. The pricing of up/down histories moves from _plan_actual into a shared module (_pricing), vectorised over histories; plan_vs_actual uses it unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Km2eWBiPJ5JNkme3vRg4B
Add npv_distribution: the net present value of each simulated run
npv_distribution takes contract=, an AvailabilityContract (plain data: periods, target, penalty and bonus per point of availability, a cap), and pays it run by run from each period's availability in that run, at the period's end, as a category of its own. compare_npv runs two plans from one seed on the same random numbers and returns each run's difference, its mean with a confidence interval, the chance the other plan is better and the standard error independent runs would have had. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Km2eWBiPJ5JNkme3vRg4B
Availability contracts and compare_npv for the simulated NPV
…'s running Blocks on covariate schedules switch from one row of covariates to another at a candidate time; each candidate is the diagram rebuilt with those schedules, simulated from one seed (common random numbers) and priced as npv_distribution prices its runs, with the value rate split at the switch. The horizon is scanned and the best refined; the result is SimulatedSwitchTime, with the NPVs of never switching and switching at once and an interval on the gain over each. For one block it agrees with the numerical one-unit best_switch_time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Km2eWBiPJ5JNkme3vRg4B
# Conflicts: # CHANGELOG.md # README.md # docs/api/results.md # repyability/__init__.py # repyability/rbd/_repairable_routes.py # repyability/tests/capabilities.py # repyability/tests/test_analysis_routes.py
Best time to switch a diagram's running (simulated)
RepairableRBD takes crew_cost_rate: each of the repair_crews crews costs that much per unit time, busy or not, so a crew more is a trade-off. Every cost result shows it under a new "crews" category: n c in the long-run cost rate, n c T over a window and n c (1 - exp(-r T)) / r discounted (in closed form, outside the discounting quadrature), in expected_npv's cash-flow table by period, in the histories priced for npv_distribution and plan_vs_actual, and added to every simulated run after it by the tally, so neither event loop changes and the engines still agree. The interval choices that assume unlimited crews and the redundancy allocation keep the salaries in the cost rate they report. A crew cost without repair_crews is refused; it is saved when given. Without it every value is as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
discount= (the effective yearly rate of the dated replacement policies, a year of 365.25 days, discounted to the forecast's first date) on Task.due, work_by_period, failures_by_period and events_by_period, and Task.long_run_value for a task repeating for ever. - schedule/_discount.py holds the one convention and its helpers (factor, equivalent annual cost, perpetuity, the bracket for costs that accrue inside windows). - A task's dates are known, so its present value is a finite sum; for ever, a plain interval is a geometric sum and any other task is summed until a bound on what is left is under the precision asked. - A part's expected cost accrues as it runs: short windows' costs are discounted at each window's start and end, which bracket the value. - A diagram's is exact, from expected_cost with its discount_rate. - A rule counted from an anchor no longer walks to far dates from the anchor (same dates; a long Task.due is no longer quadratic). Use cases UC-47 to UC-49 in the schedule README; with no discount every result is as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
Price repair crews: crew_cost_rate, a salary per crew per unit time
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
Present values on the calendar forecasts: discount= on tasks, failures and events by period
…failure UC-50 of the schedule README, worked by hand before the code. The long-run value of a task becomes LongRunValue, leaving TaskValue for what a task saves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
task_value(task, Replaces(part), usage) lays the task's dates on the part's clock, renews the part at each whatever its age, and compares it with the part run to failure from the same age, by calendar period, as present values with discount=. Returns TaskValue with each side, the difference, the task's own cost and the failures avoided. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
schedule: what a replacement task is worth against running to failure (task_value)
…resent value optimal_replacement_intervals(objective="eac" | "npv", discount_rate=, value_rate=, horizon=): the equivalent annual cost in the long run, each component's renewal cycle discounted (Fox, 1966) and the system's terms at its long-run availability, or the expected net present value over a horizon from new. The targets are kept; at a rate of 0 the equivalent annual cost is the cost rate, by the same search. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
bdd.order chooses from three orders now (bdd.CANDIDATES): the greedy one, the breadth-first one, and a greedy one that looks a vertex ahead, kept where its frontiers cost less. The search itself is unchanged, so the recorded plans of the recorded cores are too. scripts/bdd_benchmark.py measures grids, layered meshes and random acyclic diagrams of growing width: each order's cost, the states the search keeps, the plan's steps, the time and the peak memory. At the step limit the search holds 40 to 250 MB as Python, so the steps, not the memory, stop a core: the search keeps every state, as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
Document UnitPlan, its tasks and CalendarContext in the API reference
npv_distribution, compare_npv, least_spend_for_downtime, best_switch_time, RepairOrReplace's unit decisions and value_plan's requests drew the seed their runs share from OS entropy, which np.random.seed did not reach. They now take it through _streams.shared_seed, as cost_by_window does. Seeded results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
One way to draw the seed an unseeded multi-run result shares
RepairableRBD(shutdowns=) takes an Opportunities record in model time: each Opportunity is a shutdown of its name (period and offset or dates, duration, takes_down as the scope), with Opportunity(idle_ageing=, opportunistic=) and Opportunities(shut_costs=) for what only a diagram uses. The record is read as the dicts it stands for, which the diagram keeps and saves, so its values and seeded runs are the dicts'. Shuts on real dates go through Opportunities.on_diagram; a ShutdownPolicy is refused, naming the record to give. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
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
One shutdown model: a diagram takes the site's Opportunities
# Conflicts: # CHANGELOG.md
Credit a unit's own salvage and retirement in simulated runs
failures_by_period and task_value discounted a part's accruing cost over short windows, each between its start and its end, and gave the middle with half the bracket as its precision. They now take the diagram's own present value of an accrued cost: the integral of the discounted expected cost by the Gauss-Kronrod rule, its pieces halved to npv_tolerance, lifted out of _windows._discounted_cost into _common._discounted_accrual so that both use the one design (the diagram's values are unchanged to the bit). npv_precision is the integral's error estimate. Run to failure, the expected cost comes from failures rather than cost_by_window's distributions. The README's wear ring is worth $2,882.74 to within $0.016, where the windows gave $2,882.77 give or take $2.47. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
…services best_switch_time, plan_vs_actual and a service's task_value refused a unit's own salvage or retirement. best_switch_time now scans up to the retirement and credits every candidate's runs the salvage, reporting it as npv_distribution does; plan_vs_actual values the plan and the rest from today to the retirement, the salvage credited there as expected_npv credits it, and lists the salvage among what a log does not record; task_value runs each side to its plan's retirement, credits its salvage in the period it falls in, and does no service after it. With nothing left refusing them, the refusal goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
Credit a unit's own salvage and retirement in switch times, logs and services
Run to failure, failures' renewal count is worked out at a grid's points and taken linearly between them. The present value's precision now adds what that can move it, so the closed form for a constant rate is within the precision given. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP
Discount a schedule forecast's costs from when they fall
allocate_redundancy and redundancy_front take start_probability for cold standby: a spare that fails to start is skipped and the next is tried, as StandbyModel and standby blocks mean it. The search's reliability for a design then equals the diagram's once that design is applied. Giving it with switching_probability is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP
…bility Let the redundancy search take start_probability
JointModel and DynamicPrediction come from surpyval.univariate.joint, SemiParametricRegressionModel and ProportionalOddsFitter from surpyval.univariate.regression: surpyval 0.29 keeps them off its top level. surpyval.univariate.joint is on the public list, so DynamicPrediction leaves NO_PUBLIC_HOME. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP
…ports Take surpyval's model classes from their subpackages
Version 0.20 with surpyval>=0.29. NEXT_REMOVAL becomes 0.21, where what 0.20 deprecates goes, and REMOVED_IN_0_22 follows it; 0.19 deprecated nothing, so nothing is removed. The changelog's section is dated, with its summary. With the minimum at 0.29, the renewal processes are built with from_params (GeneralizedRenewal, GeneralizedOneRenewal, ARA, ARI), the name surpyval 0.29 gives fit_from_parameters, which warns there and goes in surpyval 0.30. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP
…raded The public long-run methods are asked of the diagram once upgraded (follows_upgrades); the test asked the private call of the diagram itself, which refuses, and failed for the two upgraded kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP
Compare an upgraded diagram's long run with its private call once upgraded
Prepare 0.20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP
- A merged or sharded run kept each simulation's time down unplanned only from its first chunk: merge adds the other's times, and a chunk's dict carries them, so unplanned_downtimes survives threads, shards and chunks as uptimes do. - least_spend_for_downtime is refused where availability is: a diagram with capacities too meshed for its reduced diagram. - Tests that predate other 0.20 changes: a number is now a task's duration (a negative one is refused); the cost categories gained crews and capital; surpyval 0.29's Hypoexponential takes stage rates all but equal; the compiled engine refuses shutdowns, which auto runs in Python. - The shutdowns guide's Opportunities example defines its diagram. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP
Fix what the 0.20 release PR's full suite found
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release RePyability 0.20 (requires surpyval 0.29, now on PyPI). Changelog: the [0.20] - 2026-11-22 section.
🤖 Generated with Claude Code
https://claude.ai/code/session_01V339RzRHo8RS8Cz3uSbQgP