Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger #112

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2024-07-15 - release 0.16.5
- Catch FMUPool log failure

2024-07-01 - release 0.16.4
- Dont write result file to disk

Expand Down
2 changes: 1 addition & 1 deletion otfmi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.16.4"
__version__ = "0.16.5"

from .otfmi import (
FMUFunction,
Expand Down
3 changes: 0 additions & 3 deletions otfmi/fmu_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ def __init__(
)
self.__logger = kwargs.pop("logger", False)
self.kwargs_simulate = kwargs
# Handle results in memory. Using file can induce ambiguities.
# If need be, AssimilationPy's fmu_pool may contain another solution.
self.kwargs_simulate.setdefault("options", dict())["result_handling"] = "memory"

def run(self):
"""Run simulation and store results in the queue."""
Expand Down
8 changes: 6 additions & 2 deletions otfmi/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ def log(text, record_time=True, path_log=path_log):

if record_time:
text = "[%s] %s" % (current_time(), text)
with open(path_log, "a") as f:
f.write(text + "\n")

try:
with open(path_log, "a") as f:
f.write(text + "\n")
except Exception:
pass


def current_time():
Expand Down
9 changes: 3 additions & 6 deletions otfmi/otfmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ def _exec_sample(self, list_value_input, **kwargs):
the underlying PyFMI model object.

"""

return self.simulate_sample(list_value_input, **kwargs)

def load_fmu(self, path_fmu, kind=None, **kwargs):
Expand Down Expand Up @@ -451,10 +450,9 @@ def simulate_sample(self, list_value_input, **kwargs):

"""

if self.n_cpus is None:
n_cpus = 1
else:
n_cpus = self.n_cpus
n_cpus = 1 if self.n_cpus is None else self.n_cpus
if n_cpus == 1:
return [self.simulate(point, **kwargs) for point in list_value_input]

kwargs.setdefault("initialization_script", self.initialization_script)

Expand All @@ -471,7 +469,6 @@ def simulate_sample(self, list_value_input, **kwargs):
)
list_kwargs.append(kwargs_simulate)

# if n_cpus > 1: # TODO?
pool = fmu_pool.FMUPool(self.model, n_process=n_cpus)
return pool.run(list_kwargs, final=self.__final)

Expand Down