Skip to content
Snippets Groups Projects
Commit 9bc117eb authored by Lukas Müller's avatar Lukas Müller
Browse files

Start on graph restructuring

Former-commit-id: 4162b2da0dec7d7d0647606e05b7e64d5721e228
parent d8593d72
No related branches found
No related tags found
No related merge requests found
Pipeline #192809 canceled
from kadmos_graph import *
from data_graph import *
from process_graph import *
\ No newline at end of file
This diff is collapsed.
# Imports
import json
import os
import re
import warnings
import pprint
import uuid
import sys
import itertools
import filecmp
import time
import copy
import tempfile
import shutil
import distutils.util
import urllib2
import logging
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
from lxml import etree
from lxml.etree import ElementTree, Element
from operator import itemgetter
from datetime import datetime
from collections import OrderedDict as OrdDict
from copy import deepcopy
from pyKADMOS.packages.XDSM_writer.XDSM import XDSM
from pyKADMOS.packages.D3_vispack import D3_vispack as D3vp
from .. import prompt_utilities as PRO
from .. import print_utilities as PRI
from ..XMLutilities import build_xpath, get_element_dict, merge
from ..print_utilities import print_indexed_list
from ..rce import RceWorkflow
from ..utilities import transform_data_into_strings, transform_string_into_format, extend_list_uniquely,\
export_as_json, move_and_open, make_camel_case, unmake_camel_case, get_list_entries, open_file, Child, ChildGroup,\
recursively_empty, format_string_for_d3js, get_unique_friendly_id, ChildSequence, remove_if_exists,\
recursively_stringify, make_plural, recursively_dictify, check, color_list, test_attr_cond, hex_to_rgb
from ..plot_utilities import AnnoteFinder
from kadmos_graph import KadmosGraph
# Settings for the logger
logger = logging.getLogger(__name__)
class MdaoGraph(KadmosGraph):
def __init__(self, *args, **kwargs):
super(MdaoGraph, self).__init__(*args, **kwargs)
def remove_node_from_diagonal(self, node):
"""Function to remove a node from the diagonal with functions.
:param node: node identifier
:type node: str
"""
# Input assertions
assert type(node) is str or type(node) is unicode
assert self.has_node(node), 'Node %s is not present in the graph.' % node
# Get current diagonal position of the node
diag_pos = self.node[node]['diagonal_position']
# Remove node
self.remove_node(node)
# Change diagonal positions according to removed node
for n, d in self.nodes_iter(data=True):
if 'diagonal_position' in d and n != node:
if d['diagonal_position'] > diag_pos:
d['diagonal_position'] -= 1
def insert_node_on_diagonal(self, node, diagonal_pos, attr_dict=None):
"""Function to insert a node on the diagonal with functions.
:param node: node identifier
:type node: str
:param diagonal_pos: integer with diagonal position (>= 0)
:type diagonal_pos: int
:param attr_dict: dictionary with node attributes
:type attr_dict: dict
"""
# Input assertions
assert type(node) is str or type(node) is unicode
assert type(diagonal_pos) is int
assert diagonal_pos > 0
if attr_dict is not None:
assert type(attr_dict) is dict
# Add or overwrite diagonal position in dictionary
if attr_dict is None:
attr_dict = dict()
attr_dict['diagonal_position'] = diagonal_pos
# Add node and given attributes
assert not self.has_node(node), 'Node %s is already present in the graph.' % node
self.add_node(node, attr_dict)
# Change diagonal positions according to inserted node
for n, d in self.nodes_iter(data=True):
if 'diagonal_position' in d and n != node:
if d['diagonal_position'] >= diagonal_pos:
d['diagonal_position'] += 1
# Imports
import json
import os
import re
import warnings
import pprint
import uuid
import sys
import itertools
import filecmp
import time
import copy
import tempfile
import shutil
import distutils.util
import urllib2
import logging
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
from lxml import etree
from lxml.etree import ElementTree, Element
from operator import itemgetter
from datetime import datetime
from collections import OrderedDict as OrdDict
from copy import deepcopy
from pyKADMOS.packages.XDSM_writer.XDSM import XDSM
from pyKADMOS.packages.D3_vispack import D3_vispack as D3vp
from .. import prompt_utilities as PRO
from .. import print_utilities as PRI
from ..XMLutilities import build_xpath, get_element_dict, merge
from ..print_utilities import print_indexed_list
from ..rce import RceWorkflow
from ..utilities import transform_data_into_strings, transform_string_into_format, extend_list_uniquely,\
export_as_json, move_and_open, make_camel_case, unmake_camel_case, get_list_entries, open_file, Child, ChildGroup,\
recursively_empty, format_string_for_d3js, get_unique_friendly_id, ChildSequence, remove_if_exists,\
recursively_stringify, make_plural, recursively_dictify, check, color_list, test_attr_cond, hex_to_rgb
from ..plot_utilities import AnnoteFinder
from kadmos_graph import KadmosGraph
from data_graph import FundamentalProblemGraph
from mdao_graph import MdaoGraph
# Settings for the logger
logger = logging.getLogger(__name__)
class ProcessGraph(KadmosGraph, MdaoGraph):
def __init__(self, *args, **kwargs):
super(ProcessGraph, self).__init__(*args, **kwargs)
class RceGraph(ProcessGraph):
def __init__(self, *args, **kwargs):
super(RceGraph, self).__init__(*args, **kwargs)
# Assertions
assert len(
self.find_all_nodes(category='variable group')) == 0, 'Variable groups are not allowed in an RceGraph.'
if 'rce_working_dir' in kwargs:
assert kwargs['rce_working_dir'][-1] == '/', 'Last character of working directory should be forward slash.'
self.rce_working_dir = kwargs['rce_working_dir']
if 'rce_wf_filename' in kwargs:
assert '.' not in kwargs['rce_wf_filename'], 'WF filename should be given without extension.'
self.rce_wf_filename = kwargs['rce_wf_filename']
class MdaoProcessGraph(ProcessGraph):
def __init__(self, *args, **kwargs):
super(MdaoProcessGraph, self).__init__(*args, **kwargs)
if 'fpg' in kwargs and 'mg_function_ordering' in kwargs:
fpg = kwargs['fpg']
mg_function_ordering = kwargs['mg_function_ordering']
assert isinstance(fpg, FundamentalProblemGraph)
fpg.check(raise_error=True)
self._add_action_blocks(fpg, mg_function_ordering)
self.graph['function_ordering'] = mg_function_ordering
del self.graph['fpg']
# ---------------------------------------------------------------------------------------------------------------- #
# CHECKING METHODS #
# ---------------------------------------------------------------------------------------------------------------- #
def _check_category_a(self):
"""Extended method to perform a category A check on the graph.
:return: result of the check and index
:rtype: bool, int
"""
# Set check
category_check, i = super(MdaoProcessGraph, self)._check_category_a()
# Get nodes
func_nodes = self.find_all_nodes(category='function')
var_nodes = self.find_all_nodes(category='variable')
# Get information
n_nodes = self.number_of_nodes()
n_functions = len(func_nodes)
n_variables = len(var_nodes)
# Checks on nodes
category_check, i = check(n_variables != 0,
'There are variable nodes present in the graph, namely: %s.' % str(var_nodes),
status=category_check,
category='A',
i=i)
category_check, i = check(n_nodes != n_functions,
'The number of total nodes does not match number of function nodes.',
status=category_check,
category='A',
i=i)
for node in func_nodes:
category_check, i_not = check('process_step' not in self.node[node],
'The process_step attribute is missing on the node %s.' % node,
status=category_check,
category='A',
i=i)
category_check, i_not = check('architecture_role' not in self.node[node],
'The architecture_role attribute is missing on the node %s.' % node,
status=category_check,
category='A',
i=i+1)
category_check, i_not = check(not self.has_node(self.COORDINATOR_STRING),
'The %s node is missing in the graph.' % self.COORDINATOR_STRING,
status=category_check,
category='A',
i=i+2)
i += 3
# Check on edges
for u, v, d in self.edges_iter(data=True):
category_check, i_not = check('process_step' not in d,
'The process_step attribute missing for the edge %s --> %s.' % (u, v),
status=category_check,
category='A',
i=i)
i += 1
# Return
return category_check, i
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment