Skip to content

Commit 0ef7853

Browse files
committed
[ModelicaSystemDoE] cleanup simulate() / rename variables
1 parent 9d94c49 commit 0ef7853

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,44 +1681,53 @@ def get_doe(self) -> Optional[pd.DataFrame]:
16811681
"""
16821682
return self._sim_df
16831683

1684-
def simulate(self, num_workers: int = 3) -> None:
1684+
def simulate(
1685+
self,
1686+
num_workers: int = 3,
1687+
) -> bool:
16851688
"""
16861689
Simulate the DoE using the defined number of workers.
16871690
16881691
Returns True if all simulations were done successfully, else False.
16891692
"""
16901693

1691-
sim_count_total = self._sim_task_query.qsize()
1694+
sim_query_total = self._sim_task_query.qsize()
1695+
if not isinstance(self._sim_df, pd.DataFrame):
1696+
raise ModelicaSystemError("Missing Doe Summary!")
1697+
sim_df_total = self._sim_df.shape[0]
16921698

16931699
def worker(worker_id, task_queue):
16941700
while True:
1695-
sim_data = {}
1701+
mscmd: Optional[ModelicaSystemCmd] = None
16961702
try:
16971703
# Get the next task from the queue
1698-
cmd: ModelicaSystemCmd = task_queue.get(block=False)
1704+
mscmd = task_queue.get(block=False)
16991705
except queue.Empty:
17001706
logger.info(f"[Worker {worker_id}] No more simulations to run.")
17011707
break
17021708

1703-
resultfile = cmd.arg_get(key='r')
1709+
if mscmd is None:
1710+
raise ModelicaSystemError("Missing simulation definition!")
1711+
1712+
resultfile = mscmd.arg_get(key='r')
17041713
resultpath = pathlib.Path(resultfile)
17051714

17061715
logger.info(f"[Worker {worker_id}] Performing task: {resultpath.name}")
17071716

17081717
try:
1709-
sim_data['sim'].run()
1718+
mscmd.run()
17101719
except ModelicaSystemError as ex:
17111720
logger.warning(f"Simulation error for {resultpath.name}: {ex}")
17121721

17131722
# Mark the task as done
17141723
task_queue.task_done()
17151724

1716-
sim_count_done = sim_count_total - self._sim_task_query.qsize()
1725+
sim_query_done = sim_query_total - self._sim_task_query.qsize()
17171726
logger.info(f"[Worker {worker_id}] Task completed: {resultpath.name} "
1718-
f"({sim_count_done}/{sim_count_total} = "
1719-
f"{sim_count_done / sim_count_total * 100:.2f}% of tasks left)")
1727+
f"({sim_query_done}/{sim_query_total} = "
1728+
f"{sim_query_done / sim_query_total * 100:.2f}% of tasks left)")
17201729

1721-
logger.info(f"Start simulations for DoE with {sim_count_total} simulations "
1730+
logger.info(f"Start simulations for DoE with {sim_query_total} simulations "
17221731
f"using {num_workers} workers ...")
17231732

17241733
# Create and start worker threads

0 commit comments

Comments
 (0)