def AddDyn_WorkflowAttributes(something): something.workflow = workflowBuilder.createWorkflow('TestWorkflow') something.sumStep1 = workflowBuilder.createToolStep( 'add', something.workflow, 'Add0') something.sumStep2 = workflowBuilder.createToolStep( 'add', something.workflow) something.multiplyStep1 = workflowBuilder.createToolStep( 'multiply', something.workflow, 'finalMulti') something.sumListStep1 = workflowBuilder.createToolStep( 'addList', something.workflow) # set constants something.sumListStep1.inputPorts['addends'].fixed_value = [ 1, 2, 3, 4, 5, 6 ] something.sumStep1.inputPorts['addend1'].fixed_value = 2 something.sumStep2.inputPorts['addend1'].fixed_value = 100 something.multiplyStep1.inputPorts['factor2'].fixed_value = 23 # connect input/output workflowBuilder.connectPorts(something.sumListStep1.outputPorts['sum'], something.sumStep1.inputPorts['addend2']) workflowBuilder.connectPorts(something.sumStep1.outputPorts['sum'], something.sumStep2.inputPorts['addend2']) workflowBuilder.connectPorts(something.sumStep2.outputPorts['sum'], something.multiplyStep1.inputPorts['factor1']) something.exp = float(2829)
def test_workflow_in_workflow(self): """Test workflow: add(1, 2) => (( add(x, 3) => multi(x, 4) => )) add(x, 5) 3 => add(3,3)=6 => multi(6,4)=24 => add(24,5)=29""" # create nested workflow with one input and one output parameter aWorkflowABC = workflowBuilder.createWorkflow( 'ArtificialDemoTestCase-aWorkflowABC') sumStepA = workflowBuilder.createToolStep(toolId='caeml.tools.add.add', parent=aWorkflowABC) sumStepA.inputPorts['addend1'].fixed_value = 3 sumStepA.inputPorts['addend2'].exposed_as = 'IN' multiStepB = workflowBuilder.createToolStep(toolId='multiply', parent=aWorkflowABC) multiStepB.inputPorts['factor2'].fixed_value = 4 workflowBuilder.connectPorts(sumStepA.outputPorts['sum'], multiStepB.inputPorts['factor1']) workflowBuilder.connectPorts(sumStepA.outputPorts['sum'], multiStepB.inputPorts['factor1']) multiStepB.outputPorts['product'].exposed_as = 'OUT' # add basic workflow steps, assign values and connect parameters aWorkflow = workflowBuilder.createWorkflow( 'ArtificialDemoTestCase-aWorkflow') sumStep1 = workflowBuilder.createToolStep(toolId='add', parent=aWorkflow) sumStep3 = workflowBuilder.createToolStep(toolId='add', parent=aWorkflow) aWorkflowABCStep = workflowBuilder.createStep(process=aWorkflowABC, parent=aWorkflow, name='aWorkflowABCStep') # assign input values sumStep1.inputPorts['addend1'].fixed_value = 1 sumStep1.inputPorts['addend2'].fixed_value = 2 sumStep3.inputPorts['addend1'].fixed_value = 5 # plug workflowABC into aWorkflow inPorts = aWorkflowABCStep.inputPorts workflowBuilder.connectPorts(sumStep1.outputPorts['sum'], inPorts['IN']) exPorts = aWorkflowABCStep.outputPorts workflowBuilder.connectPorts(exPorts['OUT'], sumStep3.inputPorts['addend2']) res = workflowRunner.executeAsync(aWorkflow) result = res.findPortState(sumStep3.outputPorts['sum']).getValue() exp = float(29) self.assertEqual( result, exp, "Error! Wrong Result expected {:.2f} got {:.2f}".format( exp, result))
def test2_WorkflowPythonTool(self): # new workflow aWorkflow = caeml.common.workflow.Workflow() # add new workflow steps # aCmdAddTool = caeml.tools.generated_tools.add() aStatsTool = caeml.tools.statsFilePython.statsFileTool() aStats = workflowBuilder.createStep(name='step1', process=aStatsTool, parent=aWorkflow) aSum = workflowBuilder.createToolStep('add', aWorkflow) # set values aStats.inputPorts['data'].fixed_value = [1, 2, 3, 4, 5, 6, 7] # connect workflowBuilder.connectPorts(aStats.outputPorts['max'], aSum.inputPorts['addend1']) workflowBuilder.connectPorts(aStats.outputPorts['min'], aSum.inputPorts['addend2']) # print(yaml.dump(aWorkflow)) state = workflowRunner.executeAsync(aWorkflow) x = state.findPortState(aSum.outputPorts['sum']).getEvaluation() self.assertEqual(x, 8)
def test1_FileBasedWorkflowTest_test1(self): # new workflow aWorkflow = workflowBuilder.createWorkflow( 'test1_FileBasedWorkflowTest_test1') # add new workflow steps # aCmdAddTool = caeml.tools.generated_tools.add() aStats = workflowBuilder.createToolStep('stats', aWorkflow) aSum = workflowBuilder.createToolStep('addFiles', aWorkflow) # set values aStats.inputPorts['data'].fixed_value = [1, 2, 3, 4, 5, 6, 7] # connect workflowBuilder.connectPorts(aStats.outputPorts['max'], aSum.inputPorts['addend1']) workflowBuilder.connectPorts(aStats.outputPorts['min'], aSum.inputPorts['addend2']) # print(yaml.dump(aWorkflow)) state = workflowRunner.executeAsync(aWorkflow) x = state.findPortState(aSum.outputPorts['sum']).getEvaluation() self.assertEqual(x, 8)