diff --git a/kadmos/cmdows/schemas/0.9/cmdows.xml b/kadmos/cmdows/schemas/0.9/cmdows.xml index cff469de9a1e9216da3b7acdf634ffb964d0fec7..84c9ba8e0a4ec9e278ba7c39b398fe674eb219cf 100644 --- a/kadmos/cmdows/schemas/0.9/cmdows.xml +++ b/kadmos/cmdows/schemas/0.9/cmdows.xml @@ -830,8 +830,7 @@ <couplingWeights> <!--1 or more repetitions:--> <couplingWeight uID="string"> - <!--You have a CHOICE of the next 2 items at this level--> - <relatedParameterUID>string</relatedParameterUID> + <!--Optional:--> <relatedInstanceUID>string</relatedInstanceUID> <label>string</label> <instanceID>3</instanceID> @@ -953,24 +952,61 @@ <!--Optional:--> <surrogateModels> <!--1 or more repetitions:--> - <surrogateModel> - <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + <surrogateModel uID="string"> + <label>string</label> + <!--Optional:--> + <training> + <inputs> + <!--1 or more repetitions:--> + <input> + <parameterUID>anyType</parameterUID> + </input> + </inputs> + <!--1 or more repetitions:--> + <outputs> + <!--1 or more repetitions:--> + <output> + <parameterUID>string</parameterUID> + </output> + </outputs> + <settings> + <fittingMethod>string</fittingMethod> + </settings> + </training> + <!--Optional:--> + <prediction> + <inputs> + <!--1 or more repetitions:--> + <input> + <parameterUID>anyType</parameterUID> + </input> + </inputs> + <!--1 or more repetitions:--> + <outputs> + <!--1 or more repetitions:--> + <output> + <parameterUID>string</parameterUID> + </output> + </outputs> + </prediction> </surrogateModel> </surrogateModels> <!--Optional:--> - <boundaryDeterminators> - <!--1 or more repetitions:--> - <boundaryDeterminator> - <relatedExecutableBlockUID>string</relatedExecutableBlockUID> - </boundaryDeterminator> - </boundaryDeterminators> - <!--Optional:--> - <surrogateModelBuilders> + <distributedSystemConvergers> <!--1 or more repetitions:--> - <surrogateModelBuilder> - <relatedExecutableBlockUID>string</relatedExecutableBlockUID> - </surrogateModelBuilder> - </surrogateModelBuilders> + <distributedSystemConverger uID="string"> + <!--Optional:--> + <label>string</label> + <!--Optional:--> + <settings> + <method>string</method> + <lastIterationsToConsider>3</lastIterationsToConsider> + <maximumIterations>3</maximumIterations> + <convergenceToleranceRelative>1.5E2</convergenceToleranceRelative> + <convergenceToleranceAbsolute>1.5E2</convergenceToleranceAbsolute> + </settings> + </distributedSystemConverger> + </distributedSystemConvergers> <!--Optional:--> <preCouplingAnalyses> <!--1 or more repetitions:--> diff --git a/kadmos/cmdows/schemas/0.9/cmdows.xsd b/kadmos/cmdows/schemas/0.9/cmdows.xsd index 86a1e455d5f11539d5325fca92e33d1160d58c93..13ce0e229d5fd52bc00dba030c33abf1c9732f1f 100644 --- a/kadmos/cmdows/schemas/0.9/cmdows.xsd +++ b/kadmos/cmdows/schemas/0.9/cmdows.xsd @@ -1005,7 +1005,17 @@ <xs:element name="couplingWeights" minOccurs="0"> <xs:complexType> <xs:sequence> - <xs:element name="couplingWeight" type="simpleArchitectureElementsVariableType" maxOccurs="unbounded"/> + <xs:element name="couplingWeight" maxOccurs="unbounded"> + <xs:complexType> + <xs:sequence> + <xs:element name="relatedInstanceUID" type="xs:string" minOccurs="0"/> + <xs:element name="label" type="xs:string"/> + <xs:element name="instanceID" type="xs:int"/> + <xs:element name="schemaPath" type="xs:string" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="uID" type="xs:string"/> + </xs:complexType> + </xs:element> </xs:sequence> </xs:complexType> </xs:element> @@ -1149,21 +1159,70 @@ <xs:element name="surrogateModels" minOccurs="0"> <xs:complexType> <xs:sequence> - <xs:element name="surrogateModel" type="simpleArchitectureElementsRelatedBlockType" maxOccurs="unbounded"/> - </xs:sequence> - </xs:complexType> - </xs:element> - <xs:element name="boundaryDeterminators" minOccurs="0"> - <xs:complexType> - <xs:sequence> - <xs:element name="boundaryDeterminator" type="simpleArchitectureElementsRelatedBlockType" maxOccurs="unbounded"/> + <xs:element name="surrogateModel" maxOccurs="unbounded"> + <xs:complexType> + <xs:complexContent> + <xs:extension base="simplerArchitectureElementsBlockType"> + <xs:sequence> + <xs:element name="training" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="inputs" maxOccurs="1"> + <xs:complexType> + <xs:sequence> + <xs:element name="input" maxOccurs="unbounded"> + <xs:complexType> + <xs:sequence> + <xs:element name="parameterUID" maxOccurs="1"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="outputs" type="outputsType" maxOccurs="unbounded"/> + <xs:element name="settings"> + <xs:complexType> + <xs:sequence> + <xs:element name="fittingMethod" type="xs:string"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="prediction" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="inputs" maxOccurs="1"> + <xs:complexType> + <xs:sequence> + <xs:element name="input" maxOccurs="unbounded"> + <xs:complexType> + <xs:sequence> + <xs:element name="parameterUID" maxOccurs="1"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="outputs" type="outputsType" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + </xs:element> </xs:sequence> </xs:complexType> </xs:element> - <xs:element name="surrogateModelBuilders" minOccurs="0"> + <xs:element name="distributedSystemConvergers" minOccurs="0"> <xs:complexType> <xs:sequence> - <xs:element name="surrogateModelBuilder" type="simpleArchitectureElementsRelatedBlockType" maxOccurs="unbounded"/> + <xs:element name="distributedSystemConverger" type="distributedSystemConvergerType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> @@ -1337,6 +1396,13 @@ </xs:sequence> <xs:attribute name="uID" type="xs:string"/> </xs:complexType> + <xs:complexType name="distributedSystemConvergerType"> + <xs:sequence> + <xs:element name="label" type="xs:string" minOccurs="0"/> + <xs:element name="settings" type="solverSettingsType" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="uID" type="xs:string"/> + </xs:complexType> <xs:complexType name="convergerType"> <xs:sequence> <xs:element name="label" type="xs:string" minOccurs="0"/> diff --git a/kadmos/graph/graph_data.py b/kadmos/graph/graph_data.py index 4e2bca7798a8cecbe9a5fc36518e39662f67575d..3411fd19999cb804395ac1e49e566ed05387ef67 100644 --- a/kadmos/graph/graph_data.py +++ b/kadmos/graph/graph_data.py @@ -5179,6 +5179,31 @@ class MdaoDataGraph(DataGraph, MdaoMixin): graph_des_vars = [{'designVariableUID': self.PROBLEM_ROLES_VAR_SUFFIXES[0] + var} for var in self.nodes[graph_node].get('design_variables')] cmdows_executable_block_elem.add('designVariables', graph_des_vars) + elif architecture_roles_fun == 'surrogate model': + training_settings = self.nodes[graph_node].get('training') + if training_settings is not None: + cmdows_training = cmdows_executable_block_elem.add('training') + cmdows_training_inps = cmdows_training.add('inputs') + for tr_inp in self.nodes[graph_node]['training']['inputs']: + el_inp = cmdows_training_inps.add('input') + el_inp.add('parameterUID', tr_inp) + cmdows_training_outs = cmdows_training.add('outputs') + for tr_out in self.nodes[graph_node]['training']['outputs']: + el_out = cmdows_training_outs.add('output') + el_out.add('parameterUID', tr_out) + cmdows_training.add('settings', self.nodes[graph_node]['training']['settings'], + camel_case_conversion=True) + prediction_settings = self.nodes[graph_node].get('prediction') + if prediction_settings is not None: + cmdows_prediction = cmdows_executable_block_elem.add('prediction') + cmdows_prediction_inps = cmdows_prediction.add('inputs') + for pr_inp in self.nodes[graph_node]['prediction']['inputs']: + el_inp = cmdows_prediction_inps.add('input') + el_inp.add('parameterUID', pr_inp) + cmdows_prediction_outs = cmdows_prediction.add('outputs') + for pr_out in self.nodes[graph_node]['prediction']['outputs']: + el_out = cmdows_prediction_outs.add('output') + el_out.add('parameterUID', pr_out) else: cmdows_executable_block_elem.add('settings', self.nodes[graph_node].get('settings'), camel_case_conversion=True) @@ -5232,10 +5257,10 @@ class MdaoDataGraph(DataGraph, MdaoMixin): cmdows_des_vars = cmdows_single_architecture_exe_block.findall('designVariables/designVariable') graph_des_vars = [var.findtext('designVariableUID')[10:] for var in list(cmdows_des_vars)] self.nodes[cmdows_uid]['design_variables'] = graph_des_vars - if role == 'converger' or role == 'optimizer': + if role == 'converger' or role == 'optimizer' or role == 'distributed system converger': if 'settings' not in self.nodes[cmdows_uid] or self.nodes[cmdows_uid]['settings'] is None: self.nodes[cmdows_uid]['settings'] = {} - if role == 'converger': + if role == 'converger' or role == 'distributed system converger': setting_options = OrderedDict([('linear_solver', 'linearSolver'), ('nonlinear_solver', 'nonlinearSolver')]) solver_settings_options = \ @@ -5270,6 +5295,11 @@ class MdaoDataGraph(DataGraph, MdaoMixin): OrderedDict((((key, cmdows_single_architecture_exe_block.findtext('settings/' + setting_options[setting_option] + '/' + solver_settings_options[key])) for key in solver_settings_options))) + elif role == 'distributed system converger': + self.nodes[cmdows_uid]['settings'] = \ + OrderedDict((((key, cmdows_single_architecture_exe_block + .findtext('settings/' + solver_settings_options[key])) + for key in solver_settings_options))) if role == 'optimizer': cmdows_des_vars = \ cmdows_single_architecture_exe_block.findall('objectiveVariables/objectiveVariable') @@ -5306,6 +5336,21 @@ class MdaoDataGraph(DataGraph, MdaoMixin): cmdows_single_architecture_exe_block.findtext('settings/seed') self.nodes[cmdows_uid]['settings']['levels'] = \ cmdows_single_architecture_exe_block.findtext('settings/levels') + elif role == 'surrogate model': + training_inputs = cmdows_single_architecture_exe_block.findall( + 'training/inputs/input/parameterUID') + training_outputs = cmdows_single_architecture_exe_block.findall( + 'training/outputs/output/parameterUID') + training_fitting_method = cmdows_single_architecture_exe_block.findtext( + 'training/settings/fittingMethod') + self.nodes[cmdows_uid]['training'] = OrderedDict((('inputs', [tr_inp.text for tr_inp in training_inputs]), + ('outputs', [tr_out.text for tr_out in training_outputs]), + ('settings', OrderedDict((('fitting_method', training_fitting_method),))))) + prediction_inputs = cmdows_single_architecture_exe_block.findall('prediction/inputs/input/parameterUID') + prediction_outputs = cmdows_single_architecture_exe_block.findall('prediction/outputs/output/parameterUID') + self.nodes[cmdows_uid]['prediction'] = OrderedDict( + (('inputs', [pr_inp.text for pr_inp in prediction_inputs]), + ('outputs', [pr_out.text for pr_out in prediction_outputs]))) else: for role in self.ARCHITECTURE_ROLES_FUNS: cmdows_role_name = make_camel_case(role) @@ -5890,7 +5935,12 @@ class MdaoDataGraph(DataGraph, MdaoMixin): category='function', architecture_role=self.ARCHITECTURE_ROLES_FUNS[10], # distributed system converger label=label, - instance=1) + instance=1, + settings=OrderedDict((('method', 'BLISS-2000'), + ('last_iterations_to_consider', 1), + ('maximum_iterations', 20), + ('convergence_tolerance_relative', 1e-4), + ('convergence_tolerance_absolute', 1e-4)))) assert isinstance(inputs, list) self.assert_node_exists(inputs) @@ -6163,6 +6213,9 @@ class MdaoDataGraph(DataGraph, MdaoMixin): self.nodes[doe_block]['design_variables'][des_var]['samples'] = self.nodes[des_var]['samples'] else: self.nodes[doe_block]['design_variables'][des_var]['samples'] = None + if 'problem_role' not in self.nodes[des_var] or \ + self.nodes[des_var]['problem_role'] != self.PROBLEM_ROLES_VARS[0]: + self.nodes[des_var]['problem_role'] = self.PROBLEM_ROLES_VARS[0] self.nodes[doe_block]['quantities_of_interest'] = qoi_nodes # For the custom design table, add the table with values to the settings @@ -6240,7 +6293,10 @@ class MdaoDataGraph(DataGraph, MdaoMixin): category='function', architecture_role=self.ARCHITECTURE_ROLES_FUNS[9], # Surrogate model label=label, - instance=1) + instance=1, + training=OrderedDict((('inputs', train_inputs), ('outputs', train_outputs), + ('settings', OrderedDict((('fitting_method', 'Kriging'),))))), + prediction=OrderedDict((('inputs', sm_inputs), ('outputs', [])))) # Connect the surrogate model # Connect train data as input @@ -6257,6 +6313,7 @@ class MdaoDataGraph(DataGraph, MdaoMixin): node_apprs = [] for sm_out_or in sm_out_originals: node_appr = self.copy_node_as(sm_out_or, self.ARCHITECTURE_ROLES_VARS[10]) + self.nodes[sm]['prediction']['outputs'].append(node_appr) self.add_edge(sm, node_appr) node_apprs.append(node_appr) diff --git a/kadmos/graph/graph_kadmos.py b/kadmos/graph/graph_kadmos.py index 0624a5413e5736ca261acac8058d988cf968db30..b85d1dc573ba3486e8cb6a9479f87a4ad7085df2 100644 --- a/kadmos/graph/graph_kadmos.py +++ b/kadmos/graph/graph_kadmos.py @@ -128,7 +128,7 @@ class KadmosGraph(nx.DiGraph, EquationMixin, VistomsMixin): 'PostAnalysis', # 8 'Metamodel', # 9 'Converger'] # 10 - CMDOWS_ARCHITECTURE_ROLE_SPLITTER = get_list_entries(ARCHITECTURE_ROLES_FUNS, 0, 1, 2, 3) + CMDOWS_ARCHITECTURE_ROLE_SPLITTER = get_list_entries(ARCHITECTURE_ROLES_FUNS, 0, 1, 2, 3, 9, 10) SYS_PREFIX = 'Sys-' SUBSYS_PREFIX = 'Sub-' SUBSYS_SUFFIX = '-'