Skip to content

Commit

Permalink
Merge branch 'master' into scheduler-fix-2
Browse files Browse the repository at this point in the history
  • Loading branch information
eudoxos committed May 28, 2024
2 parents e652061 + 81737e2 commit 395b233
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mupifDB/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def anyPort():
#mupifExamplesDir=mp.__path__[0]+'/examples/'

sys.path.append(mupifDB.__path__[0]+'/..')
import workflows.workflowdemo01 as wfdemo01
import workflows.mini01 as wfmini01

@pytest.fixture
def nameserver(xprocess):
Expand Down Expand Up @@ -123,23 +123,27 @@ def test_suite_cleanup():

class TestFoo:
def test_workflowdemo01(self,scheduler):
wf=wfdemo01.workflowdemo()
wf=wfmini01.MiniWorkflow1()
md=lambda k: wf.getMetadata(k)
wid=md('ID')
id=mupifDB.workflowmanager.insertWorkflowDefinition(wid=wid,description=md('Description'),source=wfdemo01.__file__,useCase='useCase1',workflowInputs=md('Inputs'),workflowOutputs=md('Outputs'),modulename=wf.__module__.split('.')[-1],classname=wf.__class__.__name__,models_md=md('Models'))
id=mupifDB.workflowmanager.insertWorkflowDefinition(wid=wid,description=md('Description'),source=wfmini01.__file__,useCase='useCase1',workflowInputs=md('Inputs'),workflowOutputs=md('Outputs'),modulename=wf.__module__.split('.')[-1],classname=wf.__class__.__name__,models_md=md('Models'))
print(f'Workflow inserted, {id=}')
wrec=restApiControl.getWorkflowRecord(wid)
assert wrec['wid']==wid
# print_json(data=wrec)
weid=restApiControl.createExecution(wid,version='1',ip='localhost')
#for inp in [
# mp.ConstantProperty(value=16., propID=DataID.PID_Concentration,valueType=ValueType.Scalar,unit=mp.U['m'])
#]:
# restApiControl.setExecutionInputObject(weid,
print(f'Execution created, {weid=}')
restApiControl.scheduleExecution(weid)
print(f'Execution scheduled, {weid=}')
for i in range(10):
data=restApiControl.getExecutionRecord(weid)
print(f'Execution status: {data["Status"]}')
time.sleep(1)
assert data['Status'] in ('Failed',)
assert data['Status']=='Finished'


# time.sleep(10)
Expand Down
58 changes: 58 additions & 0 deletions workflows/mini01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import mupif
import mupif as mp
import logging
log = logging.getLogger()

class MiniWorkflow1 (mupif.workflow.Workflow):
def __init__(self, metadata={}):
"""
Initializes the workflow.
"""
MD = {
'Name': 'Minimal Workflow',
'ID': '1',
'Description': 'Demo thermal problem using finite elements on rectangular domain',
'Model_refs_ID': [],
'Inputs': [
],
'Outputs': [
{'Name':'Length', 'Type': 'mupif.Property', 'Required':True, 'Type_ID':'mupif.DataID.PID_Length','Units':'m'}
],
'Models': [],
}
super().__init__(metadata=MD)
self.updateMetadata(metadata)


def initialize(self, workdir='', metadata=None, validateMetaData=True, **kwargs):
super().initialize(workdir=workdir, metadata=metadata, validateMetaData=validateMetaData, **kwargs)

def set(self, obj, objectID=''):
raise mp.APIError('This workflow has no inputs')

def get(self, objectTypeID, time=None, objectID=''):
md = {
'Execution': {
'ID': self.getMetadata('Execution.ID'),
'Use_case_ID': self.getMetadata('Execution.Use_case_ID'),
'Task_ID': self.getMetadata('Execution.Task_ID')
}
}
if objectTypeID == mp.DataID.PID_Length:
return mp.ConstantProperty(value=42, propID=mp.DataID.PID_Length, valueType=mp.ValueType.Scalar, unit=mp.U.m, time=time, metadata=md)
else:
raise mp.APIError('Unknown property ID')

def solveStep(self, istep, stageID=0, runInBackground=False):
log.info ('MiniWorkflow1.solveStep')
pass

def getCriticalTimeStep(self):
return 1.*mp.U.s

def getApplicationSignature(self):
return "thermal 1.0"

def getAPIVersion(self):
return "1.0"

0 comments on commit 395b233

Please sign in to comment.