def main(): create_file() db = dapt.Delimited_file('test.csv') ap = dapt.Param(db) while True: parameters = ap.next_parameters() #Get the next parameter if parameters == None: print("No more parameters to run!") break print("Request parameters: ") print(parameters) ap.successful(parameters["id"]) try: ap.update_status(parameters['id'], 'Adding and inserting') c = int(parameters['a']) + int(parameters['b']) db.update_cell(db.get_row_index('id', parameters['id']), 'c', c) # Update sheets to mark the test is finished ap.successful(parameters["id"] ) #Test completed successfully so we mark it as such # End tests except ValueError: # Test failed print(ValueError) print("Test failed") ap.failed(parameters["id"], str(ValueError))
def test_Param_next_parameters(): create_simple_test_file() db = dapt.Delimited_file('test.csv', ',') param = dapt.Param(db) actual = param.next_parameters() expected = OrderedDict({'id':'t2', 'status':'in progress', 'a':'10', 'b':'10', 'c':''}) assert actual == expected, "Cannot get the next paramater set."
def test_Param_failed(): create_simple_test_file() db = dapt.Delimited_file('test.csv', ',') param = dapt.Param(db) actual = param.next_parameters() actual = param.failed(actual['id'], 'This is an error') expected = OrderedDict({'id':'t2', 'status':'failed', 'a':'10', 'b':'10', 'c':''}) assert actual == expected, "Cannot update the status of the paramater set."
def test_Param_successful(): create_simple_test_file() db = dapt.Delimited_file('test.csv', ',') param = dapt.Param(db) actual = param.next_parameters() actual = param.successful(actual['id']) expected = OrderedDict({'id':'t2', 'status':'successful', 'a':'10', 'b':'10', 'c':''}) assert actual == expected, "Cannot update the status of the paramater set."
def main(db_path, config_path): # Set up DAPT objects: database (Delimited_file) and parameter manager (Param) config = dapt.Config(path=config_path) db = dapt.db.Delimited_file(db_path, delimiter=',') ap = dapt.Param(db, config=config) ap.number_of_runs = 1 print("Starting main script") # Get the first parameter. Returns None if there are none parameters = ap.next_parameters() while parameters is not None: print("Request parameters: %s" % parameters) # Use a try/except to report errors if they occur during the pipeline try: # Reset PhysiCell from the previous run using PhysiCell's data-cleanup print("Cleaning up folder") ap.update_status(parameters['id'], 'clean') os.system("make data-cleanup") # Update the default settings with the given parameters print("Creating parameters xml") ap.update_status(parameters['id'], 'xml') dapt.tools.create_XML(parameters, default_settings="config/PhysiCell_settings_default.xml", save_settings="config/PhysiCell_settings.xml") # Run PhysiCell (execution method depends on OS) print("Running test") ap.update_status(parameters['id'], 'sim') if platform.system() == 'Windows': os.system("biorobots.exe") else: os.system("./biorobots") # Moving final image to output folder ap.update_status(parameters['id'], 'output') shutil.copyfile('output/final.svg', '../outputs/%s_final.svg' % parameters["id"]) # Update sheets to mark the test is finished ap.successful(parameters["id"]) except ValueError: print("Test failed:") print(ValueError) ap.failed(parameters["id"], ValueError) parameters = ap.next_parameters() #Get the next parameter
def test_Param_successful_fields(): create_complex_test_file() db = dapt.Delimited_file('test.csv', ',') param = dapt.Param(db) actual = param.next_parameters() expected = actual actual = param.successful(actual['id']) expected = OrderedDict({'id':'t2', 'start-time':'', 'end-time':'', 'status':'successful', 'comment':'','performed-by':'', 'a':'10', 'b':'10', 'c':''}) # Check to see if the time in the database are within 15 seconds of ours. if (datetime.datetime.strptime(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S') - datetime.datetime.strptime(actual['start-time'], '%Y-%m-%d %H:%M:%S')).seconds < 15: expected['start-time'] = actual['start-time'] if (datetime.datetime.strptime(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S') - datetime.datetime.strptime(actual['end-time'], '%Y-%m-%d %H:%M:%S')).seconds < 15: expected['end-time'] = actual['end-time'] assert actual == expected, "Cannot update the status of the paramater set."
""" Example of how to use DAPT with Google Sheets. Before you can run this example, you need to create a new Google Sheet and add you Service Account Email as a collaborator with edit ability. If you are still confused you can follow the documentation guide. """ import dapt import os, sys, csv # You'll need to provide the sheet id sheet_id = '1Nfm5oi0ovsETjk3gWATVbLaxI9XRSEwup64iHJoKdDE' db = dapt.Sheet(spreedsheet_id=sheet_id, sheet_id=0, creds='../credentials.json') ap = dapt.Param(db) def init_sheet(): header = ['id', 'start-time', 'end-time', 'status', 'a', 'b', 'c'] for i in range(len(header)): db.worksheet().update_cell(1, i+1, str(header[i])) data = [{'id':'t1', 'start-time':'2019-09-06 17:23', 'end-time':'2019-09-06 17:36', 'status':'finished', 'a':'2', 'b':'4', 'c':'6'}, {'id':'t2', 'start-time':'', 'end-time':'', 'status':'', 'a':'10', 'b':'10', 'c':''}, {'id':'t3', 'start-time':'', 'end-time':'', 'status':'', 'a':'10', 'b':'-10', 'c':''}] for i in range(3): for j in range(len(header)): db.worksheet().update_cell(i+2, j+1, data[i][header[j]]) #init_sheet() input('If you go to the Google Sheet then you can see the sheet is now initialized.\nPress enter to run DAPT on the Google Sheet.')
""" PhysiCell Example ================= This file shows an example workflow with PhysiCell. """ import os, platform, datetime, time import dapt conf = dapt.Config('config.json') sheet = dapt.Delimited_file('parameters.csv', delimiter=',') ap = dapt.Param(sheet, conf) box = dapt.Box(config=conf) box.connect() print("Starting main script") parameters = ap.next_parameters() #Get the next parameter while parameters is not None: if parameters == None: print("No more parameters to run!") break print("Request parameters: %s" % parameters) try: # Reset from the previous run print("Cleaning up folder")
import os, platform import dapt config = dapt.Config(path='config.json') db = dapt.db.Delimited_file('parameters.csv', delimiter=',') params = dapt.Param(db, config=config) p = params.next_parameters() while p is not None: dapt.tools.create_XML(p, default_settings="PhysiCell_settings_default.xml", save_settings="PhysiCell_settings.xml") params.update_status(p["id"], 'running simulation') if platform.system() == 'Windows': os.system("biorobots.exe") else: os.system("./biorobots") params.successful(p["id"]) p = params.next_parameters()
for key in parameters: if key in off_limits: next node = root.find(key) if node != None: node.text = str(parameters[key]) tree.write(save_settings) # Set up DAPT objects: database (Delimited_file) and parameter manager (Param) db = dapt.db.Delimited_file('parameters.csv', delimiter=',') params = dapt.Param(db) # Get the first parameter. Returns None if there are none p = params.next_parameters() while p is not None: print("Request parameters: %s" % p) params.update_status(p["id"], 'updating PhysiCell settings') # Update the default settings with the given parameters create_XML(p, default_settings="PhysiCell_settings_default.xml", save_settings="PhysiCell_settings.xml") params.update_status(p["id"], 'running simulation')