Skip to content

Commit

Permalink
Merge branch 'main' into detach_faces
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzovecchietti authored Apr 18, 2024
2 parents c332134 + 567fd28 commit cdccddd
Show file tree
Hide file tree
Showing 18 changed files with 191 additions and 133 deletions.
5 changes: 4 additions & 1 deletion _unittest/test_launch_desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ def test_run_desktop_icepak(self):
assert aedtapp.solution_type == "SteadyState"

def test_run_desktop_hfss3dlayout(self):
aedtapp = Hfss3dLayout()
aedtapp = Hfss3dLayout(ic_mode=True)
assert aedtapp.design_type == "HFSS 3D Layout Design"
assert aedtapp.solution_type == "HFSS3DLayout"
assert aedtapp.ic_mode == True
aedtapp.ic_mode = False
assert aedtapp.ic_mode == False

@pytest.mark.skipif(is_linux, reason="Not supported in Linux.")
def test_run_desktop_twinbuilder(self):
Expand Down
7 changes: 3 additions & 4 deletions doc/source/User_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
User guide
==========

This section provides brief tutorials for helping you understand how to effectively use PyAEDT.
This section provides brief tutorials for helping you understand how to use PyAEDT effectively.

For additional practical demonstrations, see
`PyAEDT examples <https://aedt.docs.pyansys.com/version/stable/examples>`_ page.
For end-to-end examples, see `Examples <https://aedt.docs.pyansys.com/version/stable/examples>`_.


.. grid:: 2
Expand Down Expand Up @@ -40,7 +39,7 @@ For additional practical demonstrations, see

How to create a setup and run simulations.

.. grid-item-card:: Variables and Optimetrics
.. grid-item-card:: Variables
:link: variables
:link-type: doc
:margin: 2 2 0 0
Expand Down
15 changes: 7 additions & 8 deletions doc/source/User_guide/intro.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Minimal example
===============
Basic tutorial
==============

You can initiate AEDT in non-graphical mode from Python using this code:

Expand All @@ -11,15 +11,15 @@ You can initiate AEDT in non-graphical mode from Python using this code:
student_version=False):
circuit = pyaedt.Circuit()
...
# Any error here will be caught by Desktop.
# Any error here is caught by AEDT.
...
# Desktop is automatically closed here.
# AEDT is automatically closed here.
The preceding code launches AEDT and initializes a new Circuit design.

.. image:: ../Resources/aedt_first_page.png
:width: 800
:alt: Electronics Desktop launched
:alt: AEDT launched

This code creates a project and saves it with PyAEDT:

Expand All @@ -33,16 +33,15 @@ This code creates a project and saves it with PyAEDT:
cir.release_desktop(save_project=True, close_desktop=True)
# Desktop is released here.
Ansys EDB proprietary layout format is accessible through pyaedt using the following
code:
This code uses PyAEDT to access the Ansys EDB proprietary layout format:

.. code:: python
# Launch the latest installed version of EDB.
import pyaedt
edb = pyaedt.Edb("mylayout.aedb")
# User can launch Edb directly from PyEDB class.
# User can launch EDB directly from the PyEDB class.
import pyedb
edb = pyedb.Edb("mylayout.aedb")
8 changes: 4 additions & 4 deletions pyaedt/aedt_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ def _log_on_dekstop(self, message_type, message_text, level=None, proj_name=None
if not level:
level = "Design"

assert level in message_levels, "Message level must be `Design', 'Project', or 'Global'."
if level not in message_levels:
raise ValueError("Message level must be 'Design', 'Project', or 'Global'.")

if self._log_on_desktop and self._desktop:
if not proj_name and message_levels[level] > 0:
Expand All @@ -590,9 +591,8 @@ def _log_on_dekstop(self, message_type, message_text, level=None, proj_name=None
des_name = des_name[des_name.find(";") + 1 :]
try:
self._desktop.AddMessage(proj_name, des_name, message_type, message_text)

except Exception: # pragma: no cover
pass
self._global.info("Failed to add desktop message.")

def _log_on_handler(self, message_type, message_text, *args, **kwargs):
message_text = str(message_text)
Expand Down Expand Up @@ -660,7 +660,7 @@ def clear_messages(self, proj_name=None, des_name=None, level=2):
try:
self._desktop.ClearMessages(proj_name, des_name, level)
except Exception: # pragma: no cover
pass
self._global.info("Failed to clear desktop messages.")

@property
def non_graphical(self):
Expand Down
78 changes: 36 additions & 42 deletions pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
from pyaedt.modules.SolveSweeps import SetupProps

if is_linux and is_ironpython:
import subprocessdotnet as subprocess
import subprocessdotnet as subprocess # nosec
else:
import subprocess
import subprocess # nosec


class Analysis(Design, object):
Expand Down Expand Up @@ -87,6 +87,9 @@ class Analysis(Design, object):
aedt_process_id : int, optional
Only used when ``new_desktop_session = False``, specifies by process ID which instance
of Electronics Desktop to point PyAEDT at.
ic_mode : bool, optional
Whether to set the design to IC mode. The default is ``False``.
This parameter applies only to HFSS 3D Layout.
"""

Expand All @@ -105,6 +108,7 @@ def __init__(
machine="",
port=0,
aedt_process_id=None,
ic_mode=False,
):
Design.__init__(
self,
Expand All @@ -120,6 +124,7 @@ def __init__(
machine,
port,
aedt_process_id,
ic_mode,
)
self._excitation_objects = {}
self._setup = None
Expand Down Expand Up @@ -285,10 +290,11 @@ def active_setup(self):
def active_setup(self, setup_name):
setup_list = self.existing_analysis_setups
if setup_list:
assert setup_name in setup_list, "Invalid setup name {}".format(setup_name)
if setup_name not in setup_list:
raise ValueError("Setup name {} is invalid.".format(setup_name))
self._setup = setup_name
else:
raise AttributeError("No setup defined")
raise AttributeError("No setup is defined.")

@property
def existing_analysis_sweeps(self):
Expand Down Expand Up @@ -706,7 +712,7 @@ def export_results(
self.post.oreportsetup.ExportToFile(str(report_name), export_path)
self.logger.info("Export Data: {}".format(export_path))
except Exception:
pass
self.logger.info("Failed to export to file.")
exported_files.append(export_path)

if touchstone_format == "MagPhase":
Expand Down Expand Up @@ -945,19 +951,18 @@ def _get_native_data(self):
data_vals = [data_vals]
for ds in data_vals:
try:
component_name = "undefined"
if isinstance(ds, (OrderedDict, dict)):
boundaries.append(
NativeComponentObject(
self,
ds["NativeComponentDefinitionProvider"]["Type"],
ds["BasicComponentInfo"]["ComponentName"],
ds,
)
)
component_type = ds["NativeComponentDefinitionProvider"]["Type"]
component_name = ds["BasicComponentInfo"]["ComponentName"]
native_component_object = NativeComponentObject(self, component_type, component_name, ds)
boundaries.append(native_component_object)
except Exception:
pass
msg = "Failed to add native component object."
msg_end = "." if component_name == "undefined" else "(named {}).".format(component_name)
self.logger.debug(msg + msg_end)
except Exception:
pass
self.logger.debug("Failed to add native component object.")
return boundaries

class AvailableVariations(object):
Expand Down Expand Up @@ -1499,7 +1504,8 @@ def get_output_variable(self, variable, solution=None):
>>> oDesign.GetNominalVariation
>>> oModule.GetOutputVariableValue
"""
assert variable in self.output_variables, "Output variable {} does not exist.".format(variable)
if variable not in self.output_variables:
raise KeyError("Output variable {} does not exist.".format(variable))
nominal_variation = self.odesign.GetNominalVariation()
if solution is None:
solution = self.existing_analysis_sweeps[0]
Expand Down Expand Up @@ -1693,11 +1699,9 @@ def analyze_setup(
name = line.strip().split("=")[1]
break
if name:
try:
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, name)
success = self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, name)
if success:
set_custom_dso = True
except Exception:
pass
elif num_gpu or num_tasks or num_cores:
config_name = "pyaedt_config"
source_name = os.path.join(self.pyaedt_dir, "misc", "pyaedt_local_config.acf")
Expand Down Expand Up @@ -1771,10 +1775,10 @@ def analyze_setup(
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, config_name)
set_custom_dso = True
except Exception:
pass
self.logger.info("Failed to set registry from file {}.".format(target_name))
if not name:
try:
self.logger.info("Solving all design setups")
self.logger.info("Solving all design setups.")
if self.desktop_class.aedt_version_id > "2023.1":
self.odesign.AnalyzeAll(blocking)
else:
Expand Down Expand Up @@ -1919,25 +1923,16 @@ def solve_in_batch(
if os.path.exists(queue_file_completed):
os.unlink(queue_file_completed)

if is_linux and settings.use_lsf_scheduler:
options = [
"-ng",
"-BatchSolve",
"-machinelist",
"list={}:{}:{}:90%:1".format(machine, num_tasks, num_cores),
"-Monitor",
]
if num_tasks == -1:
options.append("-distributed")
options.append("-auto")
else:
options = [
"-ng",
"-BatchSolve",
"-machinelist",
"list={}:{}:{}:90%:1".format(machine, num_tasks, num_cores),
"-Monitor",
]
options = [
"-ng",
"-BatchSolve",
"-machinelist",
"list={}:{}:{}:90%:1".format(machine, num_tasks, num_cores),
"-Monitor",
]
if is_linux and settings.use_lsf_scheduler and num_tasks == -1:
options.append("-distributed")
options.append("-auto")
if setup_name and design_name:
options.append(
"{}:{}:{}".format(
Expand Down Expand Up @@ -1983,7 +1978,6 @@ def solve_in_batch(
DETACHED_PROCESS = 0x00000008
subprocess.Popen(batch_run, creationflags=DETACHED_PROCESS)
self.logger.info("Batch job launched.")

else:
subprocess.Popen(batch_run)
self.logger.info("Batch job finished.")
Expand Down
3 changes: 2 additions & 1 deletion pyaedt/application/Analysis3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,8 @@ def flatten_3d_components(self, component_name=None, purge_history=True, passwor
if isinstance(component_name, str):
component_name = [component_name]
for cmp in component_name:
assert cmp in self.modeler.user_defined_component_names, "Component Definition not found."
if cmp not in self.modeler.user_defined_component_names:
raise ValueError("Component definition was not found for '{}'.".format(cmp))

for cmp in component_name:
comp = self.modeler.user_defined_components[cmp]
Expand Down
8 changes: 6 additions & 2 deletions pyaedt/application/Analysis3DLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ class FieldAnalysis3DLayout(Analysis):
Whether to enable the student version of AEDT. The default
is ``False``.
aedt_process_id : int, optional
Only used when ``new_desktop_session = False``, specifies by process ID which instance
of Electronics Desktop to point PyAEDT at.
Specifies by process ID the instance of AEDT to point PyAEDT at.
This parameter is only used when ``new_desktop_session=False``.
ic_mode : bool, optional
Whether to set the design to IC mode. The default is ``False``.
"""

Expand All @@ -71,6 +73,7 @@ def __init__(
machine="",
port=0,
aedt_process_id=None,
ic_mode=False,
):
Analysis.__init__(
self,
Expand All @@ -87,6 +90,7 @@ def __init__(
machine,
port,
aedt_process_id,
ic_mode,
)
self._modeler = None
self._mesh = None
Expand Down
Loading

0 comments on commit cdccddd

Please sign in to comment.