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

Work in progress on CMDOWS functions

Former-commit-id: 6d17cb7dff64445bd0e35a1b276639fdb5889581
parent 0e5f83e1
No related branches found
No related tags found
No related merge requests found
Showing
with 98 additions and 60 deletions
......@@ -9,7 +9,6 @@ import sys
import itertools
import filecmp
import time
import ast
import copy
 
import shutil
......@@ -38,7 +37,7 @@ from pyKADMOS.sample.rce import RceWorkflow
from pyKADMOS.sample.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
recursively_stringify, make_plural
from pyKADMOS.sample.utilities import color_list, test_attr_cond, hex_to_rgb
 
from pyKADMOS.sample import prompt_utilities as PRO
......@@ -3024,7 +3023,7 @@ class KadmosGraph(nx.DiGraph):
if isinstance(graph, FundamentalProblemGraph) or isinstance(graph, MdaoDataGraph):
if not graph.check():
if kadmos_check_critical:
raise AssertionError('The graph is not valid according to KADMOS.')
raise IOError('The graph is not valid according to KADMOS.')
else:
warnings.warn('The graph is not valid according to KADMOS.'
'The validity of the CMDOWS output is not guaranteed.', Warning)
......@@ -3156,7 +3155,7 @@ class KadmosGraph(nx.DiGraph):
Child(cmdows_problem_role, 'parameterUID', graph_problem_role)
for cmdows_problem_role_attr in cmdows_parameterDef[1]:
if cmdows_problem_role_attr == 'samples':
# TODO: Make more feneric for all lists
# TODO: Make more generic for all lists
# Create e.g. problemDefinition/problemRoles/parameters/designVariables/designVariable/samples
cmdows_samples = Child(cmdows_problem_role, 'samples')
if graph.node[graph_problem_role].get(cmdows_problem_role_attr) is not None:
......@@ -3224,7 +3223,7 @@ class KadmosGraph(nx.DiGraph):
# Create architectureElements/parameters/...
for architecture_roles_var in graph.ARCHITECTURE_ROLES_VARS:
cmdows_parameter = Child(cmdows_parameters,
make_camel_case(architecture_roles_var, make_plural=True))
make_camel_case(architecture_roles_var, make_plural_option=True))
graph_parameter_nodes = graph.find_all_nodes(attr_cond=['architecture_role', '==', architecture_roles_var])
for graph_parameter_node in graph_parameter_nodes:
cmdows_parameter_node = Child(cmdows_parameter, make_camel_case(architecture_roles_var))
......@@ -3262,7 +3261,7 @@ class KadmosGraph(nx.DiGraph):
for architecture_roles_fun in architecture_roles_funs:
nodes = graph.find_all_nodes(attr_cond=['architecture_role', '==', str(architecture_roles_fun)])
cmdows_analyses = Child(cmdows_executable_blocks, make_camel_case(architecture_roles_fun,
make_plural=True))
make_plural_option=True))
for node in nodes:
cmdows_analysis = Child(cmdows_analyses, make_camel_case(architecture_roles_fun))
Child(cmdows_analysis, 'relatedExecutableBlockUID', node)
......@@ -4148,7 +4147,7 @@ class KadmosGraph(nx.DiGraph):
 
def load_from_cmdows(filename, source_folder=None, kadmos_check_critical=True):
"""
Method to load a KadmosGraph object from a CMDOWS file. Right now can handle RCG and FPG.
Method to load a KadmosGraph object from a CMDOWS file. Can handle RCGs and FPGs right now.
 
:param filename: name of the file to be opened
:type filename: basestring
......@@ -4264,14 +4263,16 @@ def load_from_cmdows(filename, source_folder=None, kadmos_check_critical=True):
else:
arr = list()
for cmdows_block in list(cmdows_blocks):
# TODO: Check if selection of node is unambiguous
graph.node[cmdows_block.text]['problem_role'] = role[:-5]
if graph.node.get(cmdows_block.text) == None:
# Add note if it does not exist yet
# TODO: Load architecture elements before problem definition
graph.add_node(cmdows_block.text, category='function')
graph.node[cmdows_block.text]['problem_role'] = role
arr.append(cmdows_block.text)
graph.graph['problem_formulation']['function_ordering'][role] = arr
 
# Add attributes to the variable nodes
# TODO: Get array from somewhere else
variable_types = ['designVariables', 'objectiveVariables', 'constraintVariables', 'stateVariables']
variable_types = [make_plural(role[0]) for role in graph.CMDOWS_ROLES_DEF]
for variable_type in variable_types:
cmdows_variables = cmdows_problem_roles.find('parameters/'+variable_type)
if cmdows_variables is not None:
......@@ -4291,15 +4292,23 @@ def load_from_cmdows(filename, source_folder=None, kadmos_check_critical=True):
cmdows_sample_data[int(cmdows_sample.get('position')) - 1] = float(cmdows_sample.text)
graph.node[cmdows_parameter_uid][
graph.CMDOWS_ATTRIBUTE_DICT_INV[attribute.tag]] = cmdows_sample_data
# The following nodes and edges are only generated for MDGs
if isinstance(graph, MdaoDataGraph):
 
# TODO: First set up architecture
#cmdows_architecture_parameters = cmdows.find('architectureElements/parameters')
#for cmdows_architecture_parameter in list(cmdows_architecture_parameters):
# for cmdows_single_architecture_parameter in list(cmdows_architecture_parameter):
# graph.node[cmdows_single_architecture_parameter.get('uID')]
for node, data in graph.nodes_iter(data=True):
print node
print data
 
# TODO: First set up architecture
cmdows_architecture_parameters = cmdows.find('architectureElements/parameters')
for cmdows_architecture_parameter in list(cmdows_architecture_parameters):
for cmdows_single_architecture_parameter in list(cmdows_architecture_parameter):
cmdows_uid = cmdows_single_architecture_parameter.get('uID')
graph.add_node(cmdows_block.text,
category='variable',
related_to_schema_node = cmdows_single_architecture_parameter.findtext('relatedParamterUID'),
label = cmdows_single_architecture_parameter.findtext('label'))
 
# Create MDG edges
cmdows_data_graph = cmdows.find('workflow/dataGraph')
......@@ -4318,10 +4327,12 @@ def load_from_cmdows(filename, source_folder=None, kadmos_check_critical=True):
# print graph.node[node]
 
# Check of graph
# TODO: Add kadmos_check_critical check
if isinstance(graph, FundamentalProblemGraph) or isinstance(graph, MdaoDataGraph):
if not graph.check():
logger.warning('The graph created from the CMDOWS file is invalid.')
#if isinstance(graph, FundamentalProblemGraph) or isinstance(graph, MdaoDataGraph):
# if not graph.check():
# if kadmos_check_critical:
# raise IOError('The graph created from the CMDOWS file is invalid.')
# else:
# logger.warning('The graph created from the CMDOWS file is invalid.')
 
# Finish
logger.info('CMDOWS file ' + path + ' loaded.')
......@@ -4348,7 +4359,7 @@ def cmdows_integrity_check(graph, MPG=None):
timestamp = datetime.now()
graph.save_as_cmdows('testfile1', 'test description', 'test author', '1.1', timestamp=timestamp, MPG=MPG,
kadmos_check_critical=False, pretty_print=True)
check = load_from_cmdows('testfile1')
check = load_from_cmdows('testfile1', kadmos_check_critical=False)
check.save_as_cmdows('testfile2', 'test description', 'test author', '1.1', timestamp=timestamp, kadmos_check_critical=False, pretty_print=True)
# First try file wise comparison
if filecmp.cmp('testfile1.xml', 'testfile2.xml'):
......@@ -4365,6 +4376,7 @@ def cmdows_integrity_check(graph, MPG=None):
result_a = True
else:
result_a = False
logger.info('The following elements are not loaded: '+ str([x for x in list if x not in set(checklist)]))
 
# Check if the file adheres to the schema
try:
......
......@@ -319,7 +319,27 @@ def extend_list_uniquely(original_list, extension_list):
return list(set(original_list))
def make_camel_case(string, make_plural=False):
def make_plural(string):
"""
Function to convert a string to its plural form.
:param string: initial string
:type string: str
:return: plural string
:rtype: str
"""
if string[-2:] == 'is':
# e.g. 'analysis' should become 'analyses'
string = string[:-2] + 'es'
else:
# e.g. 'variable' should become 'variables'
string += 's'
return string
def make_camel_case(string, make_plural_option=False):
"""
Function to make a string camelCase.
......@@ -335,13 +355,8 @@ def make_camel_case(string, make_plural=False):
words = word_regex_pattern.split(string)
string = "".join(w.lower() if i is 0 else w.title() for i, w in enumerate(words))
if make_plural:
if string[-2:] == 'is':
# e.g. 'analysis' should become 'analyses'
string = string[:-2] + 'es'
else:
# e.g. 'variable' should become 'variables'
string = string + 's'
if make_plural_option:
string = make_plural(string)
return string
......@@ -535,7 +550,7 @@ def ChildGroup(graph, attr_name, attr_value, data_list):
assert isinstance(data_list, list)
# Element
element = Element(make_camel_case(attr_value, make_plural=True))
element = Element(make_camel_case(attr_value, make_plural_option=True))
# Nodes
nodes = graph.find_all_nodes(attr_cond=[attr_name, '==', attr_value])
......
import os
import logging
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
from pyKADMOS.sample.graph import load_from_cmdows
source_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'sellarProblemRCE')
graph = load_from_cmdows('MDAO_IDF.xml', source_folder=source_folder)
#print graph.find_all_nodes()
\ No newline at end of file
......@@ -30,15 +30,15 @@ import json
import os
import sys
import logging
#logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
from pyKADMOS.sample.graph import FundamentalProblemGraph, load_from_cmdows, cmdows_integrity_check
from pyKADMOS.sample.knowledgebase import KnowledgeBase
from pyKADMOS.sample.utilities import get_mdao_setup
# Script settings
loop_all = True # Loop through all mdao_definition
mdao_definition_id = 7 # If not loop_all = False, select the required MDAO architecture from mdao_definitions
loop_all = False # Loop through all mdao_definition
mdao_definition_id = 10 # If not loop_all = False, select the required MDAO architecture from mdao_definitions
open_pdfs = False # Automatically open PDFs of the (X)DSMs while running the script
pdfs_folder = 'sellarProblemRCE' # Subfolder to store the PDF in
script_rce_workflows = True # Set to True to script the RCE workflows
......@@ -177,7 +177,7 @@ for mdao_definition in mdao_definitions:
# Save graph
FPG.save_as_cmdows('FPG_'+mdao_definition, 'Test FPG file', 'Imco van Gent', '0.1', destination_folder=pdfs_folder,
pretty_print=True)
cmdows_integrity_check(FPG)
#cmdows_integrity_check(FPG)
# Get graphs
MPG = FPG.get_mpg(name='MPG Sellar problem')
......@@ -191,6 +191,8 @@ for mdao_definition in mdao_definitions:
MDG.plot_graph(11, color_setting='default', fig_size=fig_size, show_now=False)
# Save graph
print MPG.find_all_nodes()
print MPG.node['Gc']
MDG.save_as_cmdows('MDAO_'+mdao_definition, 'Test MDAO file', 'Imco van Gent', '0.1', MPG=MPG,
destination_folder=pdfs_folder, pretty_print=True)
#cmdows_integrity_check(MDG, MPG=MPG)
......
No preview for this file type
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:25:41.626000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:25:41.626000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:04:27.985000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:04:27.985000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:04:27.985000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:04:27.985000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test FPG file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS export of a fundamental problem graph (FPG).</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:21:00.776000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
No preview for this file type
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test MDAO file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:25:41.626000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS Export of a mdao data graph (MDG) graph.</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:25:41.626000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
No preview for this file type
......@@ -3,14 +3,14 @@
<header>
<creator>Imco van Gent</creator>
<description>Test MDAO file</description>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:04:27.985000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
<updates>
<update>
<modification>KADMOS Export of a mdao data graph (MDG) graph.</modification>
<creator>Imco van Gent</creator>
<timestamp>2017-03-28T19:31:14.644000</timestamp>
<timestamp>2017-04-11T10:04:27.985000</timestamp>
<fileVersion>0.1</fileVersion>
<cmdowsVersion>0.4</cmdowsVersion>
</update>
......
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