@@ -1595,44 +1595,53 @@ def get_doe(self) -> Optional[pd.DataFrame]:
15951595 """
15961596 return self ._sim_df
15971597
1598- def simulate (self , num_workers : int = 3 ) -> None :
1598+ def simulate (
1599+ self ,
1600+ num_workers : int = 3 ,
1601+ ) -> bool :
15991602 """
16001603 Simulate the DoE using the defined number of workers.
16011604
16021605 Returns True if all simulations were done successfully, else False.
16031606 """
16041607
1605- sim_count_total = self ._sim_task_query .qsize ()
1608+ sim_query_total = self ._sim_task_query .qsize ()
1609+ if not isinstance (self ._sim_df , pd .DataFrame ):
1610+ raise ModelicaSystemError ("Missing Doe Summary!" )
1611+ sim_df_total = self ._sim_df .shape [0 ]
16061612
16071613 def worker (worker_id , task_queue ):
16081614 while True :
1609- sim_data = {}
1615+ mscmd : Optional [ ModelicaSystemCmd ] = None
16101616 try :
16111617 # Get the next task from the queue
1612- cmd : ModelicaSystemCmd = task_queue .get (block = False )
1618+ mscmd = task_queue .get (block = False )
16131619 except queue .Empty :
16141620 logger .info (f"[Worker { worker_id } ] No more simulations to run." )
16151621 break
16161622
1617- resultfile = cmd .arg_get (key = 'r' )
1623+ if mscmd is None :
1624+ raise ModelicaSystemError ("Missing simulation definition!" )
1625+
1626+ resultfile = mscmd .arg_get (key = 'r' )
16181627 resultpath = pathlib .Path (resultfile )
16191628
16201629 logger .info (f"[Worker { worker_id } ] Performing task: { resultpath .name } " )
16211630
16221631 try :
1623- sim_data [ 'sim' ] .run ()
1632+ mscmd .run ()
16241633 except ModelicaSystemError as ex :
16251634 logger .warning (f"Simulation error for { resultpath .name } : { ex } " )
16261635
16271636 # Mark the task as done
16281637 task_queue .task_done ()
16291638
1630- sim_count_done = sim_count_total - self ._sim_task_query .qsize ()
1639+ sim_query_done = sim_query_total - self ._sim_task_query .qsize ()
16311640 logger .info (f"[Worker { worker_id } ] Task completed: { resultpath .name } "
1632- f"({ sim_count_done } /{ sim_count_total } = "
1633- f"{ sim_count_done / sim_count_total * 100 :.2f} % of tasks left)" )
1641+ f"({ sim_query_done } /{ sim_query_total } = "
1642+ f"{ sim_query_done / sim_query_total * 100 :.2f} % of tasks left)" )
16341643
1635- logger .info (f"Start simulations for DoE with { sim_count_total } simulations "
1644+ logger .info (f"Start simulations for DoE with { sim_query_total } simulations "
16361645 f"using { num_workers } workers ..." )
16371646
16381647 # Create and start worker threads
0 commit comments