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

Lazy load of parametrics, setups and optimizations #4366

Merged
merged 16 commits into from
Mar 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions _unittest/test_11_Setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def init(self, aedtapp, local_scratch):
def test_01_create_hfss_setup(self):
setup1 = self.aedtapp.create_setup("My_HFSS_Setup", self.aedtapp.SETUPS.HFSSDrivenDefault)
assert setup1.name == "My_HFSS_Setup"
assert self.aedtapp.setups[0].name == setup1.name
assert "SaveRadFieldsOnly" in setup1.props
assert "SaveRadFieldsOnly" in setup1.available_properties
setup1["SaveRadFieldsonly"] = True
Expand Down Expand Up @@ -67,6 +68,8 @@ def test_01c_create_hfss_setup_auto_open(self):
self.aedtapp.duplicate_design("auto_open")
for setup in self.aedtapp.get_setups():
self.aedtapp.delete_setup(setup)
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved
assert setup not in self.aedtapp.setups
assert not self.aedtapp.setups
self.aedtapp.set_auto_open()
setup1 = self.aedtapp.get_setup("Auto1")
setup1.enable_adaptive_setup_multifrequency([1.9, 2.4], 0.02)
Expand All @@ -79,8 +82,9 @@ def test_02_create_circuit_setup(self):
assert setup1.name == "circuit"
setup1.props["SweepDefinition"]["Data"] = "LINC 0GHz 4GHz 501"
setup1["SaveRadFieldsonly"] = True
setup1["SweepDefinition/Data"] = "LINC 0GHz 4GHz 301"
assert setup1.props["SweepDefinition"]["Data"] == "LINC 0GHz 4GHz 301"
setup1["SweepDefinition/Data"] = "LINC 0GHz 4GHz 302"
assert setup1.props["SweepDefinition"]["Data"] == "LINC 0GHz 4GHz 302"
assert circuit.setups[0].props["SweepDefinition"]["Data"] == "LINC 0GHz 4GHz 302"
assert "SweepDefinition" in setup1.available_properties
setup1.update()
setup1.disable()
Expand Down
64 changes: 55 additions & 9 deletions pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def __init__(
port=0,
aedt_process_id=None,
):
self.setups = []
Design.__init__(
self,
application,
Expand All @@ -128,11 +127,9 @@ def __init__(
self.active_setup = setup_name
self._materials = None
self._available_variations = self.AvailableVariations(self)
if self.design_type != "Maxwell Circuit":
self.setups = [self.get_setup(setup_name) for setup_name in self.setup_names]

self.parametrics = ParametricSetups(self)
self.optimizations = OptimizationSetups(self)
self._setups = []
self._parametrics = []
self._optimizations = []
self._native_components = []
self.SOLUTIONS = SOLUTIONS()
self.SETUPS = SETUPS()
Expand All @@ -143,6 +140,9 @@ def __init__(

if not settings.lazy_load:
self._materials = self.materials
self._setups = self.setups
self._parametrics = self.parametrics
self._optimizations = self.optimizations

@property
def native_components(self):
Expand Down Expand Up @@ -192,6 +192,49 @@ def materials(self):

return self._materials

@property
def setups(self):
"""Setups in the project.

Returns
-------
:class:`pyaedt.modules.SolveSetup.Setup`
Setups in the project.

"""
if not self._setups:
if self.design_type != "Maxwell Circuit":
self._setups = [self.get_setup(setup_name) for setup_name in self.setup_names]
return self._setups

@property
def parametrics(self):
"""Setups in the project.

Returns
-------
:class:`pyaedt.modules.DesignXPloration.ParametricSetups`
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved
Parametric setups in the project.

"""
if not self._parametrics:
self._parametrics = ParametricSetups(self)
return self._parametrics

@property
def optimizations(self):
"""Optimizations in the project.

Returns
-------
:class:`pyaedt.modules.DesignXPloration.OptimizationSetups`
Parametric setups in the project.

"""
if not self._optimizations:
self._optimizations = OptimizationSetups(self)
return self._optimizations

@property
def Position(self):
"""Position of the object.
Expand Down Expand Up @@ -1265,14 +1308,17 @@ def _create_setup(self, setupname="MySetupAuto", setuptype=None, props=None):
setup.props = SetupProps(setup, new_dict)
setup.auto_update = True

tmp_setups = self.setups
setup.create()
if props:
for el in props:
setup.props[el] = props[el]
setup.update()

self.active_setup = name
self.setups.append(setup)

self._setups = tmp_setups + [setup]

return setup

@pyaedt_function_handler()
Expand Down Expand Up @@ -1307,9 +1353,9 @@ def delete_setup(self, setupname):
"""
if setupname in self.existing_analysis_setups:
self.oanalysis.DeleteSetups([setupname])
for s in self.setups:
for s in self._setups:
if s.name == setupname:
self.setups.remove(s)
self._setups.remove(s)
return True
return False

Expand Down
5 changes: 3 additions & 2 deletions pyaedt/application/Analysis3DLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ def create_setup(self, setupname="MySetupAuto", setuptype=None, **kwargs):
setuptype = SetupKeys.SetupNames.index(setuptype)
name = self.generate_unique_setup_name(setupname)
setup = Setup3DLayout(self, setuptype, name)
tmp_setups = self.setups
setup.create()
setup.auto_update = False

Expand All @@ -478,7 +479,7 @@ def create_setup(self, setupname="MySetupAuto", setuptype=None, **kwargs):
setup[arg_name] = arg_value
setup.auto_update = True
setup.update()
self.setups.append(setup)
self._setups = tmp_setups + [setup]
return setup

@pyaedt_function_handler()
Expand All @@ -501,7 +502,7 @@ def get_setup(self, setupname, setuptype=None):
"""
if setuptype is None:
setuptype = self.design_solutions.default_setup
for setup in self.setups:
for setup in self._setups:
if setupname == setup.name:
return setup
setup = Setup3DLayout(self, setuptype, setupname, isnewsetup=False)
Expand Down
3 changes: 2 additions & 1 deletion pyaedt/application/AnalysisNexxim.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ def create_setup(self, setupname="MySetupAuto", setuptype=None, **kwargs):
setuptype = SetupKeys.SetupNames.index(setuptype)
name = self.generate_unique_setup_name(setupname)
setup = SetupCircuit(self, setuptype, name)
tmp_setups = self.setups
setup.create()
setup.auto_update = False

Expand All @@ -622,5 +623,5 @@ def create_setup(self, setupname="MySetupAuto", setuptype=None, **kwargs):
setup[arg_name] = arg_value
setup.auto_update = True
setup.update()
self.setups.append(setup)
self._setups = tmp_setups + [setup]
return setup
3 changes: 2 additions & 1 deletion pyaedt/application/AnalysisTwinBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def create_setup(self, setupname="MySetupAuto", setuptype=None, **kwargs):
setuptype = SetupKeys.SetupNames.index(setuptype)
name = self.generate_unique_setup_name(setupname)
setup = SetupCircuit(self, setuptype, name)
tmp_setups = self.setups
setup.create()
setup.auto_update = False

Expand All @@ -161,5 +162,5 @@ def create_setup(self, setupname="MySetupAuto", setuptype=None, **kwargs):
setup[arg_name] = arg_value
setup.auto_update = True
setup.update()
self.setups.append(setup)
self._setups = tmp_setups + [setup]
return setup
4 changes: 2 additions & 2 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ def _init_variables(self):
self._post = None
self._materials = None
self._variable_manager = None
self.parametrics = None
self.optimizations = None
self._parametrics = None
self._optimizations = None
self._native_components = None
self._mesh = None

Expand Down
7 changes: 5 additions & 2 deletions pyaedt/modules/SolveSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ def delete(self):
``True`` if setup is deleted. ``False`` if it failed.
"""

self.omodule.DeleteSetups([self.name])
self._app.setups.remove(self)
self._app.delete_setup(self.name)
return True

@pyaedt_function_handler()
Expand Down Expand Up @@ -3627,6 +3626,10 @@ def add_sweep(self, sweepname=None, sweeptype="Interpolating"):
return False
sweep_n.create()
self.sweeps.append(sweep_n)
for setup in self.p_app.setups:
if self.name == setup.name:
setup.sweeps.append(sweep_n)
break
return sweep_n

@pyaedt_function_handler()
Expand Down