Function Reference

To use se-lib, first import it before using any functions:

import selib

These function definitions follow the convention whereby required input parameters are shown first, then optional parameters are shown with an equal sign indicating the default values. A graph here is a generic set of nodes representing system elements connected by edges shown as non-directed or directed lines.

Diagrams

context_diagram

selib.context_diagram(system, external_systems, filename=None, format='svg', engine='neato')

Returns a context diagram.

Parameters:
  • system_name (string) – The name of the system to label the diagram.

  • external_systems (list of strings) – Names of the external systems that interact with the system in a list.

  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

g – Save the graph source code to file, and open the rendered result in its default viewing application. PyML calls the Graphviz API for this.

Return type:

graph object view

critical_path_diagram

selib.critical_path_diagram(tasks, task_dependencies, filename=None, format='svg')

Compute and draw the critical path between dependent tasks as the longest in duration from start to finish.

Parameters:
  • tasks (list of tuples where each contains a task name and dictionary for duration time) – A list of tuples where each one contains a task name and dictionary for its duration time (where keyword = “Duration” and value is a number).

  • task_dependencies (list of tuples) – A list of tuples describing the dependency relationships between tasks. Each relationship is a tuple containing the predecessor task followed by its successor task. These must be the same named tasks in the task list input above.

  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

g – The rendered graph for display. It will be automatically displayed in Jupyter Notebooks or IPython consoles. With other Python editors it can be displayed in the associated console by typing the returned graph name (e.g., call the function with an assignment such as critical_path = critical_path_diagram(...) and then type critical_path in the console). If a filename is optionally provided, the rendered graph will also be saved as a file in the specified format. PyML calls the Graphviz API for this.

Return type:

graph object view

design_structure_matrix

selib.design_structure_matrix(elements, element_dependencies, filename=None, format='svg')

Draw a design structure matrix of system elements and their dependencies. Matrix elements may represent tasks (process activities), system parameters or attributes.

Parameters:
  • elements (list of strings) – Names of the matrix elements as the row and column headings in a list.

  • element_dependencies (list of tuples) – A list of tuples describing the relationships between elements. Each relationship is a tuple containing the relationship input element, output element and optionally a custom label (or other object) to mark the relationship in the form (“input element”, “output element”, “relationship label”). The default marking denoting a relationship is an uppercase ‘X’, therefore, the shortened tuple relationship (“input element”, “output element”) is equivalent to (“input element”, “output element”, “X”). A custom label can be specified as html code for styling of the font type, font color, cell color, etc. Images and unicode characters can be inserted this way, or other html markup for lists, tables, etc.

  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

g – The rendered graph for display. It will be automatically displayed in Jupyter Notebooks or IPython consoles. With other Python editors it can be displayed in the associated console by typing the returned graph name (e.g., call the function with an assignment such as dsm = design_structure_matrix(...) and then type dsm in the console). If a filename is optionally provided, the rendered graph will also be saved as a file in the specified format. PyML calls the Graphviz API for this.

Return type:

graph object view

fault_tree_diagram

selib.fault_tree_diagram(ft, filename=None, format='svg')

Returns a fault tree diagram.

Parameters:
  • ft (list of tuples) –

    A list of the faults as a tree hierarchy. Each fault is defined in a tuple containing the fault name, type, and underlying faults (if any) in the form ("fault name", "fault name", list of fault branches) with the branches as a list in the form ["branch 1 name", "branch 2 name", ... "branch n name"] to identify the adjoining faults. All basic events will have a blank list [] since they are the bottom leaves in the tree.

    The top event must be in the first row, but all other events can be in any order. They may begrouped by their event paths or by hierarchical levels as convenient. Event types can be conditional “and”s, conditional “or”s, or basic events (leaves). The following spellings are recognized as valid designations for event types:

    And: “And” “and” “AND”

    Or: “Or” “or” “OR”

    Basic: “Basic” “basic” “BASIC”

  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

g – Save the graph source code to file, and open the rendered result in its default viewing application. PyML calls the Graphviz API for this.

Return type:

graph object view

sequence_diagram

selib.sequence_diagram(system_name, actors, objects, actions, filename=None, format='svg')

Returns a sequence diagram.

Parameters:
  • system_name (string) – The name of the system to label the diagram.

  • actors (list of strings) – Names of the outside actors that participate in the activity sequence in a list.

  • objects (list of strings) – Names of the system objects that participate in the activity sequence in a list.

  • actions (list of tuples) – A chronologically ordered list describing the sequence of actions to be drawn. Each action is a tuple containing the action source, target and action name (or data/control passed) in the form (“source”, “target”, “action name”) indicating a labeled horizontal arrow drawn between them.

  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

g – Save the graph source code to file, and open the rendered result in its default viewing application. PyML calls the Graphviz API for this.

Return type:

graph object view

use_case_diagram

selib.use_case_diagram(system_name, actors, use_cases, interactions, use_case_relationships, filename=None, format='svg')

Draw a use case diagram.

Parameters:
  • system_name (string) – The name of the system to label the diagram.

  • actors (list of strings) – Names of the outside actors that interact with the system in the use cases in a list.

  • use_cases (list of strings) – Names of the use cases in a list.

  • interactions (list of tuples) – A list of the interactions to be drawn between actors and use cases. Each interaction is a tuple containing an actor and use case in the form (“actor name”, “use case name”) indicating an arrow drawn from the actor to the use case. Interactions are graph edges.

  • use_case_relationships (list of tuples, optional) – A list of the relationships, or associations to be drawn between use cases. Each relationship is a tuple containing a use case pair and type relationship in the form (“use case 1”, “use case 2”, “relationship”) indicating an arrow drawn from the first to the second use case. Relationship types are “<<include>>”, “<<extend>>” and “generalization”.

  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

g – Save the graph source code to file, and open the rendered result in its default viewing application. PyML calls the Graphviz API for this.

Return type:

graph object view

wbs_diagram

selib.wbs_diagram(decompositions, filename=None, format='svg', rankdir='TB')

Draw a work breakdown structure as a tree hierarchy. Decompositions describe the parent-child relationships.

Parameters:
  • decompositions (list of tuples) – A list of tuples describing the work decomposition relationships. Each relationship is a tuple containing the parent element followed by the child element.

  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

  • rankdir (string, optional) – The direction to display the tree from the parent node. The default rankdir='TB' denotes top to bottom for a vertical tree decomposition. It can diagrammed horizontally by providing rankdir=’LR’ to designate left to right.

Returns:

g – The rendered graph for display. It will be automatically displayed in Jupyter Notebooks or IPython consoles. With other Python editors it can be displayed in the associated console by typing the returned graph name (e.g., call the function with an assignment such as wbs = wbs_diagram(...) and then type wbs in the console). If a filename is optionally provided, the rendered graph will also be saved as a file in the specified format. PyML calls the Graphviz API for this.

Return type:

graph object view

Analyses

fault_tree_cutsets

selib.fault_tree_cutsets(fault_tree)

Returns a fault tree cutset.

Parameters:
  • ft (list of tuples) –

    A list of the faults as a tree hierarchy. Each fault is defined in a tuple containing the fault name, type, and underlying faults (if any) in the form ("fault name", "fault name", list of fault branches) with the branches as a list in the form ["branch 1 name", "branch 2 name", ... "branch n name"] to identify the adjoining faults. All basic events will have a blank list [] since they are the bottom leaves in the tree.

    The top event must be in the first row, but all other events can be in any order. They may begrouped by their event paths or by hierarchical levels as convenient. Event types can be conditional “and”s, conditional “or”s, or basic events (leaves). The following spellings are recognized as valid designations for event types:

    And: “And” “and” “AND”

    Or: “Or” “or” “OR”

    Basic: “Basic” “basic” “BASIC”

  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

cutsets – Returns a list of cutsets, where each is defined as a list of events.

Return type:

list of lists

Simulations

System Dynamics

init_sd_model

selib.init_sd_model(start, stop, dt)

Instantiates a system dynamics model for simulation

add_stock

selib.add_stock(name, initial, inflows=[], outflows=[])

Adds a stock to the model

Parameters:
  • name (str) – The name of the stock

  • initial (float) – Initial value of stock at start of simulation

  • inflows (list of float) – The names of the inflows to the stock

  • outflows (list of float) – The names of the outflows to the stock

add_flow

selib.add_flow(name, equation, inputs=[])

Adds a flow to the model

Parameters:
  • name (str) – The name of the flow

  • equation (str) – Equation for the flow using other named model variables

  • inputs (list) – Optional list of variable input names used to draw model diagram

add_auxiliary

selib.add_auxiliary(name, equation, inputs=[])

Adds auxiliary equation or constant to the model

Parameters:
  • name (str) – The name of the auxiliary

  • equation (str) – Equation for the auxiliary using other named model variables

  • inputs (list) – Optional list of variable input names used to draw model diagram

plot_graph

selib.plot_graph(*outputs)

displays matplotlib graph for each model variable

Parameters:

variables (str or list) – comma separated variable name(s) or lists of variable names to plot on single graphs

Return type:

matplotlib graph

save_graph

selib.save_graph(*outputs, filename='graph.png')

save graph to file

Parameters:
  • variables (variable name or list of variable names to plot on graph) –

  • filename (file name with format extension) –

run_model

selib.run_model(verbose=True)

Executes the current model

Returns:

  • If continuous, returns 1) Pandas dataframe containing run outputs for each variable each timestep and 2) model dictionary.

  • If discrete, returns 1) network dictionary with run statistics and 2) entity run data

set_logical_run_time

selib.set_logical_run_time(condition)

Enables a run time to be measured based on a logical condition for when the simulation should be run (like a while statement). The logical end time will be available from the ‘get_logical_end_time()’ function in lieu of the fixed end time for a simulation.

get_logical_end_time

selib.get_logical_end_time()

Returns the logical end time as specified in a previous ‘set_logical_run_time()’ function call, in lieu of the fixed end time for a simulation.

Returns:

logical_end_time – end time when the ‘set_logical_run_time()’’ condition expires

Return type:

float

draw_model_diagram

selib.draw_model_diagram(filename=None, format='svg')

Draw a diagram of the current model.

Parameters:
  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

g – Save the graph source code to file, and open the rendered result in its default viewing application. se-lib calls the Graphviz API for this.

Return type:

graph object view

Discrete Event

init_de_model

selib.init_de_model()

Instantiates a discrete event model for simulation

add_source

selib.add_source(name, entity_name, num_entities, connections, interarrival_time)

Add a source node to a discrete event model to generate entities.

Parameters:
  • name (string) – A name for the source.

  • entity_name (string) – A name for the type of entity being generated.

  • num_entities (integer) – Number of entities to generated.

  • connections (dictionary) – A dictionary of the node connections after the source. The node names are the keys and the values are the relative probabilities of traversing the connections.

  • interarrival_time (string) – The time between entity arrrivals into the system. The string may enclose a constant, random function or logical expression to be evaluated.

add_server

selib.add_server(name, connections, service_time, capacity=1)

Add a server to a discrete event model.

Parameters:
  • name (string) – A name for the server.

  • connections (dictionary) – A dictionary of the node connections after the server. The node names are the keys and the values are the relative probabilities of traversing the connection.

  • capacity (integer) – The number of resource usage slots in the server

add_delay

selib.add_delay(name, connections, delay_time)

Add a delay to a discrete event model.

Parameters:
  • name (string) – A name for the delay.

  • connections (dictionary) – A dictionary of the node connections after the delay. The node names are the keys and the values are the relative probabilities of traversing the connections.

  • delay_time (float) – The time delay for entities to traverse. May be a constant or random function.

add_terminate

selib.add_terminate(name)

Add a terminate node to a discrete event model for entities leaving the system.

Parameters:

name (string) – A name for the terminate.

run_model

selib.run_model(verbose=True)

Executes the current model

Returns:

  • If continuous, returns 1) Pandas dataframe containing run outputs for each variable each timestep and 2) model dictionary.

  • If discrete, returns 1) network dictionary with run statistics and 2) entity run data

draw_model_diagram

selib.draw_model_diagram(filename=None, format='svg')

Draw a diagram of the current model.

Parameters:
  • filename (string, optional) – A filename for the output not including a filename extension. The extension will specified by the format parameter.

  • format (string, optional) – The file format of the graphic output. Note that bitmap formats (png, bmp, or jpeg) will not be as sharp as the default svg vector format and most particularly when magnified.

Returns:

g – Save the graph source code to file, and open the rendered result in its default viewing application. se-lib calls the Graphviz API for this.

Return type:

graph object view

plot_histogram

selib.plot_histogram(data, filename=None, xlabel='Data')

Plot a histogram for a dataset and optionally save to a file.

Parameters:
  • data (list) – A list of the data values

  • filename (string, optional) – A name for the file

  • xlabel (string , optional) – A label for the x-axis

Return type:

A Matplotlib histogram