Skip to content

system_base

Orchestrates the safety analysis and coordinates visualization via observers.

SystemBase

Bases: ABC

Abstract base class for a safety system model.

It manages the system layout, triggers FIT rate calculations, and handles the generation of architectural visualizations.

Source code in src/ecc_analyzer/system_base.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class SystemBase(ABC):
    """Abstract base class for a safety system model.

    It manages the system layout, triggers FIT rate calculations, and
    handles the generation of architectural visualizations.
    """

    def __init__(self, name: str, total_fit: float):
        """Initializes the system orchestrator.

        Args:
            name (str): The descriptive name of the system (e.g., "LPDDR4_System").
            total_fit (float): The total FIT rate used as the baseline for metric calculations.
        """
        self.name = name
        self.total_fit = total_fit
        self.system_layout = None
        self.asil_block = AsilBlock("Final_Evaluation")
        self.configure_system()

    @abstractmethod
    def configure_system(self):
        """Abstract method to define the internal hardware structure.

        Must be implemented by subclasses to set the `self.system_layout`.
        """
        pass

    def run_analysis(self) -> dict[str, Any]:
        """Performs a pure mathematical FIT calculation across the system.

        No visualization is triggered during this call.

        Returns:
            dict[str, Any]: A dictionary containing calculated metrics (SPFM, LFM, ASIL level).

        Raises:
            ValueError: If `configure_system` has not set a valid system layout.
        """
        if not self.system_layout:
            raise ValueError("System layout is not configured.")

        final_spfm, final_lfm = self.system_layout.compute_fit({}, {})

        return self.asil_block.compute_metrics(self.total_fit, final_spfm, final_lfm)

    def generate_pdf(self, filename: Optional[str] = None) -> dict[str, Any]:
        """Executes the analysis while simultaneously generating a PDF visualization.

        Uses the Observer Pattern to decouple logic from Graphviz commands.

        Args:
            filename (Optional[str]): Optional name for the output file.
                Defaults to "output_<system_name>".

        Returns:
            dict[str, Any]: The final system metrics dictionary.
        """
        if filename is None:
            filename = f"output_{self.name}"

        visualizer = SafetyVisualizer(self.name)

        observable_layout = ObservableBlock(self.system_layout)
        observable_layout.attach(visualizer)

        final_spfm, final_lfm, last_ports = observable_layout.run({}, {}, {})

        visualizer.on_block_computed(
            self.asil_block,
            last_ports,
            final_spfm,
            final_lfm,
            final_spfm,
            final_lfm,
        )

        visualizer.render(filename)

        return self.asil_block.compute_metrics(self.total_fit, final_spfm, final_lfm)

__init__(name, total_fit)

Initializes the system orchestrator.

Parameters:

Name Type Description Default
name str

The descriptive name of the system (e.g., "LPDDR4_System").

required
total_fit float

The total FIT rate used as the baseline for metric calculations.

required
Source code in src/ecc_analyzer/system_base.py
19
20
21
22
23
24
25
26
27
28
29
30
def __init__(self, name: str, total_fit: float):
    """Initializes the system orchestrator.

    Args:
        name (str): The descriptive name of the system (e.g., "LPDDR4_System").
        total_fit (float): The total FIT rate used as the baseline for metric calculations.
    """
    self.name = name
    self.total_fit = total_fit
    self.system_layout = None
    self.asil_block = AsilBlock("Final_Evaluation")
    self.configure_system()

configure_system() abstractmethod

Abstract method to define the internal hardware structure.

Must be implemented by subclasses to set the self.system_layout.

Source code in src/ecc_analyzer/system_base.py
32
33
34
35
36
37
38
@abstractmethod
def configure_system(self):
    """Abstract method to define the internal hardware structure.

    Must be implemented by subclasses to set the `self.system_layout`.
    """
    pass

generate_pdf(filename=None)

Executes the analysis while simultaneously generating a PDF visualization.

Uses the Observer Pattern to decouple logic from Graphviz commands.

Parameters:

Name Type Description Default
filename Optional[str]

Optional name for the output file. Defaults to "output_".

None

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The final system metrics dictionary.

Source code in src/ecc_analyzer/system_base.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def generate_pdf(self, filename: Optional[str] = None) -> dict[str, Any]:
    """Executes the analysis while simultaneously generating a PDF visualization.

    Uses the Observer Pattern to decouple logic from Graphviz commands.

    Args:
        filename (Optional[str]): Optional name for the output file.
            Defaults to "output_<system_name>".

    Returns:
        dict[str, Any]: The final system metrics dictionary.
    """
    if filename is None:
        filename = f"output_{self.name}"

    visualizer = SafetyVisualizer(self.name)

    observable_layout = ObservableBlock(self.system_layout)
    observable_layout.attach(visualizer)

    final_spfm, final_lfm, last_ports = observable_layout.run({}, {}, {})

    visualizer.on_block_computed(
        self.asil_block,
        last_ports,
        final_spfm,
        final_lfm,
        final_spfm,
        final_lfm,
    )

    visualizer.render(filename)

    return self.asil_block.compute_metrics(self.total_fit, final_spfm, final_lfm)

run_analysis()

Performs a pure mathematical FIT calculation across the system.

No visualization is triggered during this call.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: A dictionary containing calculated metrics (SPFM, LFM, ASIL level).

Raises:

Type Description
ValueError

If configure_system has not set a valid system layout.

Source code in src/ecc_analyzer/system_base.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def run_analysis(self) -> dict[str, Any]:
    """Performs a pure mathematical FIT calculation across the system.

    No visualization is triggered during this call.

    Returns:
        dict[str, Any]: A dictionary containing calculated metrics (SPFM, LFM, ASIL level).

    Raises:
        ValueError: If `configure_system` has not set a valid system layout.
    """
    if not self.system_layout:
        raise ValueError("System layout is not configured.")

    final_spfm, final_lfm = self.system_layout.compute_fit({}, {})

    return self.asil_block.compute_metrics(self.total_fit, final_spfm, final_lfm)