Skip to content

Commit 29166f6

Browse files
committed
[ModelicaSystemDoE] cleanup simulate() / rename variables
1 parent c7c5a66 commit 29166f6

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
@@ -1586,44 +1586,53 @@ def get_doe(self) -> Optional[pd.DataFrame]:
15861586
"""
15871587
return self._sim_df
15881588

1589-
def simulate(self, num_workers: int = 3) -> None:
1589+
def simulate(
1590+
self,
1591+
num_workers: int = 3,
1592+
) -> bool:
15901593
"""
15911594
Simulate the DoE using the defined number of workers.
15921595
15931596
Returns True if all simulations were done successfully, else False.
15941597
"""
15951598

1596-
sim_count_total = self._sim_task_query.qsize()
1599+
sim_query_total = self._sim_task_query.qsize()
1600+
if not isinstance(self._sim_df, pd.DataFrame):
1601+
raise ModelicaSystemError("Missing Doe Summary!")
1602+
sim_df_total = self._sim_df.shape[0]
15971603

15981604
def worker(worker_id, task_queue):
15991605
while True:
1600-
sim_data = {}
1606+
mscmd: Optional[ModelicaSystemCmd] = None
16011607
try:
16021608
# Get the next task from the queue
1603-
cmd: ModelicaSystemCmd = task_queue.get(block=False)
1609+
mscmd = task_queue.get(block=False)
16041610
except queue.Empty:
16051611
logger.info(f"[Worker {worker_id}] No more simulations to run.")
16061612
break
16071613

1608-
resultfile = cmd.arg_get(key='r')
1614+
if mscmd is None:
1615+
raise ModelicaSystemError("Missing simulation definition!")
1616+
1617+
resultfile = mscmd.arg_get(key='r')
16091618
resultpath = pathlib.Path(resultfile)
16101619

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

16131622
try:
1614-
sim_data['sim'].run()
1623+
mscmd.run()
16151624
except ModelicaSystemError as ex:
16161625
logger.warning(f"Simulation error for {resultpath.name}: {ex}")
16171626

16181627
# Mark the task as done
16191628
task_queue.task_done()
16201629

1621-
sim_count_done = sim_count_total - self._sim_task_query.qsize()
1630+
sim_query_done = sim_query_total - self._sim_task_query.qsize()
16221631
logger.info(f"[Worker {worker_id}] Task completed: {resultpath.name} "
1623-
f"({sim_count_done}/{sim_count_total} = "
1624-
f"{sim_count_done / sim_count_total * 100:.2f}% of tasks left)")
1632+
f"({sim_query_done}/{sim_query_total} = "
1633+
f"{sim_query_done / sim_query_total * 100:.2f}% of tasks left)")
16251634

1626-
logger.info(f"Start simulations for DoE with {sim_count_total} simulations "
1635+
logger.info(f"Start simulations for DoE with {sim_query_total} simulations "
16271636
f"using {num_workers} workers ...")
16281637

16291638
# Create and start worker threads

0 commit comments

Comments
 (0)