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

FEAT: Update Twin Runtime SDK to 23R1.SP1 #83

Merged
merged 5 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 9 additions & 7 deletions src/ansys/pytwin/evaluate/twin_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _get_runtime_log_level():
if pytwin_level == PyTwinLogLevel.PYTWIN_LOG_CRITICAL:
return LogLevel.TWIN_LOG_FATAL

def _initialize_evaluation(self, parameters: dict = None, inputs: dict = None):
def _initialize_evaluation(self, parameters: dict = None, inputs: dict = None, runtime_init: bool = True):
"""
Initialize the twin model evaluation with dictionaries:
(1) Initialize parameters and/or inputs values to their start values (default values found in the twin file).
Expand All @@ -139,6 +139,7 @@ def _initialize_evaluation(self, parameters: dict = None, inputs: dict = None):
(4) Save universal time (time since epoch) at which the method is called.
(5) Evaluate twin model at time instance 0. Store its results into an outputs dictionary.
Twin runtime is reset in case of already initialized twin model.
Twin runtime is not initialized in case runtime_init is False.
"""
if self._twin_runtime is None:
self._raise_error("Twin model has not been successfully instantiated.")
Expand Down Expand Up @@ -169,15 +170,16 @@ def _initialize_evaluation(self, parameters: dict = None, inputs: dict = None):
for model_name, data in tbrom_info.items():
self._twin_runtime.twin_set_rom_image_directory(model_name, directory_path)

self._twin_runtime.twin_initialize()
if runtime_init:
self._twin_runtime.twin_initialize()
self._update_outputs()

except Exception as e:
msg = f"Something went wrong during model initialization."
msg += f"\n{str(e)}"
msg += f"\nFor more information, see the model log file: {self.model_log}."
self._raise_error(msg)

self._update_outputs()

def _initialize_inputs_with_start_values(self):
"""
Initialize inputs dictionary {name:value} with starting input values found in the twin model.
Expand Down Expand Up @@ -914,12 +916,12 @@ def load_state(self, model_id: str, evaluation_time: float, epsilon: float = 1e-
ss_filepath = ss_registry.return_saved_state_filepath(ss)

# Initialize model accordingly and load existing state
self._initialize_evaluation(parameters=ss.parameters, inputs=ss.inputs)
self._initialize_evaluation(parameters=ss.parameters, inputs=ss.inputs, runtime_init=False)
lboucin marked this conversation as resolved.
Show resolved Hide resolved
self._twin_runtime.twin_load_state(ss_filepath)
self._evaluation_time = ss.time

BU732106_WORKAROUND = True
if BU732106_WORKAROUND:
BUG732106_WORKAROUND = True
if BUG732106_WORKAROUND:
# Rather we call a step-by-step evaluation with a small time step OR we use the registry outputs
# self.evaluate_step_by_step(step_size=ss.time * 1e-12, inputs=ss.inputs)
self._outputs = ss.outputs
Expand Down
1 change: 1 addition & 0 deletions src/ansys/pytwin/twin_runtime/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '1.5.1'
Binary file modified src/ansys/pytwin/twin_runtime/licensingclient/linx64/ansyscl
Binary file not shown.
Binary file not shown.
Binary file modified src/ansys/pytwin/twin_runtime/linux64/libTwinRuntimeSDK.so
Binary file not shown.
Binary file modified src/ansys/pytwin/twin_runtime/linux64/libngcore.so
Binary file not shown.
8 changes: 5 additions & 3 deletions src/ansys/pytwin/twin_runtime/twin_runtime_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def twin_set_inputs(self, input_array):
if len(input_array) != self.number_inputs:
raise TwinRuntimeError("The input array size must match the the models number of inputs!")

array_np = np.array(input_array)
array_np = np.array(input_array, dtype=float)
array_ctypes = array_np.ctypes.data_as(POINTER(c_double * self.number_inputs))

self._TwinSetInputs.argtypes = [c_void_p, POINTER(c_double * self.number_inputs), c_int]
Expand Down Expand Up @@ -1008,15 +1008,17 @@ def twin_save_state(self, save_to):
self.twin_status = self._TwinSaveState(self._modelPointer, c_char_p(save_to))
self.evaluate_twin_status(self.twin_status, self, 'twin_save_state')

def twin_load_state(self, load_from):
def twin_load_state(self, load_from, do_fmi_init=True):
load_from = load_from.encode()
try:
self.twin_status = self._TwinLoadState(self._modelPointer, c_char_p(load_from))
self.twin_status = self._TwinLoadState(self._modelPointer, c_char_p(load_from), c_bool(do_fmi_init))
self.evaluate_twin_status(self.twin_status, self, 'twin_load_state')
except OSError as err:
msg = 'Fatal error when loading the model state'
raise TwinRuntimeError(msg, self, TwinStatus.TWIN_STATUS_FATAL.value)

# The TwinRuntimeSDK always puts the model at least in INITIALIZED state when loading a state
self.is_model_initialized = True

"""
Status message retrieval
Expand Down
Binary file modified src/ansys/pytwin/twin_runtime/win64/TwinRuntimeSDK.dll
Binary file not shown.
Binary file modified src/ansys/pytwin/twin_runtime/win64/libcrypto-1_1-x64.dll
Binary file not shown.
Binary file modified src/ansys/pytwin/twin_runtime/win64/ngcore.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/evaluate/test_twin_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def test_save_and_load_state_with_dynarom(self):
model2.evaluate_step_by_step(step_size=5)
out1 = model1.outputs
out2 = model2.outputs
assert not compare_dictionary(out1, out2) # TODO - Fix BUG732106
assert compare_dictionary(out1, out2)

def test_save_and_load_state_with_rc_heat_circuit(self):
# Init unit test
Expand Down