Skip to content

Unit plans

One unit's maintenance plan as plain data: its life and repair models, its tasks, each in its own clock, and its prices. A RepairableRBD node takes a UnitPlan as it takes a spec dict (the plan's shorthand), and a plan is valued alone through the diagram of its one node. See Maintaining a system for the tasks and Costs for the prices. They are exported at the top level and from repyability.maintenance: from repyability import UnitPlan.

UnitPlan dataclass

UnitPlan(life, repair=None, tasks=(), prices=Prices(), imperfect_repair=None, priority=None, group=None, standby=None, duty=None, covariates=None, salvage=None, escalation=None, retire_at=None)

One unit's maintenance plan: its life and repair (time to repair) models, its tasks and its prices.

A RepairableRBD node takes a plan as it takes a spec dict (the plan's shorthand: from_spec and spec), so every analysis takes it. A plan holds at most one preventive task (bind it to several shutdowns with AtShutdown(shutdown=[...])), one Inspection and one Upgrade. imperfect_repair makes repairs partial; priority (the crews' queue, higher first), group (its maintenance group's name), standby (a dict, making the node a standby group of such units), duty (the share of the time it operates, for a life in operating hours) and covariates (a surpyval StepSchedule) are as in the spec.

Three terms are the unit's own money, which a valuation (expected_npv) takes as it takes its arguments of the same names for the node: salvage, what the unit is worth at the end (a number, or a function of the age of the unit in service, taking an array of ages; negative for a cost of disposal); escalation, the growth rate per unit time of every price of the unit (continuous, of either sign); and retire_at, when the unit is retired, nothing earned or spent after it (a plan valued alone, or the only unit of a diagram).

A plan is valued alone through the diagram of its one node (diagram(), the node named UnitPlan.NODE): expected_npv, cash_flows, npv_distribution, plan_vs_actual, expected_cost, expected_cost_rate, events_by_period, failures_by_period and the optimisers are that diagram's, so a plan alone and a diagram holding it give the same values by the same code. Each takes calendar, a schedule.CalendarContext whose duty names the node "unit": the diagram on that calendar.

Parameters:

Name Type Description Default
life model

The unit's time-to-failure model, in the plan's unit of time: a fitted surpyval model, or any model with a life's functions (a NonRepairableRBD included), as a spec's "reliability".

required
repair (model, float or instant)

The unit's time-to-repair model, as a spec's "repairability"; "instant" repairs it in no time.

None
tasks sequence

Its tasks: at most one preventive task (AgePolicy, BlockPolicy, ConditionPolicy, CalendarReplacement or AtShutdown), one Inspection and one Upgrade.

()
prices Prices or dict

The unit's own prices (a dict is read as the fields of a Prices); by default none.

Prices()
imperfect_repair ImperfectRepair

Makes each repair partial; by default a repair renews the unit.

None
priority float

Its place in the repair crews' queue: higher first.

None
group hashable

The name of its maintenance group, whose stops it shares.

None
standby dict

Makes the node a standby group of such units, as a spec's "standby".

None
duty float

The share of the time it operates, in (0, 1], for a life in operating hours.

None
covariates surpyval StepSchedule

The covariates of a regression life over time.

None
salvage float or callable

What the unit is worth at the end, in money: a number, or a function of the age of the unit in service (taking an array of ages); negative for a cost of disposal.

None
escalation float

The continuous growth rate per unit of time of every price of the unit, of either sign.

None
retire_at float

When the unit is retired, in the plan's unit of time from 0; nothing is earned or spent after it.

None

Examples:

>>> import surpyval as surv
>>> from repyability.maintenance import AgePolicy, UnitPlan, Prices
>>> plan = UnitPlan(
...     surv.Weibull.from_params([1000.0, 2.5]),
...     surv.Exponential.from_params([0.1]),
...     tasks=(AgePolicy(interval=4000.0, cost=20.0),),
...     prices=Prices(repair=400.0),
... )
>>> sorted(plan.spec())
['preventive', 'reliability', 'repair_cost', 'repairability']
>>> UnitPlan.from_spec(plan.spec()) == plan
True

task

task(kind)

The plan's "preventive", "inspection" or "upgrade" task, or None.

Parameters:

Name Type Description Default
kind str

"preventive", "inspection" or "upgrade".

required

spec

spec()

The spec dict this plan is, as a RepairableRBD node reads it: keys at their defaults left out.

from_spec classmethod

from_spec(spec)

The plan a spec dict states (the spec a RepairableRBD node takes); a key no field holds is refused.

Parameters:

Name Type Description Default
spec dict

A spec dict with a "reliability", as a RepairableRBD node takes it.

required

to_dict

to_dict()

The plan as JSON-ready data (as a diagram saves a node's spec); from_dict loads it.

from_dict classmethod

from_dict(data)

The plan to_dict saved.

Parameters:

Name Type Description Default
data dict

What to_dict returned.

required

diagram

diagram(calendar=None)

The RepairableRBD of this plan's one node (named UnitPlan.NODE), on calendar if given (a schedule.CalendarContext; its duty names the node "unit"): what every valuation of the plan alone asks.

Parameters:

Name Type Description Default
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None

analysis_routes

analysis_routes(calendar=None)

How each valuation of the plan alone is worked out (exact, numerical, simulated or refused, with the reason), without running anything: its diagram's routes, by the plan's method.

Parameters:

Name Type Description Default
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None

expected_npv

expected_npv(horizon, *, calendar=None, **kwargs)

The plan's expected net present value over horizon: RepairableRBD.expected_npv of its one-node diagram (the same arguments), its salvage, escalation and retirement taken from the plan where the arguments leave them out.

Parameters:

Name Type Description Default
horizon float

The length of time valued, in the plan's unit of time.

required
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None
**kwargs

As for RepairableRBD.expected_npv.

{}

Examples:

>>> import math
>>> import surpyval as surv
>>> from repyability.maintenance import AgePolicy, Prices, UnitPlan
>>> pump = UnitPlan(
...     surv.Weibull.from_params([20000.0, 2.5]),
...     surv.Exponential.from_params([1 / 24]),
...     tasks=(AgePolicy(interval=12000.0, cost=1500.0),),
...     prices=Prices(repair=6000.0, acquisition=40000.0),
...     salvage=5000.0,
... )
>>> r = math.log(1.07) / 8760
>>> result = pump.expected_npv(8 * 8760.0, discount_rate=r)
>>> round(result.npv), round(result.salvage)
(-48719, 2910)

cash_flows

cash_flows(horizon, *, calendar=None, **kwargs)

The plan's expected cash flows by period and category: the table of expected_npv (the same arguments; periods sets the periods).

Parameters:

Name Type Description Default
horizon float

The length of time valued, in the plan's unit of time.

required
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None
**kwargs

As for expected_npv.

{}

npv_distribution

npv_distribution(horizon, *, calendar=None, **kwargs)

The plan's NPV in each of many simulated runs: RepairableRBD.npv_distribution of its one-node diagram.

Parameters:

Name Type Description Default
horizon float

The length of time valued, in the plan's unit of time.

required
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None
**kwargs

As for RepairableRBD.npv_distribution.

{}

plan_vs_actual

plan_vs_actual(timeline, now, horizon, *, calendar=None, **kwargs)

The plan against what happened to the unit: its Timeline (outage log) to now, as RepairableRBD.plan_vs_actual of its one-node diagram; a state is the unit's NodeState.

Parameters:

Name Type Description Default
timeline Timeline

The unit's outage log up to now.

required
now float

The time of the last record, in the plan's unit of time.

required
horizon float

The length of time valued from 0, in the plan's unit of time.

required
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None
**kwargs

As for RepairableRBD.plan_vs_actual; a state or start_state is the unit's own NodeState.

{}

expected_cost

expected_cost(t, *, calendar=None, **kwargs)

The plan's expected cost to t: RepairableRBD.expected_cost of its one-node diagram.

Parameters:

Name Type Description Default
t float

The time to which costs are counted, in the plan's unit of time.

required
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None
**kwargs

As for RepairableRBD.expected_cost.

{}

expected_cost_rate

expected_cost_rate(*, calendar=None)

The plan's long-run expected cost per unit time: RepairableRBD.expected_cost_rate of its one-node diagram.

Parameters:

Name Type Description Default
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None

events_by_period

events_by_period(usage, period='month', **kwargs)

The plan's expected events (and on request costs) in each calendar period: schedule.events_by_period of its one-node diagram; usage a UsageForecast or a CalendarContext (giving the node "unit" its duty plan).

Parameters:

Name Type Description Default
usage UsageForecast or CalendarContext

The calendar and the unit's duty plan (a CalendarContext's duty names the node "unit").

required
period str

The calendar period counted in: "month" (the default), as schedule.events_by_period takes.

'month'
**kwargs

As for schedule.events_by_period.

{}

failures_by_period

failures_by_period(usage, period='month', **kwargs)

The plan's expected failures (with the other events) in each calendar period, as events_by_period: a unit in a plan is worked out by the diagram's engine, its tasks and repairs taking their time, on the calendar its duty plan gives.

Parameters:

Name Type Description Default
usage UsageForecast or CalendarContext

As for events_by_period.

required
period str

As for events_by_period.

'month'
**kwargs

As for events_by_period.

{}

optimal_replacement_interval

optimal_replacement_interval(*, calendar=None, **kwargs)

The plan's best age-replacement interval: RepairableRBD.optimal_replacement_intervals of its one-node diagram (the same arguments, but nodes).

Parameters:

Name Type Description Default
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None
**kwargs

As for RepairableRBD.optimal_replacement_intervals.

{}

least_spend_for_downtime

least_spend_for_downtime(horizon, limit, *, calendar=None, **kwargs)

The least spend that keeps a bad run's downtime under limit: RepairableRBD.least_spend_for_downtime of its one-node diagram (the same arguments; a lever names the node "unit").

Parameters:

Name Type Description Default
horizon float

The length of time valued.

required
limit float

The downtime a bad run must stay under.

required
calendar CalendarContext

The calendar the diagram runs on, as for diagram.

None
**kwargs

As for RepairableRBD.least_spend_for_downtime.

{}

optimal_inspection_interval

optimal_inspection_interval(*, calendar=None, **kwargs)

The plan's best proof-test interval: RepairableRBD.optimal_inspection_intervals of its one-node diagram (the same arguments, but nodes).

Parameters:

Name Type Description Default
calendar CalendarContext

The calendar the plan's diagram runs on (its duty names the node "unit"); by default none.

None
**kwargs

As for RepairableRBD.optimal_inspection_intervals.

{}

Prices dataclass

Prices(repair=None, replace=None, downtime=None, acquisition=None)

The unit's own prices: each repair, each replace (a failure that uses a spare; each a number or a distribution), its own downtime per unit of time down, and its acquisition, the one-off cost of buying it. A task's price is the task's cost. The costs guide says which price is charged when.

Parameters:

Name Type Description Default
repair float or distribution

The price of each repair (each failure), in money: a number, or a distribution drawn afresh each time.

None
replace float or distribution

The price of each replacement on failure (one that uses a spare), in money: a number, or a distribution drawn afresh each time.

None
downtime float

The price per unit of time the unit is down, in money per the plan's unit of time, whether or not the system is.

None
acquisition float

The one-off cost of buying the unit, in money.

None

AgePolicy dataclass

AgePolicy(interval=None, cost=None, duration=INSTANT, opportunity=None, restoration=None, basis=None)

Bases: _Task

Replace (or restore) the unit at age interval since it was last renewed, or at a failure, whichever comes first.

cost is each task's price (a number, or a distribution drawn each time), duration its time (a model, or "instant"), and opportunity the age from which a stop of the unit's maintenance group renews it early. basis="operating" counts the times in operating hours (put on the clock through the unit's duty). The spec's keys are in the preventive maintenance guide.

Parameters:

Name Type Description Default
interval float

The age at which the unit is replaced, in the plan's unit of time, more than 0 (inf: never).

None
cost float or distribution

The price of each task, in money: a number, or a distribution of it (anything with qf and mean, such as a fitted surpyval model) drawn afresh each time. None prices nothing.

None
duration (model, float or instant)

How long each task takes, in the plan's unit of time: a time-to-maintain model or a fixed time, the unit down meanwhile (a planned outage); "instant" (the default) renews it in place.

INSTANT
opportunity float

An age, from 0 to interval, from which a stop of the unit's maintenance group (the plan's group) renews it early, as the task would; None takes no opportunity.

None
restoration Restoration

How much of the unit's age each task takes away; None (the default) renews it as new.

None
basis str

What the task's times are counted in: "calendar" (None, the default) or "operating", the unit's running hours, put on the calendar through its duty (see Operating part of the time).

None

spec

spec()

The "preventive" spec this task is.

BlockPolicy dataclass

BlockPolicy(interval=None, times=None, cost=None, duration=INSTANT, restoration=None, basis=None)

Bases: _Task

Replace (or restore) the unit every interval whatever its age, or at each of the given times (from 0) and no more. A replacement due while the unit is down is skipped.

Parameters:

Name Type Description Default
interval float

The time between replacements, in the plan's unit of time (at interval, 2 * interval, ...); not given with times.

None
times sequence of float

The times of the replacements, increasing, from 0 on the diagram's clock, and none after the last: a plan valued over a horizon (see Replacement at given times).

None
cost float or distribution

The price of each task, in money: a number, or a distribution of it (anything with qf and mean, such as a fitted surpyval model) drawn afresh each time. None prices nothing.

None
duration (model, float or instant)

How long each task takes, in the plan's unit of time: a time-to-maintain model or a fixed time, the unit down meanwhile (a planned outage); "instant" (the default) renews it in place.

INSTANT
restoration Restoration

How much of the unit's age each task takes away; None (the default) renews it as new.

None
basis str

What the task's times are counted in: "calendar" (None, the default) or "operating", the unit's running hours, put on the calendar through its duty (see Operating part of the time).

None

spec

spec()

The "preventive" spec this task is ("replace_at" for given times).

ConditionPolicy dataclass

ConditionPolicy(interval=None, threshold=None, level=None, inspection_cost=None, cost=None, duration=INSTANT, restoration=None, basis=None)

Bases: _Task

Inspect the unit every interval and replace (or restore) it when its chance of failing by the next inspection is above threshold, or, for a degradation process, its measured level is reached; each inspection costs inspection_cost. See Replacement on condition.

Parameters:

Name Type Description Default
interval float

The time between inspections, in the plan's unit of time, more than 0; inspections are done while the unit is up, in no time.

None
threshold float

A probability: the unit is replaced when its chance of failing before the next inspection, given its age, is above it. Not given with level.

None
level float

For a life that is a degradation process: the measured level, in the process's units, at or past which the unit is replaced (simulated only). Not given with threshold.

None
inspection_cost float or distribution

The price of each inspection, in money (a number, or a distribution drawn afresh each time).

None
cost float or distribution

The price of each replacement, in money: a number, or a distribution of it (anything with qf and mean, such as a fitted surpyval model) drawn afresh each time. None prices nothing.

None
duration (model, float or instant)

How long each task takes, in the plan's unit of time: a time-to-maintain model or a fixed time, the unit down meanwhile (a planned outage); "instant" (the default) renews it in place.

INSTANT
restoration Restoration

How much of the unit's age each task takes away; None (the default) renews it as new.

None
basis str

What the task's times are counted in: "calendar" (None, the default) or "operating", the unit's running hours, put on the calendar through its duty (see Operating part of the time).

None

spec

spec()

The "preventive" spec this task is.

CalendarReplacement dataclass

CalendarReplacement(policy=None, duration=INSTANT, opportunity=None, basis=None)

Bases: _Task

Replace the unit on a calendar policy's thresholds: a CalendarPolicy (NonRepairable.optimal_calendar_policy) or a site's ShutdownPolicy, whose prices are charged; opportunity as for AgePolicy. See Replacement on a calendar policy.

Parameters:

Name Type Description Default
policy CalendarPolicy or ShutdownPolicy

The calendar policy whose thresholds say when the unit is replaced: at the first time its age reaches one. Its prices are charged, so the task takes no cost.

None
duration (model, float or instant)

How long each task takes, in the plan's unit of time: a time-to-maintain model or a fixed time, the unit down meanwhile (a planned outage); "instant" (the default) replaces it in place.

INSTANT
opportunity float

An age, from which a stop of the unit's maintenance group (the plan's group) renews it early, as the task would; None takes no opportunity.

None
basis str

What the task's times are counted in: "calendar" (None, the default) or "operating", the unit's running hours, put on the calendar through its duty (see Operating part of the time).

None

spec

spec()

The "preventive" spec this task is (its policy under "calendar").

AtShutdown dataclass

AtShutdown(shutdown=None, policy='block', older_than=None, threshold=None, inspection_cost=None, cost=None, restoration=None, basis=None)

Bases: _Task

Renew the unit at each of the site's shutdowns named shutdown (a name, or a list of names), taking the shut's time; with older_than, only if it is that old. policy="condition" inspects it there instead, replacing it above threshold. See Shutdowns.

Parameters:

Name Type Description Default
shutdown str or list of str

The name (or names) of the diagram's shutdowns at whose shuts the task is done; it takes the shut's time.

None
policy str

"block" (the default): renewed at every shut (with older_than, only if that old). "condition": inspected at every shut and replaced above threshold.

'block'
older_than float

Renewed at a shut only if its age then is at least this, in the plan's unit of time.

None
threshold float

Under "condition": the probability of failing before the next shut, given its age, above which it is replaced.

None
inspection_cost float or distribution

The price of each inspection (under "condition"), in money (a number, or a distribution drawn afresh each time).

None
cost float or distribution

The price of each renewal, in money: a number, or a distribution of it (anything with qf and mean, such as a fitted surpyval model) drawn afresh each time. None prices nothing.

None
restoration Restoration

How much of the unit's age each task takes away; None (the default) renews it as new.

None
basis str

What the task's times are counted in: "calendar" (None, the default) or "operating", the unit's running hours, put on the calendar through its duty (see Operating part of the time).

None

spec

spec()

The "preventive" spec this task is (with its "shutdown").

Inspection dataclass

Inspection(interval=None, cost=None, duration=INSTANT, offset=None, coverage=None, full_test=None, shutdown=None, basis=None)

Test the unit every interval (or at the site's shutdown), finding a hidden failure; the first at offset, each finding one with probability coverage and every full_test all of them, each taking duration and costing cost. The spec's keys are in Hidden failures and inspection.

Parameters:

Name Type Description Default
interval float

The time between tests, in the plan's unit of time, more than 0; not given with shutdown.

None
cost float or distribution

The price of each test, in money: a number, or a distribution of it (anything with qf and mean, such as a fitted surpyval model) drawn afresh each time. None prices nothing.

None
duration (model, float or instant)

How long each test takes, in the plan's unit of time: a model or a fixed time, the unit off line meanwhile; "instant" (the default) takes no time.

INSTANT
offset float

The time of the first test, from 0 to less than interval (tests at offset, offset + interval, ...); by default the first is at interval.

None
coverage float

The chance in [0, 1] that a test finds a failure (by default 1); a failure a test misses stays hidden until a full test.

None
full_test float

With a coverage below 1: the time between full tests, which find every failure, a whole multiple of interval.

None
shutdown str or list of str

The name (or names) of the diagram's shutdowns at whose shuts the unit is tested, in place of an interval.

None
basis str

What the test's times (interval, offset, full_test) are counted in: "calendar" (None, the default) or "operating", the unit's running hours, put on the calendar through its duty (see Operating part of the time).

None

spec

spec()

The "inspection" spec this task is.

Upgrade dataclass

Upgrade(at=None, life=None, cost=None)

From time at (from 0) the unit has another life: the unit in service is replaced by one of it, in no time, for the capital cost.

Parameters:

Name Type Description Default
at float

When the upgrade is made, from 0 on the diagram's clock, in the plan's unit of time.

None
life model

The new unit's time-to-failure model (as the plan's life).

None
cost float

The capital cost of the upgrade, in money, charged at at.

None

spec

spec()

The "upgrade" spec this task is.

Restoration dataclass

Restoration(q=None, model='kijima2', to_age=None, process=None, replace_every=None, replacement_cost=None)

How much of its age a preventive task takes away (a task that renews the unit, the default, has none).

Give a Kijima factor (q with model "kijima1" or "kijima2": 0 renews, 1 leaves the unit as old as it was, above 1 leaves it older), a virtual age to restore to (to_age), or a fitted surpyval GeneralizedRenewal (process). With replace_every N, every N-th task replaces the unit, at replacement_cost (the task's own cost if None). The rules are in Maintaining a system, "Planned maintenance that restores partly".

Parameters:

Name Type Description Default
q float

Kijima's restoration factor, 0 or more: 0 renews the unit, 1 leaves it as old as it was, above 1 leaves it older. Not given with to_age or process.

None
model str

Kijima's virtual-age model for q: "kijima2" (the default, the factor applied to the whole virtual age) or "kijima1" (to the age gained since the last action).

'kijima2'
to_age float

A virtual age, 0 or more and in the plan's unit of time, that each task leaves the unit at, whatever its age before.

None
process surpyval GeneralizedRenewal

A fitted renewal process whose Kijima model and factor each task takes.

None
replace_every int

Every replace_every-th task since the unit was last renewed replaces it as new instead.

None
replacement_cost float or distribution

The price of such a replacement, in money; by default the task's own cost.

None

spec

spec()

The keys of a "preventive" spec this restoration is.

ImperfectRepair dataclass

ImperfectRepair(model='kijima1', q=None, process=None, replace_after=None)

A repair that restores the unit only partly: Kijima's model ("kijima1" or "kijima2") with factor q in [0, 1], or a fitted renewal process (G1, ARA, ARI) repairing by its own rule. With replace_after N, the N-th failure since the unit was renewed replaces it. See Imperfect repair.

Parameters:

Name Type Description Default
model str

Kijima's virtual-age model: "kijima1" (the default, the factor applied to the age gained since the last repair) or "kijima2" (to the whole virtual age).

'kijima1'
q float

The restoration factor in [0, 1]: 0 renews the unit at each repair, 1 leaves it as old as it was (minimal repair).

None
process surpyval renewal model

A fitted G1, ARA or ARI renewal process repairing by its own rule, in place of model and q.

None
replace_after int

The failure, counted since the unit was renewed, at which it is replaced rather than repaired.

None

spec

spec()

The spec's "repair" and "replace_after".