Skip to content
Snippets Groups Projects
Commit 7cd2d13f authored by imcovangent's avatar imcovangent
Browse files

Added and tested addition of vistoms_start() for multiple graphs.

Added use of vistoms_start() in ssbj_mdo script for testing purposes.


Former-commit-id: 713f88cad680a482ca3e4dc96d892151a53b58ba
parent ebb7cde5
No related branches found
No related tags found
No related merge requests found
Pipeline #192808 canceled
......@@ -5,6 +5,8 @@ import logging
from kadmos.graph import FundamentalProblemGraph, load
# Settings for logging
from kadmos.graph.mixin_vistoms import vistoms_start
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
# List of MDAO definitions that can be wrapped around the problem
......@@ -13,10 +15,12 @@ mdao_definitions = ['MDF-GS', # 0
'IDF', # 2
'CO', # 3
'BLISS-2000'] # 4
all_graphs = []
# Settings for scripting
mdao_definitions_loop_all = True # Option for looping through all MDAO definitions
mdao_definition_id = 2 # Option for selecting a MDAO definition (in case mdao_definitions_loop_all=False)
start_interactive_vistoms = True # Option to start an interactive VISTOMS at the end
# Settings for loading and saving
kb_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../knowledgebases')
......@@ -95,8 +99,7 @@ rcg.add_contact_roles('lmuller', roles='integrator')
# Create a DSM and a VISTOMS visualization of the RCG
rcg.create_dsm('RCG_extended', include_system_vars=True, destination_folder=pdf_dir, function_order=function_order)
# rcg.vistoms_create(vistoms_dir, function_order=function_order)
rcg.vistoms_start(vistoms_dir)
rcg.vistoms_create(vistoms_dir, function_order=function_order)
# Save CMDOWS and KDMS file
rcg.save('RCG', destination_folder=kdms_dir)
......@@ -108,6 +111,7 @@ rcg.save('RCG',
destination_folder=cmdows_dir,
pretty_print=True,
integrity=True)
all_graphs.append(rcg)
# On to the wrapping of the MDAO architectures
# Get iterator (all or single one)
......@@ -186,6 +190,7 @@ for mdao_definition in mdao_definitions:
fpg.add_problem_formulation(mdao_definition, function_order,
doe_settings=None if mdao_definition is not 'BLISS-2000' else
{'doe_method': 'Latin hypercube design', 'doe_seed': 5, 'doe_runs': 50})
all_graphs.append(fpg)
# Get Mdao graphs
mdg, mpg = fpg.impose_mdao_architecture()
......@@ -214,5 +219,9 @@ for mdao_definition in mdao_definitions:
version='0.1',
pretty_print=True,
integrity=True)
all_graphs.append((mdg,mpg))
logging.info('Done!')
if start_interactive_vistoms:
vistoms_start(all_graphs, file_dir='ssbj/VISTOMStest')
......@@ -55,7 +55,7 @@ class VistomsMixin(object):
"""
# Logging
logger.info('Creating the VISTOMS instance (this might take a while)...')
logger.info('Creating the VISTOMS instance...')
# If destination folder is given, create + use that
if file_dir is not None:
......@@ -919,6 +919,51 @@ class VistomsMixin(object):
return variable_tree_categorized_function_level
def vistoms_start(graphs, file_dir=None):
"""Function to open an interactive VISTOMS based on a list of data and (optionally) process graphs. If file_dir is
not provided then the files are stored in a temp directory.
:param graphs: list or tuple with graphs. For pure data graphs, provide the graph object directly in the list. For
data+process graphs, provide them as a list or tuple pair with first the data graph and then process graph.
:type graphs: list or tuple
:param file_dir: folder name or path where the graphs used in the interactive VISTOMS will be stored.
:type file_dir: path
:param mpg: MDAO process graph to be used in combination with the data graph.
:type mpg: MdaoProcessGraph
:return: interactive VISTOMS
:rtype: file
"""
# Logging
logger.info('Creating the VISTOMS instance...')
# Assert input
assert isinstance(graphs, (list, tuple)), 'Input should be of type list or tuple, now: {}.'.format(type(graphs))
# If destination folder is given, create + use that
if file_dir is not None:
if os.path.isdir(file_dir):
shutil.rmtree(file_dir)
os.mkdir(file_dir)
vistoms_dir = os.path.abspath(file_dir)
# Else create temporary directory
else:
temp_dir = tempfile.mkdtemp()
vistoms_dir = os.path.abspath(temp_dir)
# Save the graphs in the folder
for i, graph in enumerate(graphs):
i_str = format(len(graphs)-i, '02d')
if isinstance(graph, (list, tuple)):
graph[0].save('tmp_{}.kdms'.format(i_str), destination_folder=vistoms_dir, mpg=graph[1])
else:
graph.save('tmp_{}.kdms'.format(i_str), destination_folder=vistoms_dir)
# Then run interactive VISTOMS
from kadmos.vistoms.vistoms import run_vistoms
run_vistoms(folder=vistoms_dir)
def vistoms_remove(graph_id, vistoms_dir, compress=False, remove_after_compress=True):
""" Function to remove a graph from a VISTOMS instance.
......
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