mbdlyb.functional.base
Base classes for functional analysis models.
This module defines the core node types and dependency relations for functional analysis in model-based diagnosis systems. It includes:
FunctionalNode: Base class for all functional model nodes
OperatingMode: Represents system operating modes
Function: Represents system functions
Hardware: Represents hardware components
DirectObservable: Represents directly observable phenomena
ObservedError: Represents observed error codes
DiagnosticTest: Represents diagnostic tests
DiagnosticTestResult: Represents diagnostic test results
Cluster: Container for a functional model network
FunctionalDependency: Base class for dependency relations
Various relation types: RealizesRelation, RequiredForRelation, AffectsRelation, etc.
ClusterReasonerView: Reasoner view for functional clusters
The module integrates with multiple reasoning engines (Bayesian networks, Tensor networks, Markov networks) to support probabilistic fault diagnosis and failure analysis.
Classes
Relation indicating that hardware degradation affects function operation. |
|
Container for a functional model network. |
|
Specialized reasoner view for functional clusters. |
|
Relation representing inter-function communication carrying error information. |
|
Represents a diagnostic test that can be performed on the system. |
|
Represents the result or output of a diagnostic test. |
|
Represents a directly observable phenomenon. |
|
Represents a function in the system model. |
|
Base class for dependency relations in functional models. |
|
Base class for all nodes in functional models. |
|
Represents a hardware component in the system model. |
|
Relation indicating that a test result indicates node state. |
|
Base class for observable nodes in functional models. |
|
Relation indicating observation of a node state. |
|
Represents an observed error code or failure indication. |
|
Represents an operating mode of a system. |
|
Relation indicating that a hardware component realizes a function. |
|
Relation indicating that a function enables error reporting. |
|
Relation indicating functional dependency between two functions. |
|
Relation indicating that a diagnostic test produces a result. |
|
Relation indicating that a function operates in a specific operating mode. |
|
Relation representing functional decomposition hierarchy. |
|
Relation indicating that a function failure yields an error code. |
Module Contents
- class mbdlyb.functional.base.AffectsRelation(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation indicating that hardware degradation affects function operation.
- Variables:
- class mbdlyb.functional.base.Cluster(name: str, cluster: Cluster | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BayesNet,mbdlyb.formalisms.tensornet.TensorNet,mbdlyb.formalisms.markovnet.MarkovNet,mbdlyb.MBDNetContainer for a functional model network.
A cluster is a directed acyclic graph (DAG) containing functional nodes (functions, hardware, observables, etc.) and dependency relations. Clusters support multiple reasoning engines (Bayesian, Tensor, Markov networks) and operating mode management.
- Variables:
elements (dict[str, Union[FunctionalNode, Cluster]]) – Named elements in this cluster.
_opmsets (dict[OpmSet, MBDNode]) – Mapping from operating mode sets to their nodes.
relations (list[FunctionalDependency]) – All dependency relations in the cluster.
- add_element(element: mbdlyb.MBDElement)
Add an element to this cluster.
If the element is an OperatingMode, registers it in the operating mode set mapping.
- Parameters:
element (MBDElement) – Element to add to the cluster.
- create_reasoner_view() mbdlyb.MBDNetReasonerView
Create a reasoner view for this cluster.
- Returns:
A ClusterReasonerView instance.
- Return type:
- filter_operating_modes(operating_modes: list[str]) tuple[set[mbdlyb.MBDNode], set[FunctionalDependency]]
Filter the model to only include active operating modes.
Removes nodes and relations that are disabled by the selected operating modes in a 5-step process: 1. Remove disabled dependency relations 2. Remove test-result nodes with removed indicated-by/yields-error relations 3. Remove function nodes with removed subfunction relations 4. Remove isolated nodes without any relations 5. Remove diagnostic tests without results
- Parameters:
operating_modes (list[str]) – List of operating mode names that are active.
- Returns:
Removed nodes and relations.
- Return type:
tuple[set[MBDNode], set[FunctionalDependency]]
- get_all_opm_nodes() dict[mbdlyb.functional.operating_mode.OpmSet, mbdlyb.MBDNode]
Get all operating mode nodes in this cluster.
- get_opm_node(fqn: mbdlyb.fqn.FQN) mbdlyb.MBDNode | None
Get an operating mode node by its fully qualified name.
- get_opm_node_from_set(opm_set: mbdlyb.functional.operating_mode.OpmSet) mbdlyb.MBDNode | None
Get the operating mode node for a specific OpmSet.
- propagate_operating_modes(verbose=False)
Propagate operating mode constraints throughout the model.
Infers operating modes on dependency relations through four propagation steps: 1. Propagate between function nodes via required-for and subfunction relations 2. Propagate from functions to hardware via realizes and affects relations 3. Propagate from yields-error to reports-error relations 4. Propagate from indicated-by to results-in relations
- Parameters:
verbose (bool) – If True, print inferred operating modes. Defaults to False.
- elements: dict[str, FunctionalNode | Cluster]
- relations: list[FunctionalDependency]
- class mbdlyb.functional.base.ClusterReasonerView(net: Cluster)
Bases:
mbdlyb.MBDNetReasonerViewSpecialized reasoner view for functional clusters.
Performs model transformations to make functional clusters suitable for probabilistic reasoning, including cycle elimination, functional decomposition handling, and error reporting unfolding.
- Variables:
net (Cluster) – The cluster being reasoned over.
_dropped_functional_decomposition_functions (list[Function]) – Functions removed during decomposition cleaning.
_dropped_functional_decomposition_relations (list[SubfunctionOfRelation]) – Relations removed during decomposition cleaning.
_cycles (list[list[Function]]) – Detected cycles in function dependencies.
_cycle_functions (list[Optional[Function]]) – Cycle placeholders.
_cycle_relations (list[Optional[RequiredForRelation]]) – Cycle relation placeholders.
_duplicated_reporting_functions (dict[Function, set[Function]]) – Duplicated reporting functions.
_duplicated_reporting_chains (dict[RequiredForRelation, set[RequiredForRelation]]) – Duplicated chains.
_duplicated_reporting_dependencies (dict[FunctionalDependency, set[FunctionalDependency]]) – Duplicated dependencies.
- class mbdlyb.functional.base.CommunicatesThroughRelation(source: mbdlyb.MBDNode, target: mbdlyb.MBDNode, error_codes: list[ObservedError] | None = None, weight: float = 1.0, net: Cluster | None = None)
Bases:
FunctionalDependencyRelation representing inter-function communication carrying error information.
Represents error propagation through communication between functions.
- Variables:
_label (str) – ‘communicates_through’
_error_codes (list[ObservedError]) – Error codes propagating through communication.
source (Function) – The communicating function.
target (Function) – The function receiving communication.
- create()
Create this relation and register error codes.
Adds this relation to the observation paths of its error codes.
- remove()
Remove this relation and unregister error codes.
Removes this relation from the observation paths of its error codes.
- property error_codes: list[ObservedError]
Get the error codes propagating through this communication.
- Returns:
Error codes carried by this communication.
- Return type:
list[ObservedError]
- property label: str
Get label with associated error codes.
- Returns:
Label including error code list.
- Return type:
str
- class mbdlyb.functional.base.DiagnosticTest(name: str, fixed_cost: dict[str, float], preconditions: dict[str, bool], cluster: Cluster)
Bases:
FunctionalNodeRepresents a diagnostic test that can be performed on the system.
Diagnostic tests are actions taken to evaluate the state of functions and hardware. They have fixed costs and preconditions required before execution.
- Variables:
fixed_cost (dict[str, float]) – Fixed costs by type (e.g., ‘time’, ‘money’).
preconditions (dict[str, bool]) – Conditions required for test execution.
- get_fixed_cost(cost_type: str | None = None) float
Get the fixed cost of performing this diagnostic test.
If cost_type is specified, returns only that cost type. Otherwise returns the sum of all cost types.
- Parameters:
cost_type (Optional[str]) – Specific cost type to retrieve. Defaults to None.
- Returns:
The fixed cost value or sum of costs.
- Return type:
float
- fixed_cost: dict[str, float]
- preconditions: dict[str, bool]
- property test_results: list[DiagnosticTestResult]
Get all results produced by this diagnostic test.
- Returns:
Test result nodes related via ResultsInRelation.
- Return type:
list[DiagnosticTestResult]
- class mbdlyb.functional.base.DiagnosticTestResult(name: str, states: list[str], fp_rate: float, fn_rate: float, cluster: Cluster)
Bases:
ObservableNodeRepresents the result or output of a diagnostic test.
Test results are observations that show whether a diagnostic test passed or failed. They are produced by DiagnosticTest nodes.
- property test: DiagnosticTest
Get the diagnostic test that produces this result.
- Returns:
The test node related via ResultsInRelation.
- Return type:
- class mbdlyb.functional.base.DirectObservable(name: str, states: list[str], fp_rate: float, fn_rate: float, cluster: Cluster)
Bases:
ObservableNodeRepresents a directly observable phenomenon.
Direct observables are measurements or observations that directly indicate the state of system components.
- class mbdlyb.functional.base.Function(name: str, states: list[str], cluster: Cluster)
Bases:
mbdlyb.formalisms.bayesnet.BayesAutoSplitNode,mbdlyb.formalisms.tensornet.TensorAutoSplitNode,mbdlyb.formalisms.markovnet.MarkovAutoSplitNode,FunctionalNodeRepresents a function in the system model.
Functions are the core elements of functional models, representing capabilities or behaviors that the system can perform. Functions can have subfunctions (functional decomposition) and can realize hardware components.
- Variables:
DEFAULT_STATES (list[str]) – Default states [‘Ok’, ‘NOk’].
_split_preserve_classes (list) – Classes to preserve during splitting (OperatingMode).
false_positive_weight (float) – Weight for false positive errors.
- superfunction_chain(as_fqn: bool = False) list[list[Function | mbdlyb.fqn.FQN]]
Get all chains of superfunctions up to root functions.
- valid_parent_relation(relation: mbdlyb.MBDDependency) bool
Validate if a dependency relation is valid for this function.
- Parameters:
relation (MBDDependency) – The dependency relation to validate.
- Returns:
- True if relation is a FunctionalDependency or a normalized
numerical node relation.
- Return type:
bool
- DEFAULT_STATES = ['Ok', 'NOk']
- false_positive_weight: float = 0.0
- property has_subfunctions: bool
Check if this function has subfunctions.
- Returns:
True if this function has any subfunction_of relations.
- Return type:
bool
- property has_superfunctions: bool
Check if this function has superfunctions.
- Returns:
True if this function is a subfunction of other functions.
- Return type:
bool
- class mbdlyb.functional.base.FunctionalDependency(source: mbdlyb.MBDNode, target: mbdlyb.MBDNode, weight: float = 1.0, net: Cluster | None = None, operating_modes: mbdlyb.functional.operating_mode.OpmLogic | None = None)
Bases:
mbdlyb.MBDDependencyBase class for dependency relations in functional models.
Represents dependencies between functional nodes with optional operating mode constraints and weights. Supports both explicit and inferred operating modes.
- Variables:
- set_inferred_operating_modes(operating_modes: mbdlyb.functional.operating_mode.OpmLogic)
Set the inferred operating mode constraints.
- Parameters:
operating_modes (OpmLogic) – The inferred operating mode constraints.
- property inferred_operating_modes: mbdlyb.functional.operating_mode.OpmLogic
Get the inferred operating mode constraints.
- Returns:
Inferred operating mode logic expression.
- Return type:
- property label: str
Get the label for this dependency.
Includes explicit or inferred operating mode constraints if present.
- Returns:
Label string, optionally with operating mode constraints.
- Return type:
str
- property operating_modes: mbdlyb.functional.operating_mode.OpmLogic
Get the explicit operating mode constraints.
- Returns:
Operating mode logic expression.
- Return type:
- weight: float = 1.0
- class mbdlyb.functional.base.FunctionalNode(name: str, states: list[T], net: MBDNet)
Bases:
mbdlyb.MBDNodeBase class for all nodes in functional models.
Functional nodes are the basic building blocks of functional models and represent various aspects of a system such as functions, hardware, observables, and tests. All functional nodes support operating modes.
- Variables:
DEFAULT_STATES (list[str]) – Default state values for this node type.
_EQ_MAP (dict) – Mapping from node class names to equivalent/ok states.
_operating_modes (OpmSet) – The operating modes applicable to this node.
parent_relations (set[FunctionalDependency]) – Incoming dependency relations.
child_relations (set[FunctionalDependency]) – Outgoing dependency relations.
- set_operating_modes(operating_modes: mbdlyb.functional.operating_mode.OpmSet)
Set the operating modes for this node.
- Parameters:
operating_modes (OpmSet) – Operating modes to assign to this node.
- DEFAULT_STATES: list[str] = []
- child_relations: set[FunctionalDependency]
- property operating_modes: mbdlyb.functional.operating_mode.OpmSet
Get the operating modes for this node.
- Returns:
Set of operating modes.
- Return type:
- parent_relations: set[FunctionalDependency]
- class mbdlyb.functional.base.Hardware(name: str, fault_rates: dict[str, float], cluster: Cluster)
Bases:
mbdlyb.formalisms.bayesnet.BayesNode,mbdlyb.formalisms.tensornet.TensorNode,mbdlyb.formalisms.markovnet.MarkovNode,FunctionalNodeRepresents a hardware component in the system model.
Hardware components have failure modes with associated fault rates. They can realize one or more functions in the system.
- Variables:
DEFAULT_STATES (list[str]) – Default states with ‘Healthy’ as the only state.
fault_rates (dict[str, float]) – Mapping from fault state names to fault rates.
- DEFAULT_STATES = ['Healthy']
- fault_rates: dict[str, float]
- property is_elementary: bool
Check if this hardware is elementary (has no subfunctions).
- Returns:
True if this hardware realizes only functions without subfunctions.
- Return type:
bool
- class mbdlyb.functional.base.IndicatedByRelation(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation indicating that a test result indicates node state.
- Variables:
_label (str) – ‘indicated_by’
source (Union[Hardware, Function]) – The indicated component.
target (DiagnosticTestResult) – The test result indicating state.
- target: DiagnosticTestResult
- class mbdlyb.functional.base.ObservableNode(name: str, states: list[str], fp_rate: float, fn_rate: float, cluster: Cluster)
Bases:
mbdlyb.formalisms.bayesnet.BayesNode,mbdlyb.formalisms.tensornet.TensorNode,mbdlyb.formalisms.markovnet.MarkovNode,FunctionalNodeBase class for observable nodes in functional models.
Observable nodes represent phenomena that can be observed or measured to assess the state of functions and hardware. They have false positive and false negative rates.
- Variables:
DEFAULT_STATES (list[str]) – Default states [‘Ok’, ‘NOk’].
fp_rate (float) – False positive rate (observing failure when healthy).
fn_rate (float) – False negative rate (not observing failure when faulty).
- DEFAULT_STATES = ['Ok', 'NOk']
- fn_rate: float = 0.0
- fp_rate: float = 0.0
- class mbdlyb.functional.base.ObservedByRelation(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation indicating observation of a node state.
- Variables:
_label (str) – ‘observed_by’
source (Union[Hardware, Function]) – The observed component.
target (DirectObservable) – The observable indicating its state.
- target: DirectObservable
- class mbdlyb.functional.base.ObservedError(name: str, states: list[str], fp_rate: float, fn_rate: float, error_code: str, cluster: Cluster)
Bases:
DirectObservableRepresents an observed error code or failure indication.
Observed errors are error codes or indicators that show when functions have failed. They have an associated error code identifier and can be observed through various observation paths (required-for and communicates-through relations).
- Variables:
DEFAULT_STATES (list[str]) – Default states [‘Absent’, ‘Present’].
error_code (str) – Unique identifier for this error code.
observation_path (set) – Relations through which this error can be observed.
- DEFAULT_STATES = ['Absent', 'Present']
- property enabling_functions: list[Function]
Get functions that must be Ok to enable error reporting.
- Returns:
Functions related via ReportsErrorRelation.
- Return type:
list[Function]
- error_code: str
- observation_path: set[RequiredForRelation | CommunicatesThroughRelation]
- class mbdlyb.functional.base.OperatingMode(name: str, operating_modes: list[str], cluster: Cluster)
Bases:
mbdlyb.formalisms.bayesnet.BayesNode,mbdlyb.formalisms.tensornet.TensorNode,mbdlyb.formalisms.markovnet.MarkovNode,FunctionalNodeRepresents an operating mode of a system.
Operating modes define different states or configurations in which a system can operate. Each mode represents a mutually exclusive set of possible values.
- Variables:
opm_set (OpmSet) – The set of operating mode values.
- class mbdlyb.functional.base.RealizesRelation(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation indicating that a hardware component realizes a function.
- Variables:
- class mbdlyb.functional.base.ReportsErrorRelation(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation indicating that a function enables error reporting.
- Variables:
_label (str) – ‘reports_error’
source (Function) – The enabling function.
target (ObservedError) – The error code being reported.
- target: ObservedError
- class mbdlyb.functional.base.RequiredForRelation(source: mbdlyb.MBDNode, target: mbdlyb.MBDNode, operating_modes: mbdlyb.functional.operating_mode.OpmLogic | None = None, error_codes: list[ObservedError] | None = None, weight: float = 1.0, net: Cluster | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation indicating functional dependency between two functions.
Represents that one function must work for another to work. Can track error codes that propagate through this dependency.
- Variables:
_label (str) – ‘required_for’
source (Function) – The required function.
target (Function) – The dependent function.
error_codes (list[ObservedError]) – Error codes propagating through this relation.
- create()
Create this relation and register error codes.
Adds this relation to the observation paths of its error codes.
- remove()
Remove this relation and unregister error codes.
Removes this relation from the observation paths of its error codes.
- error_codes: list[ObservedError]
- property label: str
Get label with associated error codes.
- Returns:
Label including error code indicators.
- Return type:
str
- class mbdlyb.functional.base.ResultsInRelation(source: mbdlyb.MBDNode, target: mbdlyb.MBDNode, weight: float = 1.0, net: Cluster | None = None, operating_modes: mbdlyb.functional.operating_mode.OpmLogic | None = None)
Bases:
FunctionalDependencyRelation indicating that a diagnostic test produces a result.
- Variables:
_label (str) – ‘results_in’
source (DiagnosticTest) – The test.
target (DiagnosticTestResult) – The result.
- source: DiagnosticTest
- target: DiagnosticTestResult
- class mbdlyb.functional.base.SelectOperatingModeRelation(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation indicating that a function operates in a specific operating mode.
- Variables:
_label (str) – ‘select’
source (OperatingMode) – The operating mode.
target (Function) – The function operating in this mode.
- source: OperatingMode
- class mbdlyb.functional.base.SubfunctionOfRelation(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation representing functional decomposition hierarchy.
- Variables:
- class mbdlyb.functional.base.YieldsErrorRelation(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.formalisms.bayesnet.BNDependency,mbdlyb.formalisms.tensornet.TNDependency,mbdlyb.formalisms.markovnet.MNDependency,FunctionalDependencyRelation indicating that a function failure yields an error code.
- Variables:
_label (str) – ‘yields_errors’
source (Function) – The function that yields the error.
target (ObservedError) – The error code yielded.
- target: ObservedError