Skip to content

Commit 5a7aa2a

Browse files
committed
[ModelicaSystemDoE] cleanup simulate() / rename variables
1 parent 7a55a00 commit 5a7aa2a

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
@@ -1952,44 +1952,53 @@ def get_doe(self) -> Optional[pd.DataFrame]:
19521952
"""
19531953
return self._sim_df
19541954

1955-
def simulate(self, num_workers: int = 3) -> None:
1955+
def simulate(
1956+
self,
1957+
num_workers: int = 3,
1958+
) -> bool:
19561959
"""
19571960
Simulate the DoE using the defined number of workers.
19581961
19591962
Returns True if all simulations were done successfully, else False.
19601963
"""
19611964

1962-
sim_count_total = self._sim_task_query.qsize()
1965+
sim_query_total = self._sim_task_query.qsize()
1966+
if not isinstance(self._sim_df, pd.DataFrame):
1967+
raise ModelicaSystemError("Missing Doe Summary!")
1968+
sim_df_total = self._sim_df.shape[0]
19631969

19641970
def worker(worker_id, task_queue):
19651971
while True:
1966-
sim_data = {}
1972+
mscmd: Optional[ModelicaSystemCmd] = None
19671973
try:
19681974
# Get the next task from the queue
1969-
cmd: ModelicaSystemCmd = task_queue.get(block=False)
1975+
mscmd = task_queue.get(block=False)
19701976
except queue.Empty:
19711977
logger.info(f"[Worker {worker_id}] No more simulations to run.")
19721978
break
19731979

1974-
resultfile = cmd.arg_get(key='r')
1980+
if mscmd is None:
1981+
raise ModelicaSystemError("Missing simulation definition!")
1982+
1983+
resultfile = mscmd.arg_get(key='r')
19751984
resultpath = pathlib.Path(resultfile)
19761985

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

19791988
try:
1980-
sim_data['sim'].run()
1989+
mscmd.run()
19811990
except ModelicaSystemError as ex:
19821991
logger.warning(f"Simulation error for {resultpath.name}: {ex}")
19831992

19841993
# Mark the task as done
19851994
task_queue.task_done()
19861995

1987-
sim_count_done = sim_count_total - self._sim_task_query.qsize()
1996+
sim_query_done = sim_query_total - self._sim_task_query.qsize()
19881997
logger.info(f"[Worker {worker_id}] Task completed: {resultpath.name} "
1989-
f"({sim_count_done}/{sim_count_total} = "
1990-
f"{sim_count_done / sim_count_total * 100:.2f}% of tasks left)")
1998+
f"({sim_query_done}/{sim_query_total} = "
1999+
f"{sim_query_done / sim_query_total * 100:.2f}% of tasks left)")
19912000

1992-
logger.info(f"Start simulations for DoE with {sim_count_total} simulations "
2001+
logger.info(f"Start simulations for DoE with {sim_query_total} simulations "
19932002
f"using {num_workers} workers ...")
19942003

19952004
# Create and start worker threads

0 commit comments

Comments
 (0)