Skip to content

Building an RBD

Learning this for the first time?

This page is the reference. The ideas behind it are taught step by step, with worked examples and exercises, in Lesson 2 (series, parallel and \(k\)-out-of-\(n\)) and Lesson 3 (path and cut sets).

A reliability block diagram is a directed graph from one input node to one output node, plus a model for every node in between. The system works while at least one path of working nodes connects the input to the output.

Edges and node models

Give the edges as (from, to) pairs and a dict mapping each intermediate node to its model. Node names can be any hashable (strings, integers, tuples).

import surpyval as surv
from repyability import NonRepairableRBD

#   s -> (pump1 | pump2) -> valve -> t
edges = [
    ("s", "pump1"), ("s", "pump2"),
    ("pump1", "valve"), ("pump2", "valve"),
    ("valve", "t"),
]
models = {
    "pump1": surv.Weibull.from_params([100, 2]),
    "pump2": surv.Weibull.from_params([100, 2]),
    "valve": surv.Weibull.from_params([200, 1.5]),
}
rbd = NonRepairableRBD(edges, models)
rbd.sf(50)   # -> 0.8393   system reliability at t = 50

The input and output nodes are inferred as the unique node with no predecessors and the unique node with no successors, and need no model. You can name them with input_node=/output_node=, but they must be that source and sink: naming any other node raises ValueError. Either way, the diagram must have exactly one source and one sink.

A node model is anything that exposes sf(t) and ff(t):

Model Use it for
A surpyval parametric distribution (Weibull, Exponential, LogNormal, …) An ordinary component with a fitted lifetime.
A surpyval MixtureModel A population of failure modes (infant mortality and wear-out).
A surpyval Bayesian fit (fit_bayes, a BayesianParametric) A component whose life is known with uncertainty: the life is the fit's posterior predictive (see below).
A surpyval WienerProcess or GammaProcess fit A component that fails when its degradation reaches a threshold: its life is the time to the threshold (see Costs for replacing it on the measured level).
A surpyval non-parametric fit (KaplanMeier, NelsonAalen, …) Refused (ValueError): its curve ends at the data, and says nothing beyond it. Fit a parametric distribution in surpyval instead.
surpyval.FixedEventProbability A component with a fixed probability of failure (a demand, a mission).
PerfectReliability / PerfectUnreliability A node that never fails / has always failed (a junction, a placeholder).
StandbyModel, RepeatedStandbyNode Standby redundancy (see Redundancy models).
RepeatedNode n identical independent copies in series or parallel.
LoadSharingModel Units that share a load and fail dependently.
RegressionNode A component whose life depends on its operating conditions (see Condition-based evaluation).
Another NonRepairableRBD A subsystem, nested as a single node.

A surpyval parametric model can carry an offset (gamma), a limited failure population (lfp_p < 1: a fraction 1 - lfp_p of the units never fail) or zero inflation (f0 > 0: a fraction dead on arrival). Every calculation honours them. Simulations draw an infinite lifetime for a unit that never fails and 0 for one dead on arrival, so a system that can outlast its failing units has an infinite MTTF, as has the node itself:

cured = surv.Weibull.from_params([100, 2], lfp_p=0.9)   # one unit in ten never fails
one = NonRepairableRBD([("s", "c"), ("c", "t")], {"c": cured})
one.sf(1e6)             # -> 0.1   the units that never fail
one.node_mttf()["c"]    # inf

(surpyval's own mean() of such a model is the defective mean, its failing units' mean weighted by their fraction: RePyability never uses it as a lifetime.)

A Bayesian fit as a life

A Bayesian fit in surpyval (surv.Weibull.fit_bayes(...), or surv.bayes.BayesianParametric.from_draws(...) from another sampler's draws) says how sure we are of a life's parameters. Given to a diagram, a NonRepairable or a RepairableRBD's component, the block's life is the fit's averaged prediction over that uncertainty: the life of a new unit, all things considered. It is a little more spread than the life at the best single estimate, with more early failures and more long lives.

In symbols, the block's reliability is the posterior predictive, S(t) = sum_i w_i S(t | theta_i): the survival function at each posterior point theta_i, averaged with its probability w_i (equal for draws). Where the fit has it in closed form (an Exponential with a Gamma posterior on its rate, whose predictive is a Lomax), that is used. The block is a PosteriorPredictive: each function is the predictive's (its probability of failing worked out in its own right, its quantile by inverting it, its mean the points' means averaged), and the simulations draw a posterior point and a life from it, from one uniform. Each function is surpyval's own; for a posterior of more than 2,000 points surpyval (0.28 on) reads them from a table it builds once, within 1e-6 of the full sum relative (1e-5 for the density and hazard). Set fit.predictive_table = False for the full sum.

import numpy as np

# The rate of a pump's exponential life has a Gamma(5, 1250) posterior,
# here as 4000 draws from another sampler.
rate = np.random.default_rng(1).gamma(5.0, 1 / 1250.0, 4000)
fit = surv.bayes.BayesianParametric.from_draws(surv.Exponential, rate[:, None])
plant = NonRepairableRBD(
    [("s", "pump"), ("pump", "valve"), ("valve", "t")],
    {"pump": fit, "valve": surv.Weibull.from_params([2000, 1.5])},
)
plant.sf(100)                                # -> 0.676
plant.reliabilities["pump"].sf(100)          # -> 0.6836   the draws' average

Its credible band, carried to the system

The predictive is one number for each question: the best single answer, with the uncertainty averaged in. How sure the fit is of that answer is its credible band, and the parameter-uncertainty methods (sf_uncertainty, mean_uncertainty, bx_life_uncertainty, time_to_reliability_uncertainty, and a RepairableRBD's mean_availability_uncertainty and the like) carry it to the system. For an ordinary fit they draw plausible parameters from the fit's sampling uncertainty; for a Bayesian fit the plausible parameters are the posterior itself. Each draw picks a posterior point by its probability (grid points have unequal probabilities; none is left out or thinned), or, for a conjugate posterior, a value from its exact family; the block in that draw is the plain distribution at that point, not the predictive. The system's value is worked out for every draw, and the spread of those values is the band. The point value (nominal) stays the predictive's.

In symbols, with theta_k the k-th draw from the posterior, the band is the percentiles of R_sys(t | theta_k) over the draws: for one exponential block whose rate lam has a Gamma(a, b) posterior, R(t) = exp(-lam t) falls as lam rises, so the 90% band is (exp(-t q_0.95), exp(-t q_0.05)), q the Gamma's quantiles, and the point value the Lomax (b / (b + t)) ** a.

band = plant.sf_uncertainty(100, n_draws=10_000, seed=0)
band.band                                    # 'credible'
band.nominal                                 # -> 0.676   the predictive's
lower, upper = band.interval(0.9)
round(lower, 3), round(upper, 3)             # (0.483, 0.847)

Against the closed form: the Gamma(5, 1250) quantiles give (0.475, 0.845) (times the valve's 0.9978); the 4000 draws the fit is made of are that posterior to within their own sampling error.

By default every fitted block is drawn: the Bayesian ones from their posteriors, the ones fitted by maximum likelihood from their covariance. A band over both is "mixed": each draw takes every block's draw, so it holds both kinds of uncertainty at once, and is neither a confidence band nor a credible band alone. UncertaintyResult.band says which it is: "credible" (Bayesian blocks only), "confidence" (covariance-based fits only), "given" (distributions or lists of models given) or "mixed".

Blocks given the same fit object are one population, as blocks given one ordinary fit are: they share one draw of the posterior in every draw (the diagram holds one model for them), and drawing one without the others is warned about. Two fit objects, even of the same data, are drawn apart. uncertainty_importance takes a Bayesian block with method="sobol"; its default, the delta method, moves parameters a little about one value with their covariance, which a posterior has not, and refuses it. A {parameter: distribution} for a Bayesian block is refused too: give "fit", or a list of models.

A fit with an offset, a limited failure population or zero inflation (fit_bayes(offset=True), lfp=True, zi=True, or draws with gamma, lfp_p or f0 columns) is taken too: each posterior point is its own model, with its own offset and shares, and the predictive is their average. Its functions are the fit's own; a draw picks a point and inverts that point's model (0 for a unit dead on arrival, inf for one that never fails); its share that never fails is the points' 1 - lfp_p averaged, so in the long run a repaired unit is up for good; and its credible band draws each point with its offset and shares. A fit of a discrete distribution is refused: it is of a count, not a life.

A life on two clocks: hours and starts

Some parts wear by running hours and by starts: a gas turbine's hot parts, a pump that cycles. surpyval's Equivalence (from surpyval 0.28) fits the combined clock hours + k starts, where k is what one start is worth in hours, and model.at_usage(rate) gives the life of a unit making rate starts per running hour, in hours. That life is a block as it is: give it to a diagram, a NonRepairable or a RepairableRBD's component, and the diagram answers in hours.

In plain words: a unit making rate starts an hour ages 1 + k rate equivalent hours for every hour it runs, so it lasts that many times less in hours. One start worth 20 hours makes a base-load unit (0.01 starts an hour) age 1.2 times as fast as running alone would, and a peaking unit (0.3 starts an hour) 7 times as fast.

# Needs surpyval's LifeAtUsage (0.28)
# Fitted in surpyval to the fleet's hours and starts:
# surv.WeibullEquivalence.fit(hours, starts, c=c, clocks=("hours", "starts"))
model = surv.WeibullEquivalence.from_params(
    [20000, 2.5, 20], clocks=("hours", "starts")
)
peaking = model.at_usage(0.3)                # 0.3 starts per running hour
peaking.acceleration                         # -> 7.0
plant = NonRepairableRBD([("s", "turbine"), ("turbine", "t")], {"turbine": peaking})
plant.sf(2000)                               # -> 0.6637
plant.mean()                                 # -> 2535.0   hours

The rate is a lever: parameter_sensitivity reports how the system moves with it ("rate", or "reliability.rate" for a repairable component), levers() lists it, from 0 up, and with_levers builds the diagram at another rate. Here each extra start per ten running hours takes about 0.19 off the plant's reliability at 2,000 hours (to first order):

# Needs surpyval's LifeAtUsage (0.28)
plant.parameter_sensitivity(2000)["turbine"]["rate"]       # -> -1.943
plant.with_levers({("turbine", "rate"): 0.1}).sf(2000)     # -> 0.9519

Where a diagram needs a surpyval distribution (a RepairableRBD's exact methods and simulation engines), the block's life is the one the rate gives: every distribution Equivalence takes keeps its family when its time is divided by 1 + k rate, so a Weibull on the combined clock is a Weibull in hours with its scale divided by it. The spec keeps the life at the rate, for its lever and for saving. A "duty" (the share of the calendar it runs) applies on top, the rate being per running hour. A diagram saves the model and the rate, and needs surpyval 0.28 or later to load them. The model on two clocks itself is refused as a block, saying to give model.at_usage(rate).

k-out-of-n nodes

A node with k greater than 1 works only while at least k of its incoming branches are working. Pass k={node: k}:

from repyability import PerfectReliability

#   three pumps, of which two must run, feed a perfect junction "v"
unit = surv.Weibull.from_params([100, 2])
two_of_three = NonRepairableRBD(
    [("s", "a"), ("s", "b"), ("s", "c"),
     ("a", "v"), ("b", "v"), ("c", "v"),
     ("v", "t")],
    {"a": unit, "b": unit, "c": unit, "v": PerfectReliability},
    k={"v": 2},
)
two_of_three.sf(50)   # -> 0.8749   = 3p² − 2p³ with p = unit.sf(50)

k must be a positive integer no larger than the node's number of incoming edges; k equal to that number is allowed but warned about in the structure check (it is just a series arrangement).

One component in several places

Some diagrams need the same physical component in more than one place: a power supply feeding two otherwise separate branches, say. Draw it as two nodes and point the second one's entry at the first node's name instead of at a model. The RBD then treats both as one component, which fails once for both:

from surpyval import FixedEventProbability

#   s -> ps  -> a -> t
#   s -> ps2 -> b -> t        ps2 is the same supply as ps
shared_supply = NonRepairableRBD(
    [("s", "ps"), ("ps", "a"), ("a", "t"),
     ("s", "ps2"), ("ps2", "b"), ("b", "t")],
    {
        "ps": FixedEventProbability.from_params(0.05),
        "ps2": "ps",
        "a": FixedEventProbability.from_params(0.1),
        "b": FixedEventProbability.from_params(0.1),
    },
)
shared_supply.sf()        # -> 0.9405   = 0.95 × (1 − 0.1²)
shared_supply.repeated    # {'ps2': 'ps'}

Treating the two supply nodes as independent would give (1 − 0.05 · 0.1)² = 0.99, a large over-estimate. Each appearance keeps its place in the diagram, its edges and its own k, so the paths are exactly as drawn, and every calculation treats the appearances as the one component: the result is exact however they are arranged. A repeated node cannot be forced working or broken on its own (force the component it repeats), and cannot be a member of a common-cause group. This is different from RepeatedNode, which models n distinct, identical copies.

Nested RBDs

A NonRepairableRBD can be a node of another, so a subsystem can be built and tested once and reused:

pair = NonRepairableRBD(
    [("s", "x"), ("s", "y"), ("x", "t"), ("y", "t")],
    {"x": unit, "y": unit},
)
plant = NonRepairableRBD(
    [("s", "pumps"), ("pumps", "valve"), ("valve", "t")],
    {"pumps": pair, "valve": surv.Weibull.from_params([300, 1.5])},
)
plant.sf(50)          # -> 0.8885
plant.node_names()    # ['pumps', 'valve']

A RepairableRBD can likewise contain RepairableRBD components (see Repairable systems).

Units

A diagram works in one unit throughout: its nodes' lives, the times you ask about, intervals, repair times, rates and costs per unit of time are all in the unit the models were fitted in, whatever it is (hours, cycles, kilometres, demands). Which unit makes no difference to the answers; mixing two does. RePyability converts nothing, so give every node's model in one unit, and every number you type in it too.

A surpyval model can say which unit it is in: fit it (or build it) with unit=, and it keeps the label as model.unit. A diagram reads those labels. When its models name different units, it is built with a warning that names the blocks and their units, because its answers would mix the two; models with no unit say nothing, so a diagram of unlabelled models is as before. Labels are compared as units, so "h", "hrs" and "hours" agree. The diagram keeps its unit as rbd.unit (shown in its printout), and the results it returns carry it as model_unit (and in to_dict()), so a report can say what its times are in. A fault tree, a network and a phased mission read their models' units the same way.

motor = surv.Weibull.from_params([2000, 1.5], unit="hours")
seal = surv.Weibull.from_params([400, 2], unit="days")
drive = [("s", "motor"), ("motor", "seal"), ("seal", "t")]
mixed = NonRepairableRBD(drive, {"motor": motor, "seal": seal})
# UserWarning: The diagram's models are in different units:
# 'hours' for 'motor'; 'days' for 'seal'. ... (mixed.unit is None)

Nothing is converted: rebuild (or refit) the seal in hours, and the warning goes. The diagram and its results then say which unit they are in:

seal = surv.Weibull.from_params([400 * 24, 2], unit="hours")
in_hours = NonRepairableRBD(drive, {"motor": motor, "seal": seal})
in_hours.unit                                  # 'hours'
in_hours.structure_summary().model_unit        # 'hours'

The rest of the numbers you give are in that unit too:

  • Intervals, repair times and costs per time are in the models' unit: a proof-test interval of 1 means one hour if the lives are in hours, not one year. A discount rate is per that unit too (see Costs).
  • A probability per demand (FixedEventProbability) is no life: a RepairableRBD simulates a unit that fails at once with that probability or never, and refuses its long-run and time-dependent values, which have no mean time to work from.
  • A covariate of a RegressionNode is in the unit its model was fitted with: a temperature fitted in kelvin is wrong given in degrees Celsius, and a load-sharing group's load is the group's total. A covariate's zero is its unit's, so differential_importance(change="proportional") refuses one (a uniform change is unaffected).
  • Lives in operating time on a diagram that runs on the calendar: a RepairableRBD component that operates a fraction of the time takes a "duty" (see Repairable systems).
  • A rate of use of a life on two clocks is in its model's units: starts per hour for a model of hours and starts, so per running hour, and the life it gives is in hours.

Validation and the structure check

The constructor checks the diagram and, by default, raises ValueError if it is not a valid RBD. It checks for:

  • cycles;
  • more than one node without predecessors, or more than one without successors;
  • a k below 1, or a k larger than the node's number of inputs, or a k given for a node that is not in the graph (and a k that is not a whole number is refused at once);
  • a node in the edges without a model (but the input and output nodes, which need none; a junction, such as a vote point, takes PerfectReliability), and a model for a name in no edge.

The error lists each problem on a line of its own, and suggests the node a mistyped model was meant for:

ValueError: RBD not correctly structured:
  - node 'pump' (in the edges) has no model
  - model 'pmup' is not a node in the edges; did you mean 'pump'?

Pass on_infeasible_rbd="warn" to get a warning instead, or "ignore" to build it silently, and inspect the findings in structure_check:

broken = NonRepairableRBD(
    [("s", "a"), ("a", "t"), ("b", "t")],   # "b" is a second source
    {"a": unit, "b": unit},
    on_infeasible_rbd="ignore",
)
broken.structure_check["is_valid"]                     # False
broken.structure_check["nodes_with_no_predecessors"]   # ['s', 'b']

structure_check is a dict of findings: is_valid, has_cycles and cycles, nodes_with_no_predecessors / nodes_with_no_successors, nodes_with_no_model and nodes_in_no_edge (models for names in no edge, which are left out of the diagram), koon_errors and koon_warnings, irrelevant_nodes, all_distributions_fixed, and is_analytically_solvable with non_analytic_nodes. An RBD built with errors can give meaningless results; use "warn"/"ignore" to diagnose a diagram, not to analyse it.

Path sets, cut sets and irrelevant nodes

two_of_three.get_min_path_sets(include_in_out_nodes=False)
# {frozenset({'a', 'b', 'v'}), frozenset({'a', 'c', 'v'}),
#  frozenset({'b', 'c', 'v'})}
two_of_three.get_min_cut_sets()
# {frozenset({'a', 'b'}), frozenset({'a', 'c'}),
#  frozenset({'b', 'c'}), frozenset({'v'})}
  • get_min_path_sets(include_in_out_nodes=True) returns the minimal path sets: minimal sets of nodes whose working guarantees the system works. By default each set includes the input and output nodes.
  • get_min_cut_sets(include_in_out_nodes=False) returns the minimal cut sets: minimal sets of nodes whose failure guarantees the system fails.
  • get_all_path_sets() iterates over every simple path from input to output (minimal or not). The number of paths can grow very fast with the size of the diagram.
  • find_irrelevant_components() returns the nodes that appear in no minimal path set: their state never changes whether the system works, which usually means an edge is missing or misplaced.
#   b only ever leads into a, which is reachable directly
redundant_b = NonRepairableRBD(
    [("s", "a"), ("a", "t"), ("s", "b"), ("b", "a")],
    {"a": unit, "b": unit},
)
redundant_b.find_irrelevant_components()   # {'b'}
list(redundant_b.get_all_path_sets())      # [['s', 'a', 't'], ['s', 'b', 'a', 't']]

Path and cut sets depend only on the structure and are computed once per RBD.

How big is the structure?

A large diagram can have far more path or cut sets than you want to list. structure_summary() tells you the size first, from the same reduction that makes the probabilities fast: the reduction folds series chains, parallel groups and k-out-of-n groups into modules, and what it cannot fold (a bridge, say) is the core. A diagram that folds completely is series-parallel.

info = two_of_three.structure_summary()
info.n_components, info.series_parallel   # -> (4, True)
info.n_path_sets, info.n_cut_sets         # -> (3, 4)

The summary also gives how deeply the modules nest (module_depth), how many modules there are (n_modules), and the size of the core (core_size, core_path_sets; both 0 for a series-parallel diagram). count_minimal_path_sets() and count_minimal_cut_sets() give just the counts. Each count is exact unless a component is drawn in more than one place (counts_exact says), when it is an upper bound. A diagram too meshed to work out exactly gives None and says why in too_meshed.

Is the system time-dependent, and is it exact?

  • is_fixed is True when every node is a fixed probability. Then time plays no part: sf() can be called without a time, and methods that invert reliability to a time raise. is_time_varying is its complement.
  • is_analytically_solvable() is False when some node has no exact or numerical reliability: a StandbyModel or LoadSharingModel that only a simulation works out (see their is_simulated), or a repeated node or nested RBD of one. get_non_analytic_nodes() names them. The analyses that need such a node's reliability refuse, and the system's simulations draw its lifetimes.
  • analysis_routes() says how each analysis of the RBD is computed: exactly, numerically, by simulation, or not at all, with the reason and the nodes that decide it (see What is exact and what is simulated).
shared_supply.is_fixed                      # True
plant.is_fixed                              # False
from repyability import StandbyModel
spare = NonRepairableRBD(
    [("s", "sb"), ("sb", "t")], {"sb": StandbyModel([unit, unit])}
)
spare.is_analytically_solvable()            # True: a numerical convolution
two_of_three = NonRepairableRBD(
    [("s", "sb"), ("sb", "t")],
    {"sb": StandbyModel([unit] * 3, k=2, dormancy_factor=0.5)},
)
two_of_three.is_analytically_solvable()     # False: warm, two operating
two_of_three.get_non_analytic_nodes()       # {'sb': 'StandbyModel'}
two_of_three.analysis_routes()["sf"].route  # 'refused'
two_of_three.analysis_routes()["random"].route  # 'simulated'

Low-level building blocks

These are what the higher-level methods are made of; they are public for custom analyses.

  • is_system_working(component_status, method) evaluates the structure function: given {node: True/False} for every node, is the system up?
  • system_probability(node_probabilities, method="p") is the exact engine: given each node's probability of working (a number or an array, all the same length), it returns the probability the system works. It reduces the series, parallel and k-out-of-n parts to closed forms and decomposes only the rest (see Concepts).
  • path_set_probabilities(node_probabilities) returns an array holding, for each minimal path set, the product of its members' probabilities. The entries are not labelled and come in no fixed order; pair them with the sets yourself if you need to know which is which.
status = {"pump1": False, "pump2": True, "valve": True}
rbd.is_system_working(status, "p")                                  # True
rbd.system_probability({"pump1": 0.9, "pump2": 0.9, "valve": 0.95})  # array([0.9405])