Welcome to KADMOS’s documentation!¶
See sidebar on the right for the table of contents.
Documentation for the Code¶
Below the simplified class diagram of the KADMOS package is shown (not all methods are included for clarity). The UML can als be downloaded as PDF here
.

Example scripts for using KADMOS are available in the examples/scripts folder. The following scripts are available there:
Sellar Problem
: Small two-disciplinary MDO problem based on MDO literature.TU Delft Wing Design
: The wing design case described here was developed at TU Delft and takes a variety of different disciplines into account.
KnowledgeBase¶
Below the full KADMOS KnowledgeBase class description can be found.
Graph¶
Below the KADMOS KadmosGraph class and its subclasses are listed.
KadmosGraph¶
-
class
kadmos.graph.
KadmosGraph
(*args, **kwargs)¶ -
add_cycle
(nodes, **attr)¶ Add a cycle.
- nodes: iterable container
- A container of nodes. A cycle will be constructed from the nodes (in order) and added to the graph.
- attr : keyword arguments, optional (default= no attributes)
- Attributes to add to every edge in cycle.
add_path, add_star
>>> G=nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_cycle([0,1,2,3]) >>> G.add_cycle([10,11,12],weight=7)
-
add_default_description
()¶ Method to add a default description attribute to a graph
Returns: graph with default attribute description Return type: KadmosGraph
-
add_default_name
()¶ Method to add a default name attribute to a graph
Returns: graph with default attribute name Return type: KadmosGraph
-
add_edge
(u, v, attr_dict=None, **attr)¶ Add an edge between u and v.
The nodes u and v will be automatically added if they are not already in the graph.
Edge attributes can be specified with keywords or by providing a dictionary with key/value pairs. See examples below.
- u, v : nodes
- Nodes can be, for example, strings or numbers. Nodes must be hashable (and not None) Python objects.
- attr_dict : dictionary, optional (default= no attributes)
- Dictionary of edge attributes. Key/value pairs will update existing data associated with the edge.
- attr : keyword arguments, optional
- Edge data (or labels or objects) can be assigned using keyword arguments.
add_edges_from : add a collection of edges
Adding an edge that already exists updates the edge data.
Many NetworkX algorithms designed for weighted graphs use as the edge weight a numerical value assigned to a keyword which by default is ‘weight’.
The following all add the edge e=(1,2) to graph G:
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> e = (1,2) >>> G.add_edge(1, 2) # explicit two-node form >>> G.add_edge(*e) # single edge as tuple of two nodes >>> G.add_edges_from( [(1,2)] ) # add edges from iterable container
Associate data to edges using keywords:
>>> G.add_edge(1, 2, weight=3) >>> G.add_edge(1, 3, weight=7, capacity=15, length=342.7)
-
add_edges_from
(ebunch, attr_dict=None, **attr)¶ Add all the edges in ebunch.
- ebunch : container of edges
- Each edge given in the container will be added to the graph. The edges must be given as as 2-tuples (u,v) or 3-tuples (u,v,d) where d is a dictionary containing edge data.
- attr_dict : dictionary, optional (default= no attributes)
- Dictionary of edge attributes. Key/value pairs will update existing data associated with each edge.
- attr : keyword arguments, optional
- Edge data (or labels or objects) can be assigned using keyword arguments.
add_edge : add a single edge add_weighted_edges_from : convenient way to add weighted edges
Adding the same edge twice has no effect but any edge data will be updated when each duplicate edge is added.
Edge attributes specified in edges take precedence over attributes specified generally.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edges_from([(0,1),(1,2)]) # using a list of edge tuples >>> e = zip(range(0,3),range(1,4)) >>> G.add_edges_from(e) # Add the path graph 0-1-2-3
Associate data to edges
>>> G.add_edges_from([(1,2),(2,3)], weight=3) >>> G.add_edges_from([(3,4),(1,4)], label='WN2898')
-
add_equation
(edge_or_node, equation, language='Python')¶ Method to add an equation to an output edge.
Parameters: - edge_or_node (list, str) – graph edge or node under consideration.
- equation (str) – equation to be added
- language (str) – equation language used for the equation
-
add_equation_label
(edge, label=None, language='Python')¶ Method to add an equation label to a edge that can (safely) be used as reference in an equation.
Parameters: - edge (str) – graph edge under consideration
- label (str) – label to be added (if not given it will be determined based on the node label or key)
- language (str) – equation language used for the equation label
Returns: label
Return type: str
-
add_equation_labels
(nodes, language='Python')¶ Method to add equation labels automatically to all input edges connected to the specified list of nodes
Parameters: - nodes (list) – list of nodes
- language (str) – equation language used for the equation label
-
add_nodes_from
(nodes, **attr)¶ Add multiple nodes.
- nodes : iterable container
- A container of nodes (list, dict, set, etc.). OR A container of (node, attribute dict) tuples. Node attributes are updated using the attribute dict.
- attr : keyword arguments, optional (default= no attributes)
- Update attributes for all nodes in nodes. Node attributes specified in nodes as a tuple take precedence over attributes specified generally.
add_node
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_nodes_from('Hello') >>> K3 = nx.Graph([(0,1),(1,2),(2,0)]) >>> G.add_nodes_from(K3) >>> sorted(G.nodes(),key=str) [0, 1, 2, 'H', 'e', 'l', 'o']
Use keywords to update specific node attributes for every node.
>>> G.add_nodes_from([1,2], size=10) >>> G.add_nodes_from([3,4], weight=0.4)
Use (node, attrdict) tuples to update attributes for specific nodes.
>>> G.add_nodes_from([(1,dict(size=11)), (2,{'color':'blue'})]) >>> G.node[1]['size'] 11 >>> H = nx.Graph() >>> H.add_nodes_from(G.nodes(data=True)) >>> H.node[1]['size'] 11
-
add_objective_function_by_nodes
(*args, **kwargs)¶ This function adds objective functions to the graph using lists of variable nodes.
Each list produces a separate objective function node in the graph. If the list if passed as a keyword argument, the keyword is taken as the name of the objective function node. Otherwise, a standard name will be given to the node. Each objective function node has one output variable, and takes the nodes given in the argument list as input nodes.
If the provided nodes do not exist in the graph, a warning is given to the user on whether to continue the addition of the objective function to the graph using valid nodes.
Example: unnamed_function = list(>>list of graph nodes<<) named_obj_fcn = list(>>list of graph nodes<<) MyGraph.add_objective_function_by_nodes(unnamed_function, My_obj_fcn_name = named_obj_fcn)
The added objective function nodes can be queried by the attribute Graph.node[node][“name”] == “Objective”.
Parameters: - args (list) – list of nodes (list elements must be strings)
- kwargs (list) – list of nodes (list elements must be strings)
Returns: list of Objective Functions added to Graph
Return type: list
-
add_path
(nodes, **attr)¶ Add a path.
- nodes : iterable container
- A container of nodes. A path will be constructed from the nodes (in order) and added to the graph.
- attr : keyword arguments, optional (default= no attributes)
- Attributes to add to every edge in path.
add_star, add_cycle
>>> G=nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.add_path([10,11,12],weight=7)
-
add_star
(nodes, **attr)¶ Add a star.
The first node in nodes is the middle of the star. It is connected to all other nodes.
- nodes : iterable container
- A container of nodes.
- attr : keyword arguments, optional (default= no attributes)
- Attributes to add to every edge in star.
add_path, add_cycle
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_star([0,1,2,3]) >>> G.add_star([10,11,12],weight=2)
-
add_weighted_edges_from
(ebunch, weight='weight', **attr)¶ Add all the edges in ebunch as weighted edges with specified weights.
- ebunch : container of edges
- Each edge given in the list or container will be added to the graph. The edges must be given as 3-tuples (u,v,w) where w is a number.
- weight : string, optional (default= ‘weight’)
- The attribute name for the edge weights to be added.
- attr : keyword arguments, optional (default= no attributes)
- Edge attributes to add/update for all edges.
add_edge : add a single edge add_edges_from : add multiple edges
Adding the same edge twice for Graph/DiGraph simply updates the edge data. For MultiGraph/MultiDiGraph, duplicate edges are stored.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_weighted_edges_from([(0,1,3.0),(1,2,7.5)])
-
adjacency_iter
()¶ Return an iterator of (node, adjacency dict) tuples for all nodes.
This is the fastest way to look at every edge. For directed graphs, only outgoing adjacencies are included.
- adj_iter : iterator
- An iterator of (node, adjacency dictionary) for all nodes in the graph.
adjacency_list
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> [(n,nbrdict) for n,nbrdict in G.adjacency_iter()] [(0, {1: {}}), (1, {0: {}, 2: {}}), (2, {1: {}, 3: {}}), (3, {2: {}})]
-
adjacency_list
()¶ Return an adjacency list representation of the graph.
The output adjacency list is in the order of G.nodes(). For directed graphs, only outgoing adjacencies are included.
- adj_list : lists of lists
- The adjacency structure of the graph as a list of lists.
adjacency_iter
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.adjacency_list() # in order given by G.nodes() [[1], [0, 2], [1, 3], [2]]
-
adjlist_dict_factory
¶ alias of
dict
-
check
(raise_error=False)¶ Method to check the graph for validity and completeness.
Several checks are performed. However the method does not guarantee the validity of the graph.
The checks are split into several categories and the methods _check_category_a, _check_category_b and _check_category_c are used to determine the overall validity and completeness. These sub methods are generally defined below and are then further refined in child classes.
Parameters: raise_error (bool) – determines if an error should be raised in case of an invalid graph Returns: result of the check Return type: bool
-
check_cmdows_integrity
(convention=True, mpg=None)¶ Method to check the integrity of the CMDOWS file that can be created with the save method.
The integrity check is graph specific and thus needs to be executed for every graph before saving as CMDOWS if one wants to be sure that the CMDOWS file is integer. Due to its relative long runtime this check is however not performed automatically when using the save method.
Parameters: - convention (bool) – option for applying a UID convention
- mpg (MdaoProcessGraph) – MPG to be saved together with graph
Returns: check result
Return type: bool
-
check_for_coupling
(function_order, only_feedback=False, raise_error_if_true=False)¶ Function to check for the presence of coupling in a graph for a list of analyses in a given analysis order.
Note that only the functions in the function_order list are checked for feedback.
Parameters: - function_order (list) – list with node names of functions
- only_feedback (bool) – Boolean on whether to check for feedback coupling only (this is useful for Gauss-Seidel)
- raise_error_if_true (bool) – Boolean on whether to raise an error if coupling exists
Returns: Boolean value on whether coupling exists
Return type: bool
-
cleancopy
()¶ Method to make a clean copy of a graph.
This method can be used to avoid deep-copy problems in graph manipulation algorithms. The graph class is kept.
Returns: clean-copy of the graph Return type: KadmosGraph
-
clear
()¶ Remove all nodes and edges from the graph.
This also removes the name, and all graph, node, and edge attributes.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.clear() >>> G.nodes() [] >>> G.edges() []
-
copy
()¶ Return a copy of the graph.
- G : Graph
- A copy of the graph.
to_directed: return a directed copy of the graph.
This makes a complete copy of the graph including all of the node or edge attributes.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> H = G.copy()
-
copy_node_with_suffix
(node, suffix, label_extension, **kwargs)¶ Method to simply copy a node and its attributes by creating a new node with a suffix.
Parameters: - node (str) – node to be copied
- suffix (str) – suffix to be added to the node ID
- label_extension (str) – extension for labels
- kwargs (dict) – keyword arguments will be added as node attributes
Returns: new node name and enriched graph
Return type: str
-
count_function_nodes
()¶ This function counts the amount function nodes that are present in the graph.
Returns: amount of function nodes counted in graph Return type: int
-
create_dsm
(file_name, destination_folder=None, open_pdf=False, mpg=None, include_system_vars=True, summarize_vars=False, function_order=None, keep_tex_file=False)¶ Method to create a (X)DSM PDF file
Parameters: - file_name (str) – name of the file to be saved
- open_pdf (bool) – option for opening the created file directly
- destination_folder (str) – destination folder for the file to be saved
- mpg (MdaoProcessGraph) – optional MPG graph to be saved with MDG as XDSM (if None a DSM is created)
- include_system_vars (bool) – option for including system variables (only applicable for DSMs)
- summarize_vars (bool) – option for summarizing label
- function_order (list) – optional function order for the diagonal of the graph (only applicable for DSMs)
- keep_tex_file (bool) – optional argument to keep the tex file of the PDF
-
degree
(nbunch=None, weight=None)¶ Return the degree of a node or nodes.
The node degree is the number of edges adjacent to that node.
- nbunch : iterable container, optional (default=all nodes)
- A container of nodes. The container will be iterated through once.
- weight : string or None, optional (default=None)
- The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.
- nd : dictionary, or number
- A dictionary with nodes as keys and degree as values or a number if a single node is specified.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.degree(0) 1 >>> G.degree([0,1]) {0: 1, 1: 2} >>> list(G.degree([0,1]).values()) [1, 2]
-
degree_iter
(nbunch=None, weight=None)¶ Return an iterator for (node, degree).
The node degree is the number of edges adjacent to the node.
- nbunch : iterable container, optional (default=all nodes)
- A container of nodes. The container will be iterated through once.
- weight : string or None, optional (default=None)
- The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.
- nd_iter : an iterator
- The iterator returns two-tuples of (node, degree).
degree, in_degree, out_degree, in_degree_iter, out_degree_iter
>>> G = nx.DiGraph() # or MultiDiGraph >>> G.add_path([0,1,2,3]) >>> list(G.degree_iter(0)) # node 0 with degree 1 [(0, 1)] >>> list(G.degree_iter([0,1])) [(0, 1), (1, 2)]
-
disconnect_problematic_variables_from
(function, disconnect_collided_targets=True, disconnect_shared_sources=True)¶ Method to automatically disconnect certain problematic variables with respect to a given function.
If given as setting (disconnect_collided_targets=True) then the collided targets will be disconnected from this function. Also, if given as setting (disconnect_shared_sources=True), shared sources are also disconnected.
Parameters: - function (basestring) – function around which problematic variables are disconnected
- disconnect_collided_targets (bool) – setting to disconnect collided targets
- disconnect_shared_sources (bool) – setting to disconnect shared sources
-
edge_attr_dict_factory
¶ alias of
dict
-
edges
(nbunch=None, data=False, default=None)¶ Return a list of edges.
Edges are returned as tuples with optional data in the order (node, neighbor, data).
- nbunch : iterable container, optional (default= all nodes)
- A container of nodes. The container will be iterated through once.
- data : string or bool, optional (default=False)
- The edge attribute returned in 3-tuple (u,v,ddict[data]). If True, return edge attribute dict in 3-tuple (u,v,ddict). If False, return 2-tuple (u,v).
- default : value, optional (default=None)
- Value used for edges that dont have the requested attribute. Only relevant if data is not True or False.
- edge_list: list of edge tuples
- Edges that are adjacent to any node in nbunch, or a list of all edges if nbunch is not specified.
edges_iter : return an iterator over the edges
Nodes in nbunch that are not in the graph will be (quietly) ignored. For directed graphs this returns the out-edges.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> G.add_edge(2,3,weight=5) >>> G.edges() [(0, 1), (1, 2), (2, 3)] >>> G.edges(data=True) # default edge data is {} (empty dictionary) [(0, 1, {}), (1, 2, {}), (2, 3, {'weight': 5})] >>> list(G.edges_iter(data='weight', default=1)) [(0, 1, 1), (1, 2, 1), (2, 3, 5)] >>> G.edges([0,3]) [(0, 1), (3, 2)] >>> G.edges(0) [(0, 1)]
-
edges_iter
(nbunch=None, data=False, default=None)¶ Return an iterator over the edges.
Edges are returned as tuples with optional data in the order (node, neighbor, data).
- nbunch : iterable container, optional (default= all nodes)
- A container of nodes. The container will be iterated through once.
- data : string or bool, optional (default=False)
- The edge attribute returned in 3-tuple (u,v,ddict[data]). If True, return edge attribute dict in 3-tuple (u,v,ddict). If False, return 2-tuple (u,v).
- default : value, optional (default=None)
- Value used for edges that dont have the requested attribute. Only relevant if data is not True or False.
- edge_iter : iterator
- An iterator of (u,v) or (u,v,d) tuples of edges.
edges : return a list of edges
Nodes in nbunch that are not in the graph will be (quietly) ignored. For directed graphs this returns the out-edges.
>>> G = nx.DiGraph() # or MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> G.add_edge(2,3,weight=5) >>> [e for e in G.edges_iter()] [(0, 1), (1, 2), (2, 3)] >>> list(G.edges_iter(data=True)) # default data is {} (empty dict) [(0, 1, {}), (1, 2, {}), (2, 3, {'weight': 5})] >>> list(G.edges_iter(data='weight', default=1)) [(0, 1, 1), (1, 2, 1), (2, 3, 5)] >>> list(G.edges_iter([0,2])) [(0, 1), (2, 3)] >>> list(G.edges_iter(0)) [(0, 1)]
-
find_all_nodes
(category='all', subcategory='all', attr_cond=None, attr_include=None, attr_exclude=None, print_in_log=False, print_attributes='all')¶ Advanced search function to get nodes and their properties.
Parameters: - category (str) – category of the node (you can specify multiple in a list), see note for allowed values.
- subcategory (str) – subcategory of the node (you can specify multiple in a list), see note for allowed values.
- attr_cond (list) – conditional on the node attribute value (e.g. [‘execution time’,’>’,200])
- attr_include (list) – attributes to exclusively include in search
- attr_exclude (list) – attributes to exclude from search
- print_in_log (bool) – parameter to set printing in log on or off
- print_attributes (str or list) – attributes that should be printed in the log
Returns: list of all nodes that meet the search criteria
Return type: list
Note
The following categories are allowed:
- all
- variable
- variable group
- function
- architecture element
- RCE component
Note
The following subcategories are allowed:
GROUPS:
- all
- all variables
- all inputs
- all outputs
- all couplings
- all circular variables
- all PSG blocks
- all iterative blocks
- all design variables
VARIABLES:
- hole
- supplied input
- supplied shared input
- output
- collision
- coupling
- pure circular coupling
- shared coupling
- shared circular coupling
- collided coupling
- collided circular coupling
- collided shared coupling
- collided shared circular coupling
VARIABLE GROUPS:
- hole group
- supplied input group
- supplied shared input group
- output group
- coupling group
- shared coupling group
FUNCTIONS:
- hole
- inputless
- outputless
- complete
ARCHITECTURE ELEMENTS:
Action blocks:
- optimizer
- MDA
- optimizer function
- MDA analysis
- independent output function
Parameters:
- initial guess design variable
- final design variable
- final output variable
- MDA coupling variable
- initial guess MDA coupling variable
- final MDA coupling variable
- consistency constraint variable
RCE COMPONENTS:
- Input Provider
- XML Merger
- XML PyMerger
- CPACS Tool
- Converger
- Optimizer
- Consistency constraint function
Example usage: Just get all nodes of a graph in a list:
>>> all_nodes = self.find_all_nodes()
Get all input nodes in a list and print them in the log as well:
>>> all_nodes = self.find_all_nodes(category='all', subcategory='all inputs', print_in_log=True)
Get all input nodes with a certain attribute value:
>>> all_nodes = self.find_all_nodes(category='all', subcategory='all inputs', >>> attr_cond=['execution time', '>', 5], print_in_log=True)
-
get_adjacency_matrix
(print_in_log=True)¶ Function to determine the adjacency matrix of a graph.
Parameters: print_in_log (bool) – option for printing the results Returns: different methods of storing the same adjacency matrix in one dictionary Return type: dict
-
get_categorized_nodes
(print_in_log=False)¶ Function that returns a dictionary with graph nodes grouped according to category and subcategory.
Parameters: print_in_log (bool) – option for printing the categories Returns: dictionary with analysis results Return type: dict
-
get_contracted_graph
(contraction_level)¶ This function contracts the nodes of a graph to the provided contraction level.
The contraction level refers to the xpath-level, which represents the position of the descendant with respect to its predecessors. The example below represents a level 3 node, with “cpacs” being at level zero.
/cpacs/aircraft/wings/wing
-cpacs |—-aircraft |——–wings |————wing
All nodes above the contraction level are removed from the graph and replaced by a “variable group” node, which groups the removed nodes in a node at contraction level. This allows for a “de-cluttering” of the graph, with the graph connections still being represented.
Parameters: contraction_level – int from 0 (highest level) to X (lowest level existing in XML schema) Returns: contracted_graph: graph with contracted nodes
-
get_direct_coupling_nodes
(*args, **kwargs)¶ This method returns the direct couplings between two nodes in a graph.
This method is specifically written (and tested) with function nodes in mind. Direct coupling is defined as coupling with between two nodes through a third node.
In this function, each combination between the provided arguments is tested for couplings (in pairs). First, the two nodes in each pair are checked for common neighbors. If they do, the edges of the common neighbors are iterated to determine whether the node-pair is connected to each other, or only the neighbor. The direction of the coupling is also checked.
Example:
The connection
F1 —> N1 —> F2
leads to
[(F1, F2, N1)]
Parameters: - args (str, list) – nodes to be checked for couplings; at least two must be provided
- kwargs (direction: str) – print_couplings: option for printing all couplings with coupling direction and node (optional)
- kwargs – direction: set only coupling in certain direction (optional)
Returns: couplings: list of tuples containing the coupled nodes and the coupling node
Return type: list
-
get_edge_data
(u, v, default=None)¶ Return the attribute dictionary associated with edge (u,v).
u, v : nodes default: any Python object (default=None)
Value to return if the edge (u,v) is not found.- edge_dict : dictionary
- The edge attribute dictionary.
It is faster to use G[u][v].
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G[0][1] {}
Warning: Assigning G[u][v] corrupts the graph data structure. But it is safe to assign attributes to that dictionary,
>>> G[0][1]['weight'] = 7 >>> G[0][1]['weight'] 7 >>> G[1][0]['weight'] 7
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.get_edge_data(0,1) # default edge data is {} {} >>> e = (0,1) >>> G.get_edge_data(*e) # tuple form {} >>> G.get_edge_data('a','b',default=0) # edge not in graph, return 0 0
-
get_function_graph
(keep_objective_variables=False)¶ Method for replacing variable nodes by function connections.
This function removes all variable nodes from the graph and replaces the variable connections of each function with function connections, such that
F(1) —-> N(1) —-> F(2) —-> N(2) —-> F(3)
becomes
F(1) —-> F(2) —-> F(3),
where N(i) is a variable node, and F(i) a function node.
Param: keep_objective_variables: if given the objective variables will remain in graph Type: keep_objective_variables: bool Returns: new graph without variable nodes
-
get_function_metadata
(node)¶ Function to get the node metadata in a list (used in the dynamic visualization package).
Parameters: node (basestring) – function node to collect the metadata for. Returns: list with metadata Return type: list
-
get_function_nodes
()¶ This function returns a list of all function nodes in the graph.
-
get_graph_properties
(*args)¶ This function retrieves the properties of a graph.
If no argument is given, the standard list of properties GRAPH_PROPERTIES is analyzed and their values are returned in a dict. If arguments are given, only this list will be used as standard list of properties.
Param: args: specific properties to be retrieved (optional) Returns: dictionary containing the properties of the graph Return type: dict
-
get_node_attributes
(node, attr_list, print_in_log=False)¶ Function to get and print certain attributes of a node from the graph.
Parameters: - node (str) – node name
- attr_list (list) – list with attributes to be pulled
- print_in_log (bool) – option for printing to log
Returns: dictionary with node attributes
Return type: dict
-
get_node_subcategory
(node)¶ Method to analyse a node and to update the subcategory attribute of the node.
The following table illustrates how the subcategory is determined based on the category, indegree and outdegree:
CATEGORY OF NODE SUBCATEGORY INDEGREE OUTDEGREE variable hole 0 0 supplied input 0 1 supplied shared input 0 >1 output 1 0 collision >1 0 - coupling
- or
pure circular coupling
1 1 - shared coupling
- or
shared circular coupling
1 >1 - collided coupling
- or
collided circular coupling
>1 1 - collided shared coupling
- or
collided shared circular coupling
>1 >1 function hole 0 0 inputless 0 >0 outputless >0 0 complete >0 >0 Parameters: node (basestring) – node in the graph Returns: subcategory of the node Return type: basestring
-
get_nodes_based_on_strings
(*args, **kwargs)¶ This function enables the user to search graph nodes for specific strings.
Each provided string will be searched for, and if multiple node are found for each string, the user will be able to select the ones desired. The other matched nodes are disregarded.
Parameters: - args (str) – strings that graph nodes being searched for
- kwargs (include_all: bool) – include_all: If include_all is set to True, all matching nodes are added to returned list
Returns: matching nodes that user selected (all if include_all is True)
-
get_nodes_indegree
()¶ Function to get the indegree of all the graph nodes and store them in a dictionary.
Returns: dictionary with node name key and indegree integer value. Return type: dict
-
get_nodes_outdegree
()¶ Function to get the outdegree of all the graph nodes and store them in a dictionary.
Returns: dictionary with node name key and outdegree integer value. Return type: dict
-
get_nodes_subcategory
()¶ Method to analyse all nodes and to update the subcategory attributes of the nodes.
-
get_number_of_couplings
(node)¶ This function returns the number of couplings of a node in the graph.
Parameters: node – input node Returns: number of couplings for the input node Type: int
-
get_partitioned_graph
(n_parts, tpwgts=None, recursive=False, contig=False, output='KadmosGraph')¶ Partition a graph using the Metis algorithm (http://glaros.dtc.umn.edu/gkhome/metis/metis/overview).
Note that partitioning can only be performed on undirected graphs. Therefore every graph input is translated into an undirected graph.
Parameters: - n_parts – number of partitions requested (algorithm might provide less)
- tpwgts – list of target partition weights
- recursive – Metis option
- contig – Metis option
- output – set whether expected output is a KadmosGraph, DiGraph or normal Graph
Returns: list of edges that have been cut
Returns: list of partition group to which each node belongs
-
get_sources
(node)¶ Function to determine the sources of a given node.
Parameters: node (basestring) – node for which sources should be found Returns: list with sources Return type: list
-
get_subgraph_by_function_nodes
(*args, **kwargs)¶ This function retrieves a subgraph from the original graph only containing the argument nodes.
All arguments must be found in the graph.
Parameters: - args (list, str) – arbitrary amount of graph nodes
- kwargs (copy_type: str) – copy_type: type of copy (clean or deep)
Returns: sub-graph only containing nodes provided as arguments, and their edges
-
get_system_inputs
(*args, **kwargs)¶ This method checks whether there are system inputs in the graph using the function nodes provided.
The function nodes should be provided in the args. If system inputs exist they are returned.
Parameters: args – function nodes Returns: system input nodes dictionary Return type: dict
-
get_targets
(node)¶ Function to determine the targets of a given node.
Parameters: node (basestring) – node for which targets should be found Returns: list with targets Return type: list
-
has_edge
(u, v)¶ Return True if the edge (u,v) is in the graph.
- u, v : nodes
- Nodes can be, for example, strings or numbers. Nodes must be hashable (and not None) Python objects.
- edge_ind : bool
- True if edge is in the graph, False otherwise.
Can be called either using two nodes u,v or edge tuple (u,v)
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.has_edge(0,1) # using two nodes True >>> e = (0,1) >>> G.has_edge(*e) # e is a 2-tuple (u,v) True >>> e = (0,1,{'weight':7}) >>> G.has_edge(*e[:2]) # e is a 3-tuple (u,v,data_dictionary) True
The following syntax are all equivalent:
>>> G.has_edge(0,1) True >>> 1 in G[0] # though this gives KeyError if 0 not in G True
-
has_node
(n)¶ Return True if the graph contains the node n.
n : node
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> G.has_node(0) True
It is more readable and simpler to use
>>> 0 in G True
-
has_nodes
(nodes)¶ Function that checks whether all nodes given in a list are present in the graph.
Parameters: nodes (list) – list of nodes to be checked Returns: boolean whether all nodes have been found Return type: bool
-
has_predecessor
(u, v)¶ Return True if node u has predecessor v.
This is true if graph has the edge u<-v.
-
has_successor
(u, v)¶ Return True if node u has successor v.
This is true if graph has the edge u->v.
-
in_degree
(nbunch=None, weight=None)¶ Return the in-degree of a node or nodes.
The node in-degree is the number of edges pointing in to the node.
- nbunch : iterable container, optional (default=all nodes)
- A container of nodes. The container will be iterated through once.
- weight : string or None, optional (default=None)
- The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.
- nd : dictionary, or number
- A dictionary with nodes as keys and in-degree as values or a number if a single node is specified.
degree, out_degree, in_degree_iter
>>> G = nx.DiGraph() # or MultiDiGraph >>> G.add_path([0,1,2,3]) >>> G.in_degree(0) 0 >>> G.in_degree([0,1]) {0: 0, 1: 1} >>> list(G.in_degree([0,1]).values()) [0, 1]
-
in_degree_iter
(nbunch=None, weight=None)¶ Return an iterator for (node, in-degree).
The node in-degree is the number of edges pointing in to the node.
- nbunch : iterable container, optional (default=all nodes)
- A container of nodes. The container will be iterated through once.
- weight : string or None, optional (default=None)
- The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.
- nd_iter : an iterator
- The iterator returns two-tuples of (node, in-degree).
degree, in_degree, out_degree, out_degree_iter
>>> G = nx.DiGraph() >>> G.add_path([0,1,2,3]) >>> list(G.in_degree_iter(0)) # node 0 with degree 0 [(0, 0)] >>> list(G.in_degree_iter([0,1])) [(0, 0), (1, 1)]
-
in_edges
(nbunch=None, data=False)¶ Return a list of the incoming edges.
edges : return a list of edges
-
in_edges_iter
(nbunch=None, data=False)¶ Return an iterator over the incoming edges.
- nbunch : iterable container, optional (default= all nodes)
- A container of nodes. The container will be iterated through once.
- data : bool, optional (default=False)
- If True, return edge attribute dict in 3-tuple (u,v,data).
- in_edge_iter : iterator
- An iterator of (u,v) or (u,v,d) tuples of incoming edges.
edges_iter : return an iterator of edges
-
inspect
()¶ Method to print an overview of the graph.
-
inspect_node
(node)¶ Method to print a node with details.
Parameters: node (str) – node
-
inspect_nodes
(list_of_nodes)¶ Method to inspect a list of nodes with details.
Parameters: list_of_nodes (list) – node list
-
is_directed
()¶ Return True if graph is directed, False otherwise.
-
is_multigraph
()¶ Return True if graph is a multigraph, False otherwise.
-
make_all_variables_valid
()¶ Method to analyze all variables in a graph and make any problematic variables valid.
Problematic variable are holes and splittables. Splittable variables are split and holes will simply be removed.
-
merge_function_modes
(*args, **kwargs)¶ Function to contract certain modes of the same function.
Parameters: - args (list) – function (first arg) and then followed by modes to be contracted.
- kwargs (dict) – new_label to specify new node label manually (optional)
Returns: contracted graph
Return type:
-
merge_function_nodes_based_on_modes
(merge_funcs=None)¶ This class method merges all execution modes of the same function into a single node.
Mainly used for illustration purposes since information on the execution modes gets lost.
Parameters: merge_funcs – List of tuple of functions to merge. If empty (default), all functions are merged. Functions must be present in graph. :type merge_funcs: list, tuple :return: merged graph
-
merge_parallel_functions
(*args, **kwargs)¶ Function to merge a list of functions
Parameters: - args (node_ids) – functions to be merged
- kwargs (dict) – new_label to specify new node label manually (optional)
-
merge_sequential_functions
(*args, **kwargs)¶ Function to merge a collection of functions.
It is assumed that the merged functions are actually executed in the sequence in which they are given to this function.
Parameters: - args (node_ids) – functions to be merged in the given sequence
- kwargs (dict) – new_label to specify new node label manually (optional)
-
nbunch_iter
(nbunch=None)¶ Return an iterator of nodes contained in nbunch that are also in the graph.
The nodes in nbunch are checked for membership in the graph and if not are silently ignored.
- nbunch : iterable container, optional (default=all nodes)
- A container of nodes. The container will be iterated through once.
- niter : iterator
- An iterator over nodes in nbunch that are also in the graph. If nbunch is None, iterate over all nodes in the graph.
- NetworkXError
- If nbunch is not a node or or sequence of nodes. If a node in nbunch is not hashable.
Graph.__iter__
When nbunch is an iterator, the returned iterator yields values directly from nbunch, becoming exhausted when nbunch is exhausted.
To test whether nbunch is a single node, one can use “if nbunch in self:”, even after processing with this routine.
If nbunch is not a node or a (possibly empty) sequence/iterator or None, a NetworkXError is raised. Also, if any object in nbunch is not hashable, a NetworkXError is raised.
-
neighbors
(n)¶ Return a list of successor nodes of n.
neighbors() and successors() are the same function.
-
neighbors_iter
(n)¶ Return an iterator over successor nodes of n.
neighbors_iter() and successors_iter() are the same.
-
node_dict_factory
¶ alias of
dict
-
node_is_function
(node)¶ Function that checks whether a node is a function node or not.
Parameters: node (str) – node in graph Returns: check result Return type: bool
-
node_is_hole
(node)¶ Function that checks whether a node is a hole (unconnected).
Parameters: node (str) – node in graph Returns: check result Return type: bool
-
node_is_objective_function
(node)¶ This function checks whether the provided node is a objective function.
- This function checks whether the provided node:
- exists in graph
- has name-attribute “Objective”
- has an out-degree of 1
- has an outgoing node with an out-degree of zero # TODO: THIS IS WRONG!
Only if all checks are satisfied, is the node a valid objective function node.
Parameters: node (str) – graph node to be tested Returns: check result Return type: bool
-
node_is_output
(node)¶ Function that checks whether a node is a system output.
Parameters: node (str) – node in graph Returns: check result Return type: bool
-
node_is_variable
(node)¶ Function that checks whether a node is a variable node or not.
Parameters: node (str) – node in graph Returns: check result Return type: bool
-
nodes
(data=False)¶ Return a list of the nodes in the graph.
- data : boolean, optional (default=False)
- If False return a list of nodes. If True return a two-tuple of node and node data dictionary
- nlist : list
- A list of nodes. If data=True a list of two-tuples containing (node, node data dictionary).
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> G.nodes() [0, 1, 2] >>> G.add_node(1, time='5pm') >>> G.nodes(data=True) [(0, {}), (1, {'time': '5pm'}), (2, {})]
-
nodes_iter
(data=False)¶ Return an iterator over the nodes.
- data : boolean, optional (default=False)
- If False the iterator returns nodes. If True return a two-tuple of node and node data dictionary
- niter : iterator
- An iterator over nodes. If data=True the iterator gives two-tuples containing (node, node data, dictionary)
If the node data is not required it is simpler and equivalent to use the expression ‘for n in G’.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2])
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2])
>>> [d for n,d in G.nodes_iter(data=True)] [{}, {}, {}]
-
nodes_with_selfloops
()¶ Return a list of nodes with self loops.
A node with a self loop has an edge with both ends adjacent to that node.
- nodelist : list
- A list of nodes with self loops.
selfloop_edges, number_of_selfloops
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1,1) >>> G.add_edge(1,2) >>> G.nodes_with_selfloops() [1]
-
number_of_edges
(u=None, v=None)¶ Return the number of edges between two nodes.
- u, v : nodes, optional (default=all edges)
- If u and v are specified, return the number of edges between u and v. Otherwise return the total number of all edges.
- nedges : int
- The number of edges in the graph. If nodes u and v are specified return the number of edges between those nodes.
size
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.number_of_edges() 3 >>> G.number_of_edges(0,1) 1 >>> e = (0,1) >>> G.number_of_edges(*e) 1
-
number_of_nodes
()¶ Return the number of nodes in the graph.
- nnodes : int
- The number of nodes in the graph.
order, __len__ which are identical
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> len(G) 3
-
number_of_selfloops
()¶ Return the number of selfloop edges.
A selfloop edge has the same node at both ends.
- nloops : int
- The number of selfloops.
nodes_with_selfloops, selfloop_edges
>>> G=nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1,1) >>> G.add_edge(1,2) >>> G.number_of_selfloops() 1
-
order
()¶ Return the number of nodes in the graph.
- nnodes : int
- The number of nodes in the graph.
number_of_nodes, __len__ which are identical
-
out_degree
(nbunch=None, weight=None)¶ Return the out-degree of a node or nodes.
The node out-degree is the number of edges pointing out of the node.
- nbunch : iterable container, optional (default=all nodes)
- A container of nodes. The container will be iterated through once.
- weight : string or None, optional (default=None)
- The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.
- nd : dictionary, or number
- A dictionary with nodes as keys and out-degree as values or a number if a single node is specified.
>>> G = nx.DiGraph() # or MultiDiGraph >>> G.add_path([0,1,2,3]) >>> G.out_degree(0) 1 >>> G.out_degree([0,1]) {0: 1, 1: 1} >>> list(G.out_degree([0,1]).values()) [1, 1]
-
out_degree_iter
(nbunch=None, weight=None)¶ Return an iterator for (node, out-degree).
The node out-degree is the number of edges pointing out of the node.
- nbunch : iterable container, optional (default=all nodes)
- A container of nodes. The container will be iterated through once.
- weight : string or None, optional (default=None)
- The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.
- nd_iter : an iterator
- The iterator returns two-tuples of (node, out-degree).
degree, in_degree, out_degree, in_degree_iter
>>> G = nx.DiGraph() >>> G.add_path([0,1,2,3]) >>> list(G.out_degree_iter(0)) # node 0 with degree 1 [(0, 1)] >>> list(G.out_degree_iter([0,1])) [(0, 1), (1, 1)]
-
out_edges
(nbunch=None, data=False, default=None)¶ Return a list of edges.
Edges are returned as tuples with optional data in the order (node, neighbor, data).
- nbunch : iterable container, optional (default= all nodes)
- A container of nodes. The container will be iterated through once.
- data : string or bool, optional (default=False)
- The edge attribute returned in 3-tuple (u,v,ddict[data]). If True, return edge attribute dict in 3-tuple (u,v,ddict). If False, return 2-tuple (u,v).
- default : value, optional (default=None)
- Value used for edges that dont have the requested attribute. Only relevant if data is not True or False.
- edge_list: list of edge tuples
- Edges that are adjacent to any node in nbunch, or a list of all edges if nbunch is not specified.
edges_iter : return an iterator over the edges
Nodes in nbunch that are not in the graph will be (quietly) ignored. For directed graphs this returns the out-edges.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> G.add_edge(2,3,weight=5) >>> G.edges() [(0, 1), (1, 2), (2, 3)] >>> G.edges(data=True) # default edge data is {} (empty dictionary) [(0, 1, {}), (1, 2, {}), (2, 3, {'weight': 5})] >>> list(G.edges_iter(data='weight', default=1)) [(0, 1, 1), (1, 2, 1), (2, 3, 5)] >>> G.edges([0,3]) [(0, 1), (3, 2)] >>> G.edges(0) [(0, 1)]
-
out_edges_iter
(nbunch=None, data=False, default=None)¶ Return an iterator over the edges.
Edges are returned as tuples with optional data in the order (node, neighbor, data).
- nbunch : iterable container, optional (default= all nodes)
- A container of nodes. The container will be iterated through once.
- data : string or bool, optional (default=False)
- The edge attribute returned in 3-tuple (u,v,ddict[data]). If True, return edge attribute dict in 3-tuple (u,v,ddict). If False, return 2-tuple (u,v).
- default : value, optional (default=None)
- Value used for edges that dont have the requested attribute. Only relevant if data is not True or False.
- edge_iter : iterator
- An iterator of (u,v) or (u,v,d) tuples of edges.
edges : return a list of edges
Nodes in nbunch that are not in the graph will be (quietly) ignored. For directed graphs this returns the out-edges.
>>> G = nx.DiGraph() # or MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> G.add_edge(2,3,weight=5) >>> [e for e in G.edges_iter()] [(0, 1), (1, 2), (2, 3)] >>> list(G.edges_iter(data=True)) # default data is {} (empty dict) [(0, 1, {}), (1, 2, {}), (2, 3, {'weight': 5})] >>> list(G.edges_iter(data='weight', default=1)) [(0, 1, 1), (1, 2, 1), (2, 3, 5)] >>> list(G.edges_iter([0,2])) [(0, 1), (2, 3)] >>> list(G.edges_iter(0)) [(0, 1)]
-
plot_adjacency_matrix
(fig_num=1, fig_size=(7, 7), show_now=True)¶ Draw the adjacency matrix in a plot window.
Parameters: - fig_num – figure number
- fig_size – figure size
- show_now – Boolean whether to plot directly (pausing the execution until the plot is closed), or not.
-
plot_graph
(fig_num=1, fig_size=(18, 11), color_setting='default', save_as=None, show_now=True, title=None, edge_label=False)¶ Function to plot a graph.
Note that you need to add matplotlib.pyplot.show() at the end of your code to see the plot window.
Parameters: - fig_num – figure number
- fig_size – size of figure window
- color_setting – choose from ‘default’, ‘sinks’, ‘categories’, ‘partitions’
- save_as – save plot as figure file
- show_now – Boolean whether to plot directly (pausing the execution until the plot is closed), or not.
- title – title string of the graph
- edge_label – edge attribute that will be shown for each edge in graph
Returns: window with plot
-
predecessors
(n)¶ Return a list of predecessor nodes of n.
-
predecessors_iter
(n)¶ Return an iterator over predecessor nodes of n.
-
print_graph
(use_pretty_print=False)¶ Function to print the full graph.
Parameters: use_pretty_print (bool) – Boolean on whether to use pretty print for node and edge attributes
-
relabel_function_nodes
(mapping=None)¶ Method to relabel all function nodes so that they meet the CMDOWS convention ID[modeID][instanceID][version]
-
remove_edge
(u, v)¶ Remove the edge between u and v.
- u, v : nodes
- Remove the edge between nodes u and v.
- NetworkXError
- If there is not an edge between u and v.
remove_edges_from : remove a collection of edges
>>> G = nx.Graph() # or DiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.remove_edge(0,1) >>> e = (1,2) >>> G.remove_edge(*e) # unpacks e from an edge tuple >>> e = (2,3,{'weight':7}) # an edge with attribute data >>> G.remove_edge(*e[:2]) # select first part of edge tuple
-
remove_edges_from
(ebunch)¶ Remove all edges specified in ebunch.
- ebunch: list or container of edge tuples
Each edge given in the list or container will be removed from the graph. The edges can be:
- 2-tuples (u,v) edge between u and v.
- 3-tuples (u,v,k) where k is ignored.
remove_edge : remove a single edge
Will fail silently if an edge in ebunch is not in the graph.
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> ebunch=[(1,2),(2,3)] >>> G.remove_edges_from(ebunch)
-
remove_function_nodes
(*args)¶ Function that removes a function node
Also the input and output variables that only have links to this specific function node are deleted. A simple remove_node of a function node might lead to unconnected variables in the graph.
Parameters: args (str) – function node id(s)
-
remove_node
(n)¶ Remove node n.
Removes the node n and all adjacent edges. Attempting to remove a non-existent node will raise an exception.
- n : node
- A node in the graph
- NetworkXError
- If n is not in the graph.
remove_nodes_from
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> G.edges() [(0, 1), (1, 2)] >>> G.remove_node(1) >>> G.edges() []
-
remove_nodes_from
(nbunch)¶ Remove multiple nodes.
- nodes : iterable container
- A container of nodes (list, dict, set, etc.). If a node in the container is not in the graph it is silently ignored.
remove_node
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2]) >>> e = G.nodes() >>> e [0, 1, 2] >>> G.remove_nodes_from(e) >>> G.nodes() []
-
reverse
(copy=True)¶ Return the reverse of the graph.
The reverse is a graph with the same nodes and edges but with the directions of the edges reversed.
- copy : bool optional (default=True)
- If True, return a new DiGraph holding the reversed edges. If False, reverse the reverse graph is created using the original graph (this changes the original graph).
-
save
(file_name, file_type='kdms', graph_check_critical=True, destination_folder=None, mpg=None, description='', creator='', version='1.0', timestamp=datetime.datetime(2017, 9, 5, 16, 41, 58, 881401), keep_empty_elements=False, pretty_print=False, convention=True, integrity=False)¶ Method to save the graph.
Different output file types are implemented for saving graphs. They are listed in the following. kdms: the most simple file type which makes use of pickling cmdows: the most versatile file type especially suited for file exchange with other tools graphml: another file type especially suited for file exchange with other tools based on graphs
Parameters: - file_name (str) – name of the file to be saved
- file_type (str) – file_type
- graph_check_critical (bool) – option for raising errors in case of an invalid graph
- destination_folder (str) – destination folder for the file to be saved
- mpg (MdaoProcessGraph) – optional MPG graph to be saved with MDG
- description (str) – description of the file (only applicable for the cmdows file type)
- creator (str) – name of the creator of the file (only applicable for the cmdows file type)
- version (str | float | int) – version of the file (only applicable for the cmdows file type)
- timestamp (datetime) – timestamp to be saved in the file (only applicable for the cmdows file type)
- keep_empty_elements (bool) – option for keeping empty XML elements (only applicable for the cmdows file type)
- pretty_print (bool) – option for pretty XML printing (only applicable for the cmdows file type)
- convention (bool) – option for appyling a UID convention (only applicable for the cmdows file type)
- integrity (bool) – option for doing an integrity file check (only applicable for the cmdows file type)
-
select_objectives_from_graph
(*args)¶ This functions lets the user select one or more objective functions from the graph.
Only functions can be selected as objectives. If no arguments are provided, user is prompted to select an objective from all functions in graph.
Param: args: objective functions to choose from Returns: list of objective functions
-
selfloop_edges
(data=False, default=None)¶ Return a list of selfloop edges.
A selfloop edge has the same node at both ends.
- data : string or bool, optional (default=False)
- Return selfloop edges as two tuples (u,v) (data=False) or three-tuples (u,v,datadict) (data=True) or three-tuples (u,v,datavalue) (data=’attrname’)
- default : value, optional (default=None)
- Value used for edges that dont have the requested attribute. Only relevant if data is not True or False.
- edgelist : list of edge tuples
- A list of all selfloop edges.
nodes_with_selfloops, number_of_selfloops
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1,1) >>> G.add_edge(1,2) >>> G.selfloop_edges() [(1, 1)] >>> G.selfloop_edges(data=True) [(1, 1, {})]
-
size
(weight=None)¶ Return the number of edges.
- weight : string or None, optional (default=None)
- The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1.
- nedges : int
- The number of edges or sum of edge weights in the graph.
number_of_edges
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.size() 3
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge('a','b',weight=2) >>> G.add_edge('b','c',weight=4) >>> G.size() 2 >>> G.size(weight='weight') 6.0
-
split_variables
(*args)¶ Method to split a problematic variable node into multiple separate valid nodes.
The following variables are considered problematic and will be handled by this function:
- pure circular coupling
- shared circular coupling
- collided coupling
- collision
- collided circular coupling
- collided shared coupling
- collided shared circular coupling
PURE CIRCULAR COUPLING x1 <====> F1
Which will be resolved into: x1/variableInstance1 ====> F1 ====> x1/variableInstance2
SHARED CIRCULAR COUPLING F1 <====> x1 ====> F2, F3, etc.
Which will be resolved into: x1/variableInstance1 ====> F1 ====> x1/variableInstance2 ====> F2, F3, etc.
COLLIDED (SHARED) COUPLING F1,F3 ====> x1 ====> F2, F4
Which will, with a function order of [F1,F2,F3,F4], be resolved into: F1 ====> x1/variableInstance1 ====> F2 F3 ====> x1/variableInstance2 ====> F4
COLLISION F1,F2 ====> x1
Which will, with a function order of [F1,F2], be resolved into: F1 ====> x1/variableInstance1 F2 ====> x1/variableInstance2
COLLIDED CIRCULAR COUPLING F1 <====> x1 <==== F2, F3
Which will be resolved into: x1/variableInstance1 ====> F1 ====> x1/variableInstance2
F2 ====> x1/variableInstance3 F3 ====> x1/variableInstance4COLLIDED SHARED CIRCULAR COUPLING F3,F5 <====> x1 <==== F2
/F1,F4,F6
Which will, with a function order of [F1,F2,F3,F4,F5,F6], be resolved into: x1/variableInstance1 ====> F2 ====> (...) x1/variableInstance2 ====> F1,F3 ====> (...) x1/variableInstance3 ====> F4,F5 ====> (...) x1/variableInstance4 ====> F6
Parameters: args (basestring, list) – problematic node in the graph
-
subgraph
(nbunch)¶ Return the subgraph induced on nodes in nbunch.
The induced subgraph of the graph contains the nodes in nbunch and the edges between those nodes.
- nbunch : list, iterable
- A container of nodes which will be iterated through once.
- G : Graph
- A subgraph of the graph with the same edge attributes.
The graph, edge or node attributes just point to the original graph. So changes to the node or edge structure will not be reflected in the original graph while changes to the attributes will.
To create a subgraph with its own copy of the edge/node attributes use: nx.Graph(G.subgraph(nbunch))
If edge attributes are containers, a deep copy can be obtained using: G.subgraph(nbunch).copy()
For an inplace reduction of a graph to a subgraph you can remove nodes: G.remove_nodes_from([ n in G if n not in set(nbunch)])
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> H = G.subgraph([0,1,2]) >>> H.edges() [(0, 1), (1, 2)]
-
successors
(n)¶ Return a list of successor nodes of n.
neighbors() and successors() are the same function.
-
successors_iter
(n)¶ Return an iterator over successor nodes of n.
neighbors_iter() and successors_iter() are the same.
-
to_directed
()¶ Return a directed copy of the graph.
- G : DiGraph
- A deepcopy of the graph.
This returns a “deepcopy” of the edge, node, and graph attributes which attempts to completely copy all of the data and references.
This is in contrast to the similar D=DiGraph(G) which returns a shallow copy of the data.
See the Python copy module for more information on shallow and deep copies, http://docs.python.org/library/copy.html.
>>> G = nx.Graph() # or MultiGraph, etc >>> G.add_path([0,1]) >>> H = G.to_directed() >>> H.edges() [(0, 1), (1, 0)]
If already directed, return a (deep) copy
>>> G = nx.DiGraph() # or MultiDiGraph, etc >>> G.add_path([0,1]) >>> H = G.to_directed() >>> H.edges() [(0, 1)]
-
to_undirected
(reciprocal=False)¶ Return an undirected representation of the digraph.
- reciprocal : bool (optional)
- If True only keep edges that appear in both directions in the original digraph.
- G : Graph
- An undirected graph with the same name and nodes and with edge (u,v,data) if either (u,v,data) or (v,u,data) is in the digraph. If both edges exist in digraph and their edge data is different, only one edge is created with an arbitrary choice of which edge data to use. You must check and correct for this manually if desired.
If edges in both directions (u,v) and (v,u) exist in the graph, attributes for the new undirected edge will be a combination of the attributes of the directed edges. The edge data is updated in the (arbitrary) order that the edges are encountered. For more customized control of the edge attributes use add_edge().
This returns a “deepcopy” of the edge, node, and graph attributes which attempts to completely copy all of the data and references.
This is in contrast to the similar G=DiGraph(D) which returns a shallow copy of the data.
See the Python copy module for more information on shallow and deep copies, http://docs.python.org/library/copy.html.
Warning: If you have subclassed DiGraph to use dict-like objects in the data structure, those changes do not transfer to the Graph created by this method.
-
vistoms_add
(vistoms_dir, mpg=None, function_order=None, reference_file=None, compress=False, remove_after_compress=True, graph_id=None, replacement_id=None)¶ Function to add a graph to a existing VISTOMS instance.
In one VISTOMS instance different graphs can be shown. For example it is possible to include different architectures for the same problem in one VISTOMS instance.
Parameters: - vistoms_dir (str) – directory of the VISTOMS directory to be used for addition
- mpg (MdaoProcessGraph) – optional MPG graph to be saved with MDG as XDSM (if None a DSM is created)
- function_order (list) – optional function order for the diagonal of the graph (only applicable for DSMs)
- reference_file (str) – file from which reference values are extracted (either full path or file in same folder)
- compress (bool) – setting whether to compress the final VISTOMS instance folder to a zip file
- remove_after_compress (bool) – setting whether to remove the original folder after compression
- replacement_id (basestr) – indentifier of the graph to be replaced
-
vistoms_create
(vistoms_dir, vistoms_version=None, mpg=None, function_order=None, reference_file=None, compress=False, remove_after_compress=True, graph_id=None, use_png_figs=False, file_refs=None)¶ Function to create a new VISTOMS instance from a graph.
Parameters: - vistoms_dir (str) – directory of the VISTOMS directory to be created
- vistoms_version – version of the VISTOMS instance to be used (as stored in the package itself)
- vispack_version – str
- mpg (MdaoProcessGraph) – optional MPG graph to be saved with MDG as XDSM (if None a DSM is created)
- function_order (list) – optional function order for the diagonal of the graph (only applicable for DSMs)
- reference_file (str) – file from which reference values are extracted (either full path or file in same folder)
- compress (bool) – setting whether to compress the final VISTOMS instance folder to a zip file
- remove_after_compress (bool) – setting whether to remove the original folder after compression
- graph_id (basestring) – identifier of the new graph
- use_png_figs (bool) – setting whether to use the PNG figures instead of the SVG figures for local execution
- file_refs (dict) – setting to provide file references manually (to use VISTOMS on a server)
-
RepositoryConnectivityGraph¶
-
class
kadmos.graph.
RepositoryConnectivityGraph
(*args, **kwargs)¶ -
cleancopy
()¶ Method to make a clean copy of a graph.
This method can be used to avoid deep-copy problems in graph manipulation algorithms. The graph class is kept.
Returns: clean-copy of the graph Return type: RepositoryConnectivityGraph
-
get_fpg_based_on_function_nodes
(*args, **kwargs)¶ Function to get the Fundamental Problem Graph based on a list of (or a single) function.
Parameters: - args (str) – node names of functions of interest
- kwargs (name: str) – name: name of the graph to be generated
Returns: Fundamental Problem Graph object
Return type:
-
get_fpg_based_on_list_functions
(list_of_functions, name='FPG')¶ Function to get a Fundamental Problem Graph based on a list of functions.
Parameters: - list_of_functions (list) – list with strings that specify the desired functions
- name (str) – name of the graph to be generated
Returns: Fundamental Problem Graph object
Return type:
-
get_fpg_based_on_sinks
(list_of_sinks, name='FPG')¶ Function to get the a Fundamental Problem Graph based on a list of sinks/required output variables.
Parameters: - list_of_sinks (list) – list with strings that specify the desired output
- name (str) – name of the graph to be generated
Returns: Fundamental Problem Graph object
Return type:
-
get_fpg_by_function_nodes
(*args)¶ This function creates a new (FPG)-graph based on the selected function nodes.
Returns: new fpg graph Return type: FundamentalProblemGraph
-
get_function_paths_by_objective
(*args, **kwargs)¶ This function takes an arbitrary amount of objective nodes as graph sinks and returns all path combinations of tools.
If no arguments are given, user is prompted to select objectives from the graph.
The tool combinations are found using the function itertools.product() and can lead to significant computation times for large graphs. If this is the case, the user is prompted whether to continue or not.
A variety of filters can be applied to the search of possible tools combinations, some of which reduce the computation time.
kwargs: obj_vars_covered - ensures that all objective variables are used in tool configurations ignore_funcs - ignores functions for the config source - source node; if provided, must be in config
Parameters: - args – arbitrary amount of objective nodes
- kwargs – filter options to limit possible path combinations
Returns: all possible FPG path combinations for the provided objective nodes
-
get_path_combinations
(*args, **kwargs)¶ This function takes lists of subsets and generates all possible combinations between them.
This is done by using the itertools.product() function. If the amount of expected evaluations exceeds a pre-set minimum, the user will be asked if to continue or not; because the process can take a long time and use up many resources.
Optional arguments: min_func: minimum amount of functions in each configuration max_func: maximum amount of functions in each configuration
Parameters: args (list) – lists of subsets that will be used to find configurations Returns: set of all unique path combinations
-
select_function_combination_from
(*args, **kwargs)¶ This function takes all provided workflow configurations and lists them according to their characteristics.
The user can then choose the workflow configuration from the list. A warning is given to the user if the amount of total configurations exceeds n = 1e4. Print limit is set to [0-20] by default. sort_by must be one of [“couplings”, “system_inputs”, “edges”, “nodes”].
-
FundamentalProblemGraph¶
-
class
kadmos.graph.
FundamentalProblemGraph
(*args, **kwargs)¶ -
add_function_problem_roles
(function_order_method='manual')¶ Method to add the function problem roles (pre-coupled, coupled, post-coupled functions).
Parameters: function_order_method (basestring) – algorithm to be used for the order in which the functions are executed.
-
cleancopy
()¶ Method to make a clean copy of a graph.
This method can be used to avoid deep-copy problems in graph manipulation algorithms. The graph class is kept.
Returns: clean-copy of the graph Return type: FundamentalProblemGraph
-
create_mdg
(mg_function_ordering, name='MDG')¶ Function to automatically create an MDG based on an FPG.
Parameters: - mg_function_ordering (dict) – dictionary with MDAO graph function ordering
- name (basestring) – name for the MDG graph
Returns: baseline MDG (only added additional action blocks, no changed connections)
Return type:
-
create_mpg
(mg_function_ordering, name='MPG')¶ Function to automatically create a MPG based on a FPG.
Parameters: - mg_function_ordering (dict) – dictionary with MDAO graph function ordering
- name (basestring) – name for the MPG graph
Returns: unconnected FPG (only action blocks and their diagonal position)
Return type:
-
get_coupling_matrix
(function_order_method='manual')¶ Function to determine the role of the different functions in the FPG.
Parameters: function_order_method (basestring) – algorithm to be used for the order in which the functions are executed. Returns: graph with enriched function node attributes and function problem role dictionary Return type: FundamentalProblemGraph
-
get_mdg
(name='MDG')¶ Create the MDAO data graph for a given FPG.
Parameters: name (basestring) – name of the new graph Returns: MDAO data graph Return type: MdaoDataGraph
-
get_mg_function_ordering
()¶ Method to determine the function ordering for MDAO graphs (FPG and MDG) based on an FPG.
Function ordering has to be adjusted when design variables are used. In that case, the pre-coupling functions have to be divided in two parts: the first part does not use the design variables yet, while the second does.
Returns: function ordering dictionary Return type: dict
-
get_mpg
(name='MPG', mdg=None)¶ Create the MDAO process graph for a given FPG.
Parameters: - name (basestring) – name of the new graph
- mdg (MdaoDataGraph) – data graph to be used for process optimization
Returns: MDAO process graph
Return type:
-
mark_as_constraint
(nodes, lower_bounds=None, upper_bounds=None)¶ Method to mark a list of nodes as constraint.
Parameters: - nodes (list) – list of nodes present in the graph
- lower_bounds (list) – list of lower bound values
- upper_bounds (list) – list of upper bound values
-
mark_as_design_variable
(nodes, lower_bounds=None, nominal_values=None, upper_bounds=None, samples=None)¶ Method to mark a list of nodes as design variable and add metadata.
Parameters: - nodes (list) – list of nodes present in the graph
- lower_bounds (list) – list of lower bound values
- nominal_values (list) – list of nominal values
- upper_bounds (list) – list of upper bounds
- samples (list) – nested list of kadmos values
-
mark_as_objective
(node)¶ Method to mark a single node as objective.
Parameters: node (basestring) – variable node
-
mark_as_qoi
(nodes)¶ Function to mark a list of nodes as quantity of interest.
Parameters: nodes (list) – list of nodes present in the graph
-
MdaoProcessGraph¶
-
class
kadmos.graph.
MdaoProcessGraph
(*args, **kwargs)¶ -
add_parallel_process
(start_nodes, parallel_functions, start_step, end_node=None, end_in_converger=False, use_data_graph=None)¶ Method to add a process to run multiple functions in parallel from a single start node.
Parameters: - start_nodes (basestring or list) – node or list of nodes from which all the functions are executed in parallel
- parallel_functions (list) – list of function to be run in parallel from the start node
- start_step (int) – process step number of the start_node
- end_node (basestring) – (optional) node to which all the parallel functions go after execution
- end_in_converger (bool) – (optional) indicate whether the end node finishes a convergence loop
- use_data_graph (MdaoDataGraph or None) – (optional) use data graph to assess whether nodes are actually coupled
-
add_simple_sequential_process
(functions, start_step, end_in_iterative_node=None)¶ Method to add a simple sequential process to a list of functions.
The sequence is assumed to be the order of the functions in the input list. The sequence is considered simple, since it is not analyzed for the possibility to run functions in parallel.
Parameters: - functions (list) – list of functions in the required sequence
- start_step –
- end_in_iterative_node (basestring) – (optional) iterative node to which the last function should go
-
cleancopy
()¶ Method to make a clean copy of a graph.
This method can be used to avoid deep-copy problems in graph manipulation algorithms. The graph class is kept.
Returns: clean-copy of the graph Return type: MdaoProcessGraph
-
connect_nested_iterators
(master, slave)¶ Method to connect a slave iterator to a master iterator in a nested configuration.
An example is if a converger inside an optimizer in MDF needs to be linked back.
Parameters: - master (basestring) – upper iterator node in the nested configuration
- slave (basestring) – lower iterator node in the nested configuration
-
get_nested_process_ordering
()¶ Method to determine the nesting of iterative elements in the process graph.
Returns: tuple with iterative_nodes, process_info dictionary, and nested_functions list Return type: tuple
-
get_node_text
(node)¶ Method to determine the text of a function node (for use in a XDSM diagram).
Parameters: node (basestring) – node Returns: node text for in the XDSM function box Return type: basestring
-
get_process_list
(use_d3js_node_ids=True)¶ Method to get the xdsm workflow process list (for use in dynamic visualizations).
Parameters: use_d3js_node_ids (bool) – setting whether node names should be changed into node ids according to D3js notation. Returns: process list Return type: list
-
inspect_process
()¶ Method to print the MPG.
-
MdaoDataGraph¶
-
class
kadmos.graph.
MdaoDataGraph
(*args, **kwargs)¶ -
cleancopy
()¶ Method to make a clean copy of a graph.
This method can be used to avoid deep-copy problems in graph manipulation algorithms. The graph class is kept.
Returns: clean-copy of the graph Return type: MdaoDataGraph
-
connect_converger
(converger, conv_type, coupling_functions, include_couplings_as_final_output)¶ Method to automatically connect a converger around a collection of coupled functions.
Parameters: - converger (basestring) – name of the converger to be connected
- conv_type (basestring) – setting for the type of convergence (Jacobi, Gauss-Seidel)
- coupling_functions (list) – list of coupled functions
- include_couplings_as_final_output (bool) – setting on whether coupling variables should always be added as output
-
connect_coordinator
()¶ Method to automatically connect all system inputs and outputs of a graph to the coordinator node.
-
connect_doe_block
(doe_block, design_variable_nodes, qoi_nodes)¶ Method to automatically connect an doe_block w.r.t. the design variables, objective, and constraints.
Parameters: - doe_block (basestring) – name of the doe_block to be connected
- design_variable_nodes (list) – list of design variables
- qoi_nodes (list) – list of constraint nodes
Returns: enriched MDAO data graph with connected doe_block
Return type:
-
connect_nodes_as_output
(nodes, function)¶ Method to connect a list of nodes as output to a function node.
Parameters: - nodes (list) – list of nodes to be connected as output
- function (basestring) – function to which the nodes are connected
-
connect_optimizer
(optimizer, design_variable_nodes, objective_node, constraint_nodes)¶ Method to automatically connect an optimizer w.r.t. the design variables, objective, and constraints.
Parameters: - optimizer (basestring) – name of the optimizer to be connected
- objective_node (basestring) – node used as objective by the optimizer
- constraint_nodes (list) – list of constraint nodes
Returns: enriched MDAO data graph with connected optimizer
Return type:
-
connect_qoi_nodes_as_input
(nodes, function, override_with_final_outputs)¶ Method to connect a list of qoi nodes as input to a given function node.
Parameters: - nodes (list) – list of nodes to be connected as input
- function (basestring) – function to which the nodes are connected
- override_with_final_outputs (bool) – setting on whether to override the use of final outputs
-
copy_node_as
(node, architecture_role)¶ Method to copy a given node for an architecture role.
Parameters: - node (str) – node to be copied
- architecture_role (basestring) – architecture role of the copied node
Returns: modified node
-
manipulate_coupling_nodes
(func_order, remove_feedback, remove_feedforward, converger=None, include_couplings_as_final_output=False)¶ Method to manipulate the coupling nodes in a data graph in order to remove unwanted feedback/feedforward.
Parameters: - func_order (list) – the order of the functions to be analyzed
- remove_feedback (bool) – setting on whether feedback coupling should be removed
- remove_feedforward (bool) – setting on whether feedforward coupling should be removed
- converger (basestring or None) – setting on whether the couplings should be linked to a converger
- include_couplings_as_final_output (bool) – setting on whether coupling variables should always be added as output
-
Utilities¶
Below the utilities used by KADMOS are listed.
-
kadmos.utilities.general.
color_list
()¶ A list of distinguisable colors.
Returns: list with HTML Hex colors
-
kadmos.utilities.general.
export_as_json
(data, filename, indent=None, sort_keys=True, cwd=None)¶ Function to export a data object to a json file.
Parameters: - data (dict or list) – object with the data to be exported
- filename (basestring) – name of the json file
- indent (int) – number of spaces for one indentation
- sort_keys (bool) – option for sorting keys
- cwd (None, str) – current working directory
Returns: json file
Return type: file
-
kadmos.utilities.general.
format_string_for_d3js
(string, prefix='', suffix='')¶ Function to format a string such that it can be used in the dynamic visualization package.
Parameters: - string (str) – string to be formatted
- prefix (basestring) – prefix to be placed in front of the string
- suffix (basestring) – suffix to be appended to the string
Returns: formatted string
Return type: basestring
-
kadmos.utilities.general.
get_element_dict
(xpath, var_value=None, var_dim=None, include_reference_data=False)¶ Function to create a D3.js-type dictionary for a nested tree based on an xpath.
Parameters: - xpath – xpath for the element
- var_value – value of the element in a reference file
- var_dim – dimension of the element in a reference file
- include_reference_data – setting on whether reference data should be include in the path
Returns: nested dictionary
-
kadmos.utilities.general.
get_friendly_id
(uid_length)¶ Create an ID string we can recognise. (Think Italian or Japanese or Native American.)
-
kadmos.utilities.general.
get_list_entries
(*args)¶ Utility to return only certain values of a given list based on the indices.
Parameters: args (list and int) – list and indices Returns: list with requested values at indices Return type: list
-
kadmos.utilities.general.
get_mdao_setup
(mdao_setup)¶ Simple function to specify the MDAO architecture and convergence type based on a single string.
Parameters: mdao_setup (str) – MDF-GS, MDF-J, IDF Returns: mdo_architecture, mda_type, allow_unconverged_couplings Return type: str
-
kadmos.utilities.general.
get_uid
(preference, uids)¶ Simple function to determine a valid uid which is not part of the uids list
Parameters: - preference (str) – preferred name for the uid
- uids (list) – list of existing uids
Returns: a valid uid which
Return type: str
-
kadmos.utilities.general.
get_unique_friendly_id
(used_ids, uid_length)¶ Return an ID that is not in our list of already used IDs.
-
kadmos.utilities.general.
hex_to_rgb
(value)¶ Function to translate a hex color string to an RGB color tuple.
Parameters: value (str) – HTML hex color Returns: RGB colors Return type: tuple
-
kadmos.utilities.general.
make_camel_case
(string, make_plural_option=False)¶ Function to make a string camelCase.
Parameters: - string (str) – non-camelcase string
- make_plural_option (bool) – pluralize camelcase string
Returns: camelcase string
Return type: str
-
kadmos.utilities.general.
make_plural
(string)¶ Function to convert a string to its plural form.
Parameters: string (str) – initial string Returns: plural string Return type: str
-
kadmos.utilities.general.
make_singular
(string)¶ Function to convert a string to its singular form.
Parameters: string (str) – initial string Returns: singular string Return type: str
-
kadmos.utilities.general.
open_file
(filename)¶ Utility to open a file cross-platform.
Parameters: filename – Filename including extension and path, e.g. ‘sampledir/samplefile.pdf’ Returns: An opened file
-
kadmos.utilities.general.
remove_if_exists
(input_list, entries_to_remove)¶ Utility to remove certain values from a list.
Parameters: - input_list (list) – initial list
- entries_to_remove (list) – values to remove
Returns: list with removed entries
Return type: list
-
kadmos.utilities.general.
test_attr_cond
(attr_value, operator, test_value)¶ Function to check a given conditional statement and return True or False.
Parameters: - attr_value (str, float, int) – value of the actual attribute
- operator (str) – conditional operator to be used (‘<’,’<=’,’==’,’!=’,’>=’,’>’, ‘in’)
- test_value (str, float, int) – value to which the attribute value should be compared.
Returns: result of the conditional statement.
Return type: bool
-
kadmos.utilities.general.
transform_data_into_strings
(data, keys_to_be_removed=[])¶ Utility function to transform certain data types in a dictionary into strings.
Parameters: - data (dict) – dictionary with data
- keys_to_be_removed (list) – list of keys that have to be removed from the dict
Returns: adjusted dictionary
Return type: dict
-
kadmos.utilities.general.
transform_string_into_format
(data, keys_to_be_removed=[])¶ Utility function to transform certain strings back into their original data format (NoneType, list, etc.).
Parameters: - data (dict) – dictionary with data
- keys_to_be_removed (list) – list of keys that have to be removed from the dict
Returns: adjusted dictionary
Return type: dict
-
kadmos.utilities.general.
translate_dict_keys
(dictionary, translations)¶ Utility to (recursively) translate all keys in a dictionary with a translation dictionary.
Parameters: - dictionary – dictionary to be translated
- translations – dictionary used for the translation
Returns: translated dictionary
-
kadmos.utilities.general.
translate_list
(l, dictionary)¶ Utility to quickly translate all elements in a list with a dictionary.
Parameters: - l – list to be translated
- dictionary – dictionary used for the translation
Returns: translated list
-
kadmos.utilities.general.
unmake_camel_case
(string, separator='_')¶ Function to make camelCase a string with separator (e.g. underscores).
Parameters: - string (str) – camelCase string
- separator – symbol/symbols used as separator
Returns: string with separator
Return type: str