CPU Time with Python bindings

53 views
Skip to first unread message

Dilan Pathirana

unread,
Feb 20, 2021, 10:45:50 AM2/20/21
to COPASI User Forum
Hi,

I'm working on a tool to simulate PEtab problems (thereby also SBML) with COPASI using its Python bindings.

How can I access "CPU Time", to get the time taken for simulation? I've seen this done by writing a report definition to an XML file, then using CopasiSE to simulate. Is it possible to avoid this overhead and instead do everything with python-copasi?

Kind regards,
Dilan

Frank Bergmann

unread,
Feb 22, 2021, 6:34:56 AM2/22/21
to COPASI User Forum
Hello Dilan, 

unfortunately the time variables are not directly exposed. I'll be sure to add that for a future version. For now it is a bit awkward to use, but possible. Here an example. 

     import COPASI
     
     dm = COPASI.CRootContainer.addDatamodel()
     cpu_time = dm.getObject(COPASI.CCommonName('CN=Root,Timer=CPU Time'))
     
     # calculate to update
     cpu_time.calculateValue()
     
     # print to access 
     start = float(cpu_time.printToString())
     
     # do something that takes a long time
     
     
     # calculate to update, then print to access the value
     cpu_time.calculateValue()
     end = float(cpu_time.printToString())
     
     # 
     print('that took {}'.format(end - start))
     

cheers
Frank

Dilan Pathirana

unread,
Feb 23, 2021, 3:50:44 PM2/23/21
to COPASI User Forum
Hi Frank,

Thanks very much, that works well for me.

Kind regards,
Dilan
Reply all
Reply to author
Forward
0 new messages