Skip to content

Commit

Permalink
Merge branch 'main' into feat/toolkit_installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed Apr 26, 2024
2 parents 3f68e63 + 87739a9 commit 943af54
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 48 deletions.
8 changes: 4 additions & 4 deletions _unittest/test_09_VariableManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ def test_07_addition(self):
v2 = Variable(3)
v3 = Variable("3mA")
v4 = Variable("10A")
with pytest.raises(AssertionError):
with pytest.raises(ValueError):
v1 + v2

with pytest.raises(AssertionError):
with pytest.raises(ValueError):
v2 + v1
result_1 = v2 + v2
result_2 = v3 + v4
Expand All @@ -278,10 +278,10 @@ def test_08_subtraction(self):
v3 = Variable("3mA")
v4 = Variable("10A")

with pytest.raises(AssertionError):
with pytest.raises(ValueError):
v1 - v2

with pytest.raises(AssertionError):
with pytest.raises(ValueError):
v2 - v1

result_1 = v2 - v2
Expand Down
1 change: 1 addition & 0 deletions _unittest/test_28_Maxwell3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def test_05a_assign_coil(self):
def test_05_draw_region(self):
assert self.aedtapp.modeler.create_air_region(*[300] * 6)

@pytest.mark.skipif(desktop_version == "2024.2", reason="GetDisplacementCurrent not working in 2024.2")
def test_06_eddycurrent(self):
assert self.aedtapp.eddy_effects_on(["Plate"], enable_eddy_effects=True)
oModule = self.aedtapp.odesign.GetModule("BoundarySetup")
Expand Down
63 changes: 57 additions & 6 deletions doc/source/Getting_started/Contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ for switching from viewing the documentation for the latest stable release
to viewing the documentation for the development version or previously
released versions.

Adhere to code style
--------------------
PyAEDT is compliant with `PyAnsys code style
<https://dev.docs.pyansys.com/coding-style/index.html>`_. It uses the tool
`pre-commit <https://pre-commit.com/>`_ to check the code style. You can install
and activate this tool with:
Code style
----------
PyAEDT complies with the `PyAnsys code style
<https://dev.docs.pyansys.com/coding-style/index.html>`_.
`pre-commit <https://pre-commit.com/>`_ is applied within the CI/CD to ensure compliance.
The ``pre-commit`` Python package can be installed
and run as follows:

.. code:: bash
Expand All @@ -73,6 +74,56 @@ For example::
Validate GitHub Workflows................................................Passed
blacken-docs.............................................................Passed

Naming conventions
~~~~~~~~~~~~~~~~~~
Consistency of names helps improve readability and
ease of use. Starting with release 0.8 a concerted effort
has been made to
improve consistency of naming and adherence to
:ref:`PEP-8<https://peps.python.org/pep-0008/>`_.

For example, methods used to create or access entities in
AEDT require that a name be passed to the method or function
as an argument.
It is tempting to
include context as part of that variable name. For example, while it is tempting to use
``setupname``
as an argument to :meth:`Hfss.create_setup`_,
the context "setup" is
explicitly defined by the method name. The variable ``name`` provides
a more compact
description of the variable in this context.

In previous PyAEDT versions, you can also find both ``setup_name`` and ``setupname`` used
for various methods or classes.
Improving naming consistency improves maintainability and readability.

The following table illustrates the recommended conventions:

.. list-table:: Keywords and object names
:widths: 25 25 50
:header-rows: 1

* - Old name
- New name
- Example
* - ``setupname``, ``setup_name``, ``sweepname``
- ``name``
- ``Hfss.create_setup()``, ``Hfss.create_linear_step_sweep()``
* - ``usethickness``
- ``thickness``
- ``Hfss.assign_coating()``
* - ``entities``
- ``assignment``
- ``Maxwell.assign_current_density()``
* - ``entity_list``
- ``assignment``
- ``Maxwell.assign_symmetry()``

Take care to use descriptive names for
variables and classes that adhere to PEP-8 and are consistent with conventions already
used in PyAEDT.

Log errors
~~~~~~~~~~
PyAEDT has an internal logging tool named ``Messenger``
Expand Down
7 changes: 0 additions & 7 deletions examples/03-Maxwell/Maxwell2D_Electrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,6 @@

M2D.post.export_field_plot(plot_name="LineTracesTest", output_dir=M2D.toolkit_directory, file_format="fldplt")

##########################################################
# Export a field plot to an image file
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Export the flux lines plot to an image file using PyVista Python package.

M2D.post.plot_field_from_fieldplot(plot.name, show=False)

##########################################################
# Export the mesh field plot
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
67 changes: 42 additions & 25 deletions pyaedt/application/Variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import absolute_import # noreorder
from __future__ import division

import ast
import os
import re
import types
Expand Down Expand Up @@ -156,14 +157,17 @@ def __getitem__(self, item):
if variable in key_string:
found_variable = True
break
assert found_variable, "Input string {} is not a key of the data dictionary.".format(variable)
if not found_variable:
raise KeyError("Input string {} is not a key of the data dictionary.".format(variable))
data_out._data[variable] = self._data[key_string]
data_out._header.append(variable)
return data_out

@pyaedt_function_handler()
def __add__(self, other):
assert self.number_of_columns == other.number_of_columns, "Inconsistent number of columns"
if self.number_of_columns != other.number_of_columns:
raise ValueError("Number of columns is inconsistent.")

# Create a new object to return, avoiding changing the original inputs
new_dataset = CSVDataset()
# Add empty columns to new_dataset
Expand Down Expand Up @@ -198,7 +202,8 @@ def __iadd__(self, other):
for column in other.data:
self._data[column] = []

assert self.number_of_columns == other.number_of_columns, "Inconsistent number of columns"
if self.number_of_columns != other.number_of_columns:
raise ValueError("Number of columns is inconsistent.")

# Append the data from 'other'
for column, row_data in other.data.items():
Expand Down Expand Up @@ -1056,7 +1061,7 @@ def set_variable(
self._logger.clear_messages()
return
except Exception:
pass
self._logger.debug("Something went wrong when deleting '{}'.".format(variable_name))
else:
raise Exception("Unhandled input type to the design property or project variable.") # pragma: no cover

Expand Down Expand Up @@ -1188,7 +1193,7 @@ def delete_separator(self, separator_name):
)
return True
except Exception:
pass
self._logger.debug("Failed to change desktop object property.")
return False

@pyaedt_function_handler()
Expand Down Expand Up @@ -1229,7 +1234,7 @@ def delete_variable(self, var_name):
]
)
except Exception: # pragma: no cover
pass
self._logger.debug("Failed to change desktop object property.")
else:
self._cleanup_variables()
return True
Expand Down Expand Up @@ -1424,9 +1429,12 @@ def __init__(
self._value = self._calculated_value
# If units have been specified, check for a conflict and otherwise use the specified unit system
if units:
assert not self._units, "The unit specification {} is inconsistent with the identified units {}.".format(
specified_units, self._units
)
if self._units and self._units != specified_units:
raise RuntimeError(
"The unit specification {} is inconsistent with the identified units {}.".format(
specified_units, self._units
)
)
self._units = specified_units

if not si_value and is_number(self._value):
Expand Down Expand Up @@ -1493,7 +1501,7 @@ def _set_prop_val(self, prop, val, n_times=10):
break
i += 1
except Exception:
pass
self._app.logger.debug("Failed to set property '{}' value.".format(prop))

@pyaedt_function_handler()
def _get_prop_val(self, prop):
Expand All @@ -1515,7 +1523,7 @@ def _get_prop_val(self, prop):
name = "LocalVariables"
return self._app.get_oo_object(self._aedt_obj, "{}/{}".format(name, self._variable_name)).GetPropValue(prop)
except Exception:
pass
self._app.logger.debug("Failed to get property '{}' value.".format(prop))

@property
def name(self):
Expand Down Expand Up @@ -1724,7 +1732,7 @@ def expression(self, value):
def numeric_value(self):
"""Numeric part of the expression as a float value."""
if is_array(self._value):
return list(eval(self._value))
return list(ast.literal_eval(self._value))
try:
var_obj = self._aedt_obj.GetChildObject("Variables").GetChildObject(self._variable_name)
val, _ = decompose_variable_value(var_obj.GetPropEvaluatedValue("EvaluatedValue"))
Expand Down Expand Up @@ -1818,9 +1826,12 @@ def rescale_to(self, units):
"""
new_unit_system = unit_system(units)
assert (
new_unit_system == self.unit_system
), "New unit system {0} is inconsistent with the current unit system {1}."
if new_unit_system != self.unit_system:
raise ValueError(
"New unit system {} is inconsistent with the current unit system {}.".format(
new_unit_system, self.unit_system
)
)
self._units = units
return self

Expand Down Expand Up @@ -1891,7 +1902,9 @@ def __mul__(self, other):
>>> assert result_3.unit_system == "Power"
"""
assert is_number(other) or isinstance(other, Variable), "Multiplier must be a scalar quantity or a variable."
if not is_number(other) and not isinstance(other, Variable):
raise ValueError("Multiplier must be a scalar quantity or a variable.")

if is_number(other):
result_value = self.numeric_value * other
result_units = self.units
Expand Down Expand Up @@ -1936,10 +1949,11 @@ def __add__(self, other):
>>> assert result.unit_system == "Current"
"""
assert isinstance(other, Variable), "You can only add a variable with another variable."
assert (
self.unit_system == other.unit_system
), "Only ``Variable`` objects with the same unit system can be added."
if not isinstance(other, Variable):
raise ValueError("You can only add a variable with another variable.")
if self.unit_system != other.unit_system:
raise ValueError("Only Variable objects with the same unit system can be added.")

result_value = self.value + other.value
result_units = SI_UNITS[self.unit_system]
# If the units of the two operands are different, return SI-Units
Expand Down Expand Up @@ -1978,10 +1992,11 @@ def __sub__(self, other):
>>> assert result_2.unit_system == "Current"
"""
assert isinstance(other, Variable), "You can only subtract a variable from another variable."
assert (
self.unit_system == other.unit_system
), "Only ``Variable`` objects with the same unit system can be subtracted."
if not isinstance(other, Variable):
raise ValueError("You can only subtract a variable from another variable.")
if self.unit_system != other.unit_system:
raise ValueError("Only Variable objects with the same unit system can be subtracted.")

result_value = self.value - other.value
result_units = SI_UNITS[self.unit_system]
# If the units of the two operands are different, return SI-Units
Expand Down Expand Up @@ -2023,7 +2038,9 @@ def __truediv__(self, other):
>>> assert result_1.unit_system == "Current"
"""
assert is_number(other) or isinstance(other, Variable), "Divisor must be a scalar quantity or a variable."
if not is_number(other) and not isinstance(other, Variable):
raise ValueError("Divisor must be a scalar quantity or a variable.")

if is_number(other):
result_value = self.numeric_value / other
result_units = self.units
Expand Down
4 changes: 2 additions & 2 deletions pyaedt/modules/AdvancedPostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ def plot_field_from_fieldplot(
):
"""Export a field plot to an image file (JPG or PNG) using Python PyVista.
This method does not support streamlines plot.
.. note::
The PyVista module rebuilds the mesh and the overlap fields on the mesh.
Expand Down Expand Up @@ -392,8 +394,6 @@ def plot_field_from_fieldplot(
else:
self.ofieldsreporter.UpdateQuantityFieldsPlots(plot_folder)

if self.field_plots[plot_name].field_type == "DC R/L Fields":
file_format = "fldplt"
file_to_add = self.export_field_plot(plot_name, self._app.working_directory, file_format=file_format)
model = self.get_model_plotter_geometries(
generate_mesh=False,
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/modules/SolveSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ def _get_primitives_points_per_net(self):
while len(primitive_dict[net]) < len(net_primitives[net]):
if n > 1000: # adding 1000 as maximum value to prevent infinite loop
return
n += 20
n += 10
primitive_dict[net] = []
for prim in primitives:
layer = edb.stackup.signal_layers[prim.layer_name]
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tests = [
"pyedb>=0.5.0,<0.9; python_version > '3.7'",
"pyvista>=0.38.0,<0.44",
"scikit-learn>=1.0.0,<1.5",
"scikit-rf>=0.30.0,<0.33",
"scikit-rf>=0.30.0,<1.1",
"SRTM.py",
"utm",
"vtk==9.2.6",
Expand Down Expand Up @@ -84,7 +84,7 @@ doc = [
"pyvista>=0.38.0,<0.44",
"recommonmark",
#"scikit-learn",
"scikit-rf>=0.30.0,<0.33",
"scikit-rf>=0.30.0,<1.1",
"Sphinx==5.3.0; python_version == '3.7'",
"Sphinx>=7.1.0,<7.4; python_version > '3.7'",
"sphinx-autobuild==2021.3.14; python_version == '3.7'",
Expand Down Expand Up @@ -128,7 +128,7 @@ all = [
"osmnx>=1.1.0,<1.10",
"pandas>=1.1.0,<2.3",
"pyvista>=0.38.0,<0.44",
"scikit-rf>=0.30.0,<0.33",
"scikit-rf>=0.30.0,<1.1",
"SRTM.py",
"utm",
"vtk==9.2.6",
Expand Down

0 comments on commit 943af54

Please sign in to comment.