Skip to content

Commit

Permalink
Lazy load on objects (#4384)
Browse files Browse the repository at this point in the history
Co-authored-by: maxcapodi78 <Shark78>
  • Loading branch information
maxcapodi78 authored Mar 22, 2024
1 parent 8f3eded commit 8e54f81
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 126 deletions.
2 changes: 1 addition & 1 deletion _unittest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
desktop_version = config["desktopVersion"]
new_thread = config["NewThread"]
settings.use_grpc_api = config["use_grpc"]

settings.objects_lazy_load = False
logger = pyaedt_logger


Expand Down
1 change: 0 additions & 1 deletion _unittest/test_98_Icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from pyaedt.modules.SetupTemplates import SetupKeys

test_subfolder = "T98"

if config["desktopVersion"] > "2022.2":
test_project_name = "Filter_Board_Icepak_231"
src_project_name = "USB_Connector_IPK_231"
Expand Down
32 changes: 19 additions & 13 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
import base64


def load_aedt_thread(project_path):
pp = load_entire_aedt_file(project_path)
settings._project_properties[os.path.normpath(project_path)] = pp
settings._project_time_stamp = os.path.getmtime(project_path)


class Design(AedtObjects):
"""Contains all functions and objects connected to the active project and design.
Expand Down Expand Up @@ -195,21 +201,16 @@ def __init__(
port=0,
aedt_process_id=None,
):
def load_aedt_thread(path):
start = time.time()
settings._project_properties[path] = load_entire_aedt_file(path)
settings._project_time_stamp = os.path.getmtime(project_name)
pyaedt_logger.info("AEDT file load (threaded) time: {}".format(time.time() - start))

t = None
self.__t = None
if (
not is_ironpython
and project_name
and os.path.exists(project_name)
and (os.path.splitext(project_name)[1] == ".aedt" or os.path.splitext(project_name)[1] == ".a3dcomp")
):
t = threading.Thread(target=load_aedt_thread, args=(project_name,))
t.start()
self.__t = threading.Thread(target=load_aedt_thread, args=(project_name,), daemon=True)
self.__t.start()
self._init_variables()
self._design_type = design_type
self.last_run_log = ""
Expand Down Expand Up @@ -262,8 +263,11 @@ def load_aedt_thread(path):
self._logger.odesign = self.odesign
AedtObjects.__init__(self, self._desktop_class, self.oproject, self.odesign, is_inherithed=True)
self.logger.info("Aedt Objects correctly read")
if t:
t.join()
# if t:
# t.join()
if not self.__t and not settings.lazy_load and not is_ironpython and os.path.exists(self.project_file):
self.__t = threading.Thread(target=load_aedt_thread, args=(self.project_file,), daemon=True)
self.__t.start()
self._variable_manager = VariableManager(self)
self._project_datasets = []
self._design_datasets = []
Expand Down Expand Up @@ -342,8 +346,8 @@ def boundaries(self):
bb.append(thermal)
bb.append(self.get_oo_property_value(othermal, thermal, "Type"))

if self.modeler.user_defined_components:
for component in self.modeler.user_defined_components:
if self.modeler.user_defined_components.items():
for component in self.modeler.user_defined_components.keys():
thermal_properties = self.get_oo_properties(self.oeditor, component)
if thermal_properties and "Type" not in thermal_properties and thermal_properties[-1] != "Icepak":
thermal_boundaries = self.design_properties["BoundarySetup"]["Boundaries"]
Expand Down Expand Up @@ -522,6 +526,9 @@ def project_properties(self):
dict
Dictionary of the project properties.
"""
if self.__t:
self.__t.join()
self.__t = None
start = time.time()
if self.project_timestamp_changed or (
os.path.exists(self.project_file)
Expand Down Expand Up @@ -555,7 +562,6 @@ def design_properties(self):
Dictionary of the design properties.
"""

try:
if model_names[self._design_type] in self.project_properties["AnsoftProject"]:
designs = self.project_properties["AnsoftProject"][model_names[self._design_type]]
Expand Down
25 changes: 18 additions & 7 deletions pyaedt/generic/LoadAEDTFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ def load_entire_aedt_file(filename):
dictionary containing the decoded AEDT file
"""
return _load_entire_aedt_file(os.path.normpath(filename))
settings.logger.reset_timer()
settings.logger.info("Parsing {}.".format(filename))
f_d = _load_entire_aedt_file(os.path.normpath(filename))
settings.logger.info_timer("File {} correctly loaded.".format(filename))
return f_d


def load_keyword_in_aedt_file(filename, keyword):
def load_keyword_in_aedt_file(filename, keyword, design_name=None):
"""Load s specific keyword in the AEDT file and return the dictionary
Parameters
Expand All @@ -42,7 +46,7 @@ def load_keyword_in_aedt_file(filename, keyword):
dictionary containing the decoded AEDT file
"""
return _load_keyword_in_aedt_file(filename, keyword)
return _load_keyword_in_aedt_file(filename, keyword, design_name)


# --------------------------------------------------------------------
Expand Down Expand Up @@ -358,7 +362,7 @@ def _decode_subkey(line, d):
d[k] = None


def _walk_through_structure(keyword, save_dict):
def _walk_through_structure(keyword, save_dict, design_name=None):
"""
Parameters
Expand All @@ -375,12 +379,19 @@ def _walk_through_structure(keyword, save_dict):
global _count
begin_key = "$begin '{}'".format(keyword)
end_key = "$end '{}'".format(keyword)
design_key = None
design_found = True
if design_name:
design_key = "Name='{}'".format(design_name)
design_found = False
found = False
saved_value = None
while _count < _len_all_lines:
line = _all_lines[_count]
if design_key and design_key in line:
design_found = True
# begin_key is found
if begin_key == line:
if begin_key == line and design_found:
found = True
saved_value = save_dict.get(keyword) # if the keyword is already present, save it
save_dict[keyword] = {}
Expand Down Expand Up @@ -476,7 +487,7 @@ def _load_entire_aedt_file(filename):
return main_dict


def _load_keyword_in_aedt_file(filename, keyword):
def _load_keyword_in_aedt_file(filename, keyword, design_name=None):
"""Load a specific keyword in the AEDT file and return the dictionary
Parameters
Expand All @@ -495,5 +506,5 @@ def _load_keyword_in_aedt_file(filename, keyword):
_read_aedt_file(filename)
# load the aedt file
main_dict = {}
_walk_through_structure(keyword, main_dict)
_walk_through_structure(keyword, main_dict, design_name)
return main_dict
16 changes: 16 additions & 0 deletions pyaedt/generic/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ def __init__(self):
self._retry_n_times_time_interval = 0.1
self._wait_for_license = False
self.__lazy_load = True
self.__objects_lazy_load = False

@property
def objects_lazy_load(self):
"""Flag for enabling and disabling the lazy load.
The default is ``True``.
Returns
-------
bool
"""
return self.__objects_lazy_load

@objects_lazy_load.setter
def objects_lazy_load(self, value):
self.__objects_lazy_load = value

@property
def lazy_load(self):
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/modeler/cad/Modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ def _list_verification(self, object_list, list_type):
object_list_new.append(int(element))
else:
if element in self._modeler.object_names:
obj_id = self._modeler._object_names_to_ids[element]
obj_id = self._modeler.objects[element].id
for sel in self._modeler.object_list:
if sel.id == obj_id:
for f in sel.faces:
Expand Down
Loading

0 comments on commit 8e54f81

Please sign in to comment.