Skip to content

The pyFTree is a open source tool that takes a FT model as a python program and spit out minimal cutsets.

License

Notifications You must be signed in to change notification settings

ahmedwaqar/pyFTreetool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

The pyFTreetool is an open source tool that encode a FT model as a python program and generate minimal cutsets.

Installation

Linux

A quick way to install the pyFTreetool as a python package is to follow the following instructions:

  1. At terminal, execute git clone https://github.com/ahmedwaqar/pyFTreetool
  2. cd pyFTreetool && sudo python setup.py install
  3. Install pygraphviz from https://pygraphviz.github.io/documentation/stable/install.html

Documentation

Usage

One of the two approaches can be used to perform FTA using pyFTreetool.

Approach 1: Draw and Analyze

pyFTreetool provides an xml_parser that can take fault tree diagram in an XML format, which is drawn using draw.io, and generates a python program that encodes FT model and outputs minimal cutsets. The choice of draw.io is mainly for its open source features available both in web and desktop version. However, not all the styles of fault tree diagrams should be parsed by xml_parser, there must be some rules lay down so that users can successfully generate python code for a given FT diagram. To learn this approach let us consider an example FT shown in the figure below. The details of each FT node and the resulting cutsets are described in [1].

Composite Laminate Structure

In draw.io, the AND and OR gates can be searched from the keyword gates. The following rules are embedded in the xml_parser:

  1. While drawing an FT diagram, the arrow direction of the edge connection should be downward
  2. Each FT gate should be named and the gate names should follow python variable naming convention
  3. Rectange shape should be used to represent intermediate and leaf nodes
  4. Finally and most importantly, ensure that the edge connections are not loosed
  5. Once FT is drawn, export the diagram as an XML format file

The FT python program and the resulting minimal cutsets can be obtained by issuing the following commands at the terminal:

  • Go to src/ directory
  • chmod a+x pyFTree
  • ./pyFTree -X -i <path-to-xml-file> -o <output-path-for-python-program> -c <output-path-for-cutsets>
  • For example, ./pyFTree -X -i diagrams/example_ft.xml -o output/example_ft.py -c output/example_ft_cutsets.txt

pyFTree automates the parsing of XML FT diagram and the generation of minimal cutsets.

If you wanted to run pyFTree directly on python FT program then:

  • Make sure you have specified the path to src folder and imported FTree in your python FT program
  • In your src/ directory run ./pyFTree -i <path-to-python_FT-program> -c <name-of-cutset-file> The cutset file will be saved in the same directory as python FT program.

Some sample FT programs in the examples folder may be a good starting point.

Approach 2: Code and Analyze

This approach requires famalarity with python programming languge. The starting point is to create a file with .py extension and import FTree from src/ directory. The FTree python script contains class Gates with two basic functions representing basic FT gates and_gate and or_gate. Each FT gate takes an arbitrary set of inputs and return a two-dimensional list. Each sublist of two-dimensional list represent a cutset. The minimal cutsets are obtined using MUCOS algorithm which are encoded in the FT gate functions. The function mcs removes the duplicate nodes and return minimal cutsets. Lastly, pretty_display takes minimal cutsets and print it nicely on a console.

Many examples are provided in the examples/ folder to learn the different ways of encoding a FT diagram using basic and_gate and or_gate functions.

It may be desirable to generate FT from the given FT python program in this approach. A FT_parser is provided to fulfill the need. Consider the following FT python program:


import FTree as ft

if __name__ == "__main__":
    z = ft.Gates()
    G1 = z.and_gate([["PT1"]], [["PT2"]])
    G2 = z.and_gate([["PT1"]], [["PT3"]])
    G3 = z.and_gate([["PT3"]], [["PT2"]])
    G4 = z.or_gate(G1, z.or_gate(G2, G3))
    G5 = z.or_gate([["SDV1"]], [["SDV2"]])
    top = z.or_gate(G4, z.or_gate([["LS"]], G5))
    print(top)
    mcs = z.mcs(top)
    z.pretty_display(mcs)

The FT diagram can be generated by issuing the command ./FT_parser examples/ft_program2.py in the Linux terminal. The resulting FT diagram is shown in the figure below.

Example FT diagram generated from python program

Note FT_parser may contains several bugs and not always generate aesthetically nice diagram.

Disclaimer Its a fun project and in an early stage of the development. The FTree.py and FT_parser.py expectedly contains bugs that would be uncovered as the project goes to the next stages.

Contributions: The suggestions/contributions are welcome and could be pushed in through pull request. A feature request can also be made by opening issues.

References

[1] Chen, Xi, He Ren, and Cees Bil. "Fault tree analysis for composite structural damages." Proceedings of the Institution of Mechanical Engineers, Part G: Journal of Aerospace Engineering 228.9 (2014): 1466-1474.

About

The pyFTree is a open source tool that takes a FT model as a python program and spit out minimal cutsets.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages