"""
"Task: Kinetic Optimization" Module
===================================================================
A pre-installed example script which organizes kinetic optimization
"""
import time
from panpython.sdk.kinetic_opt.kinetic_optimize import KdbBuilder
[docs]class KOpt:
"""
Parameters
----------
batch_file: str
full path of batch file template
opt_file: str
full path of optimization configuration file
Examples
--------
>>> from panpython.system import System
>>> from panpython.task.kopt import KOpt
>>> pandat = "YOUR_PATH_TO_PANDAT_EXE/Pandat.exe"
>>> dump_path = "./output"
>>> batch_file = "./resource/AA6xxx_6005_opt.pbfx"
>>> opt_file = "./resource/PanAl.opt"
>>>
>>> m_system = System(pandat=pandat, dump_path=dump_path)
>>> m_system.add_task(task_instance=KOpt(batch_file=batch_file, opt_file=opt_file))
>>> m_system.run()
"""
def __init__(self, opt_file:str, batch_file:str=None):
"""
Initialize a instance of kinetic optimization
Parameters
----------
opt_file: str
full path of optimization configuration file
batch_file: str
full path of batch file template
Returns
-------
"""
self.boost = True
self.batch_file = batch_file
self.opt_file = opt_file
self.task_type = 'Kinetic optimization'
self.m_kdb: object = None
return
[docs] def run(self, system):
"""
Run a defined kinetic optimization calculation
Parameters
----------
system: panpy_dev.system.System
a reference to a system instance handling all existing task
Returns
-------
"""
pandat = system.system_args.pandat
dump_path = system.system_args.dump_path
self.m_kdb = KdbBuilder(opt_file=self.opt_file,dump_path= dump_path,pandat_exe= pandat,batch_file=self.batch_file)
# train and print metric
start_time = time.time()
if self.boost:
self.m_kdb.fit_wrapper()
else:
...
# self.m_kdb.fit()
elapsed_training_time = time.time() - start_time
print('\n===== system report =====')
print('> elapsed training time =', elapsed_training_time, '[s]')
print('> elapsed Pandat time =', self.m_kdb.elapsed_pandat_time, '[s]')
print('> elapsed solver time =', self.m_kdb.elapsed_solver_time - self.m_kdb.elapsed_pandat_time, '[s]')
print('Kinetic optimization completes')
return
# def show_simulation(self):
# self.m_kdb.predict()
# print('Kinetic optimization simulated based on new kdb')
# return