Skip to content

Refactor optimetrics #974

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

Merged
merged 15 commits into from
Mar 23, 2022
9 changes: 9 additions & 0 deletions _unittest/test_01_Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,12 @@ def test_29_change_registry_key(self):
assert not desktop.change_registry_key("test_key_string", "test_string")
assert not desktop.change_registry_key("test_key_int", 2)
assert not desktop.change_registry_key("test_key", 2.0)

def test_30_object_oriented(self):
assert self.aedtapp.get_oo_name(self.aedtapp.oproject, "Variables")
assert self.aedtapp.get_oo_name(self.aedtapp.odesign, "Variables")
assert not self.aedtapp.get_oo_name(self.aedtapp.odesign, "Variables1")
assert self.aedtapp.get_oo_object(self.aedtapp.oproject, "Variables")
assert not self.aedtapp.get_oo_object(self.aedtapp.oproject, "Variables1")
assert self.aedtapp.get_oo_properties(self.aedtapp.oproject, "Variables\\$height")
assert self.aedtapp.get_oo_property_value(self.aedtapp.oproject, "Variables\\$height", "Value") == "10mm"
2 changes: 1 addition & 1 deletion _unittest/test_03_Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,5 @@ def test_09_non_linear_materials(self):
assert app.modeler.create_box([0, 0, 0], [10, 10, 10], matname="myMat2")

def test_10_add_material_sweep(self):
assert self.aedtapp.materials.add_material_sweep(["copper3", "new_copper"], "sweep_copper")
assert self.aedtapp.materials.add_material_sweep(["copper", "aluminum"], "sweep_copper")
assert "sweep_copper" in list(self.aedtapp.materials.material_keys.keys())
6 changes: 5 additions & 1 deletion _unittest/test_07_Object3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ def test_00_object_performance(self):
time_fn(self.create_copper_box_test_performance)

def test_01_bounding_box(self):
l1 = len(self.aedtapp.modeler.solid_objects)
o = self.create_copper_box()
a = o.color
assert len(self.aedtapp.modeler.solid_objects) == l1 + 1
assert len(self.aedtapp.modeler.sheet_objects) == 0
assert len(self.aedtapp.modeler.line_objects) == 0
assert isinstance(o.color, tuple)
bb = o.bounding_box
assert len(bb) == 6

Expand Down
2 changes: 1 addition & 1 deletion _unittest/test_08_Primitives3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ def test_77_create_helix(self):
)

# Test that an exception is raised if the name of the polyline is not provided.
# We can't use with.pytest.raises pattern bellow because IronPython does not support pytest.
# We can't use with.pytest.raises pattern below because IronPython does not support pytest.
try:
self.aedtapp.modeler.create_helix(
polyline_name="",
Expand Down
84 changes: 65 additions & 19 deletions _unittest/test_20_HFSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,42 +568,80 @@ def test_24_create_curvilinear(self):
def test_25_create_parametrics(self):
self.aedtapp["w1"] = "10mm"
self.aedtapp["w2"] = "2mm"
setup1 = self.aedtapp.opti_parametric.add_parametric_setup("w1", "LIN 0.1mm 20mm 0.2mm")
setup1 = self.aedtapp.parametrics.add({"w1": "LIN 0.1mm 20mm 0.2mm"})
assert setup1
assert setup1.add_variation("w2", "LINC 0.1mm 10mm 11")
assert setup1.add_variation("w2", "0.1mm", 10, 11)
assert setup1.add_calculation(
calculation="dB(S(1,1))", calculation_value="2.5GHz", reporttype="Modal Solution Data"
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, solution="MySetupForSweep : LastAdaptive"
)
assert setup1.name in self.aedtapp.get_oo_name(
self.aedtapp.odesign, r"Optimetrics".format(self.aedtapp.design_name)
)
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, r"Optimetrics\{}".format(setup1.name))
oo_calculation = oo.GetCalculationInfo()[0]
assert "Modal Solution Data" in oo_calculation
assert setup1.export_to_csv(os.path.join(self.local_scratch.path, "test.csv"))
assert os.path.exists(os.path.join(self.local_scratch.path, "test.csv"))
assert self.aedtapp.parametrics.add_from_file(
os.path.join(self.local_scratch.path, "test.csv"), "ParametricsfromFile"
)
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, r"Optimetrics\ParametricsfromFile")
assert oo

def test_26_create_optimization(self):
setup2 = self.aedtapp.opti_optimization.add_optimization("db(S(1,1))", "2.5GHz")
calculation = "db(S(Cir1,Cir1))"
setup2 = self.aedtapp.optimizations.add(calculation, ranges={"Freq": "2.5GHz"})
assert setup2

assert setup2.add_goal(calculation="dB(S(1,1))", calculation_value="2.6GHz")
assert setup2.add_goal(
calculation="dB(S(1,1))", calculation_value="2.6GHz", calculation_type="rd", calculation_stop="5GHz"
)
assert setup2.name in self.aedtapp.get_oo_name(
self.aedtapp.odesign, r"Optimetrics".format(self.aedtapp.design_name)
)
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, r"Optimetrics\{}".format(setup2.name))
oo_calculation = oo.GetCalculationInfo()[0]
assert calculation in oo_calculation
assert self.aedtapp.nominal_sweep in oo_calculation
for el in oo_calculation:
if "NAME:Ranges" in el:
break
assert len(el) == 3
assert setup2.add_goal(calculation=calculation, ranges={"Freq": "2.6GHz"})
oo_calculation = oo.GetCalculationInfo()[0]
for el in reversed(oo_calculation):
if "NAME:Ranges" in el:
break
assert "2.6GHz" in el[2]
assert setup2.add_goal(calculation=calculation, ranges={"Freq": ("2.6GHz", "5GHZ")})
oo = self.aedtapp.get_oo_object(self.aedtapp.odesign, r"Optimetrics\{}".format(setup2.name))
oo_calculation = oo.GetCalculationInfo()[0]
for el in reversed(oo_calculation):
if "NAME:Ranges" in el:
break
assert "rd" in el[2]

def test_27_create_doe(self):
setup2 = self.aedtapp.opti_doe.add_doe("db(S(1,1))", "2.5GHz")
setup2 = self.aedtapp.optimizations.add("db(S(1,1))", ranges={"Freq": "2.5GHz"}, optim_type="DXDOE")
assert setup2
assert setup2.add_goal(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})
assert setup2.add_calculation(calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"})

def test_28A_create_dx(self):
setup2 = self.aedtapp.optimizations.add(None, {"w1": "1mm", "w2": "2mm"}, optim_type="optiSLang")
assert setup2
assert setup2.add_goal(calculation="dB(S(1,1))", calculation_value="2.6GHz")
assert setup2.add_calculation(calculation="dB(S(1,1))", calculation_value="2.5GHz")
assert setup2.add_goal(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})

def test_28_create_dx(self):
setup2 = self.aedtapp.opti_designxplorer.add_dx_setup(["w1", "w2"], ["1mm", "2mm"])
def test_28B_create_dx(self):
setup2 = self.aedtapp.optimizations.add(None, {"w1": "1mm", "w2": "2mm"}, optim_type="DesignExplorer")
assert setup2
assert setup2.add_goal(calculation="dB(S(1,1))", calculation_value="2.6GHz")
assert setup2.add_goal(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})

def test_29_create_sensitivity(self):
setup2 = self.aedtapp.opti_sensitivity.add_sensitivity("db(S(1,1))", "2.5GHz")
setup2 = self.aedtapp.optimizations.add("db(S(1,1))", ranges={"Freq": "2.5GHz"}, optim_type="Sensitivity")
assert setup2
assert setup2.add_calculation(calculation="dB(S(1,1))", calculation_value="2.6GHz")
assert setup2.add_calculation(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})

def test_29_create_statistical(self):
setup2 = self.aedtapp.opti_statistical.add_statistical("db(S(1,1))", "2.5GHz")
setup2 = self.aedtapp.optimizations.add("db(S(1,1))", ranges={"Freq": "2.5GHz"}, optim_type="Statistical")
assert setup2
assert setup2.add_calculation(calculation="dB(S(1,1))", calculation_value="2.6GHz")
assert setup2.add_calculation(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})

def test_30_assign_initial_mesh(self):
assert self.aedtapp.mesh.assign_initial_mesh_from_slider(6)
Expand Down Expand Up @@ -754,6 +792,14 @@ def test_44_create_infinite_sphere(self):
polarization_angle=30,
)
assert bound.azimuth_start == "2deg"
self.aedtapp.create_setup()
sweep6 = self.aedtapp.optimizations.add(
calculation="RealizedGainTotal",
solution=self.aedtapp.nominal_adaptive,
ranges={"Freq": "5GHz", "Theta": "0deg", "Phi": "0deg"},
context=bound.name,
)
assert sweep6

def test_45_set_autoopen(self):
assert self.aedtapp.set_auto_open(True, "PML")
Expand Down
24 changes: 5 additions & 19 deletions doc/source/API/CoreModules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,10 @@ optimetrics setups.
close_on_exit=True, student_version=False)

# returns the ParametericsSetups Class
app.opti_parametric
app.parametrics

# returns the OptimizationSetups Class
app.opti_optimization

# returns the DOESetups Class
app.opti_doe

# returns the DXSetups Class
app.opti_designxplorer

# returns the SensitivitySetups Class
app.opti_sensitivity

# returns the StatisticalSetups Class
app.opti_statistical
app.optimizations

# adds an optimization and returns Setup class with all settings and methods
sweep3 = hfss.opti_optimization.add_optimization(calculation="dB(S(1,1))", calculation_value="2.5GHz")
Expand All @@ -82,12 +70,10 @@ optimetrics setups.
:toctree: _autosummary
:nosignatures:

DXSetups
ParametericsSetups
SensitivitySetups
StatisticalSetups
DOESetups
ParametericSetups
OptimizationSetups
SetupParam
SetupOpti



Expand Down
4 changes: 2 additions & 2 deletions examples/00-EDB/00_EDB_Create_VIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
###############################################################################
# Import the EDB Layout Object
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This example imports the EDB layout object and initializes it on version 2021.2.
# This example imports the EDB layout object and initializes it on version 2022R1.

import time
import os
Expand All @@ -21,7 +21,7 @@
tmpfold = tempfile.gettempdir()
aedb_path = os.path.join(tmpfold, generate_unique_name("pcb") + ".aedb")
print(aedb_path)
edb = Edb(edbpath=aedb_path, edbversion="2021.2")
edb = Edb(edbpath=aedb_path, edbversion="2022.1")

###############################################################################
# Create a Stackup
Expand Down
6 changes: 3 additions & 3 deletions examples/00-EDB/01_edb_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
# Launch EDB
# ~~~~~~~~~~
# This example launches the :class:`pyaedt.Edb` class.
# This example uses EDB 2021.2 and uses SI units.
# This example uses EDB 2022R1 and uses SI units.

if os.path.exists(aedt_file):
os.remove(aedt_file)
edb = Edb(edbpath=targetfile, edbversion="2021.2")
edb = Edb(edbpath=targetfile, edbversion="2022.1")

###############################################################################
# Compute Nets and Components
Expand Down Expand Up @@ -187,7 +187,7 @@
# This command open Siwave and Generate Report. This works on Window Only.

# from pyaedt import Siwave
# siwave = Siwave("2021.2")
# siwave = Siwave("2022.1")
# siwave.open_project(siwave_file)
# report_file = os.path.join(temp_folder,'Galileo.htm')
#
Expand Down
4 changes: 2 additions & 2 deletions examples/00-EDB/02_edb_to_ipc2581.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
# Launch EDB
# ~~~~~~~~~~
# This example launches the :class:`pyaedt.Edb` class.
# This example uses EDB 2021.2 and uses SI units.
# This example uses EDB 2022R1 and uses SI units.

edb = Edb(edbpath=targetfile, edbversion="2021.2")
edb = Edb(edbpath=targetfile, edbversion="2022.1")


###############################################################################
Expand Down
6 changes: 3 additions & 3 deletions examples/00-EDB/03_5G_antenna_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
###############################################################################
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This example imports the `Hfss3dlayout` object and initializes it on version
# 2021.2.
# 2022R1.
import tempfile
from pyaedt import Edb
from pyaedt.generic.general_methods import generate_unique_name
Expand Down Expand Up @@ -67,7 +67,7 @@ def points(self):
tmpfold = tempfile.gettempdir()
aedb_path = os.path.join(tmpfold, generate_unique_name("pcb") + ".aedb")
print(aedb_path)
edb = Edb(edbpath=aedb_path, edbversion="2021.2")
edb = Edb(edbpath=aedb_path, edbversion="2022.1")


###############################################################################
Expand Down Expand Up @@ -190,7 +190,7 @@ def points(self):
# Launch Hfss3d Layout and open Edb
#
project = os.path.join(aedb_path, "edb.def")
h3d = Hfss3dLayout(projectname=project, specified_version="2021.2", new_desktop_session=True, non_graphical=False)
h3d = Hfss3dLayout(projectname=project, specified_version="2022.1", new_desktop_session=True, non_graphical=False)

###############################################################################
# Create Setup and Sweeps
Expand Down
6 changes: 3 additions & 3 deletions examples/00-EDB/04_edb_parametrized_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Import the `Hfss3dlayout` Object
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This example imports the `Hfss3dlayout` object and initializes it on version
# 2021.1.
# 2022.1.

import tempfile
from pyaedt import Edb
Expand All @@ -20,7 +20,7 @@
tmpfold = tempfile.gettempdir()
aedb_path = os.path.join(tmpfold, generate_unique_name("pcb") + ".aedb")
print(aedb_path)
edb = Edb(edbpath=aedb_path, edbversion="2021.2")
edb = Edb(edbpath=aedb_path, edbversion="2022.1")
var_server = edb.active_cell.GetVariableServer()


Expand Down Expand Up @@ -322,7 +322,7 @@ def get_variable_value(self, variable_name=""):

##########################
# opening edb in aedt
h3d = Hfss3dLayout(projectname=os.path.join(aedb_path, "edb.def"), specified_version="2021.2", non_graphical=False)
h3d = Hfss3dLayout(projectname=os.path.join(aedb_path, "edb.def"), specified_version="2022.1", non_graphical=False)

##########################
# creating wave ports
Expand Down
4 changes: 2 additions & 2 deletions examples/00-EDB/05_Plot_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
# Launch EDB
# ~~~~~~~~~~
# This example launches the :class:`pyaedt.Edb` class.
# This example uses EDB 2021.2 and uses SI units.
# This example uses EDB 2022R1 and uses SI units.

edb = Edb(edbpath=targetfolder, edbversion="2021.2")
edb = Edb(edbpath=targetfolder, edbversion="2022.1")

###############################################################################
# Plot a custom set of nets colored by Layer (default).
Expand Down
2 changes: 1 addition & 1 deletion examples/00-EDB/06_Advanced_EDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _create_ground_planes(edb, layers):
# Edb Creation
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If the path doesn't exists pyaedt will generate automatically a new aedb folder.
edb = Edb(edbpath=aedb_path, edbversion="2021.2")
edb = Edb(edbpath=aedb_path, edbversion="2022.1")

##################################################################################
# Stackup Creation
Expand Down
4 changes: 2 additions & 2 deletions examples/01-Modeling-Setup/HFSS_CoordinateSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
###############################################################################
# Launch AEDT in Graphical Mode
# -----------------------------
# This example launches AEDT 2021.2 in graphical mode.
# This example launches AEDT 2022R1 in graphical mode.

nongraphical = False
d = Desktop("2021.2", non_graphical=nongraphical, new_desktop_session=True)
d = Desktop("2022.1", non_graphical=nongraphical, new_desktop_session=True)

###############################################################################
# Insert an HFSS Design
Expand Down
Loading