Skip to content

Commit

Permalink
FIX: Use pyedb instead of pyaedt to create EDB instances (#36)
Browse files Browse the repository at this point in the history
* FIX: Use pyedb to create EDB class

* CI: Fix step name typo

* DOC: Fix example comment typo

* FIX: Wrong import in example

* TESTS: Update edb writer test to use pyedb

* MAINT: Upgrade to newest pyaedt version

Note: This version has a dependency to pyedb.

* DOC: Extend check on example errors

* MISC: Update version to 2024.1

* CI: Add license server env variable

* FIX: Import pyedb download_file

* FIX: Missed import pyedb download_file

* FIX: Pyedb imports

* DOC: Fix run twice in CI and local

* WIP: Test fixing env var usage
  • Loading branch information
SMoraisAnsys authored Mar 5, 2024
1 parent 6585e49 commit 86d0b6f
Show file tree
Hide file tree
Showing 27 changed files with 107 additions and 81 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
env:
MAIN_PYTHON_VERSION: '3.10'
PACKAGE_NAME: 'pyaedt-examples'
ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER) }}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -79,10 +80,12 @@ jobs:
doc-build:
name: Build documentation
runs-on: [self-hosted, Windows, pyaedt-examples]
env:
SPHINXBUILD_KEEP_DOCTREEDIR: "1"
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ env.MAIN_PYTHON_VERSION_WINDOWS }}
- name: Set up Python ${{ env.MAIN_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
Expand Down Expand Up @@ -115,7 +118,6 @@ jobs:
# Use environment variable to keep the doctree and avoid redundant build for PDF pages
- name: Create HTML documentation
run: |
echo "SPHINXBUILD_KEEP_DOCTREEDIR=1" >> $GITHUB_ENV
.venv\Scripts\Activate.ps1
. .\doc\make.bat html
Expand All @@ -126,6 +128,10 @@ jobs:
path: doc/_build/html
retention-days: 7

- name: Update environment variable
run: |
echo "SPHINXBUILD_KEEP_DOCTREEDIR=0" >> $GITHUB_ENV
# Use environment variable to remove the doctree after the build of PDF pages
# Keeping doctree could cause an issue, see https://github.com/ansys/pyaedt/pull/3844/files
- name: Create PDF documentation
Expand Down
10 changes: 8 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def remove_doctree(app, exception):

# Keep the doctree to avoid creating it twice. This is typically helpful in CI/CD
# where we want to build both HTML and PDF pages.
if bool(os.getenv("SPHINXBUILD_KEEP_DOCTREEDIR", False)):
if bool(int(os.getenv("SPHINXBUILD_KEEP_DOCTREEDIR", "0"))):
logger.info(f"Keeping directory {app.doctreedir}.")
else:
size = directory_size(app.doctreedir)
Expand Down Expand Up @@ -204,7 +204,13 @@ def check_example_error(app, pagename, templatename, context, doctree):
if any(
map(
lambda msg: msg in context["body"],
["UsageError", "NameError", "DeadKernelError", "NotebookError"],
[
"UsageError",
"NameError",
"DeadKernelError",
"NotebookError",
"CellExecutionError",
],
)
):
logger.error(f"An error was detected in file {pagename}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
import tempfile

from ansys.pyaedt.examples.constants import EDB_VERSION
import pyaedt
import pyedb

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
aedb_path = os.path.join(temp_dir.name, "create_via.aedb")
print(f"AEDB file path: {aedb_path}")

# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edb = pyaedt.Edb(edbpath=aedb_path, edbversion=edb_version)
edb = pyedb.Edb(edbpath=aedb_path, edbversion=edb_version)
# -

# ## Add stackup layers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import time

from ansys.pyaedt.examples.constants import EDB_VERSION
import pyaedt
import pyedb
from pyedb.misc.downloads import download_file

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
targetfile = pyaedt.downloads.download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)
targetfile = download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)

siwave_file = os.path.join(os.path.dirname(targetfile), "ANSYS-HSD_V1.siw")
print(targetfile)
Expand All @@ -22,17 +23,17 @@

# ## Launch Ansys Electronics Database (EDB)
#
# Instantiate an instance of the `pyaedt.Edb` class using SI units.
# Instantiate an instance of the `pyedb.Edb` class using SI units.

# +
if os.path.exists(aedt_file):
os.remove(aedt_file)

# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edb = pyaedt.Edb(edbpath=targetfile, edbversion=edb_version)
edb = pyedb.Edb(edbpath=targetfile, edbversion=edb_version)
# -

# ## Identify nets and components
Expand Down Expand Up @@ -193,7 +194,7 @@
# using the SIwave user interface. This command works on Window OS only.

# +
# siwave = pyaedt.Siwave("2023.2")
# siwave = pyedb.Siwave("2024.1")
# siwave.open_project(siwave_file)
# report_file = os.path.join(temp_folder,'Ansys.htm')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,36 @@
import tempfile

from ansys.pyaedt.examples.constants import EDB_VERSION
import pyaedt
import pyedb
from pyedb.generic.general_methods import generate_unique_name
from pyedb.misc.downloads import download_file

# -

# ## Download the AEDB file and copy it in the temporary folder.

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
targetfile = pyaedt.downloads.download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)
targetfile = download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)
ipc2581_file_name = os.path.join(temp_dir.name, "Ansys_Hsd.xml")
print(targetfile)

# ## Launch EDB
#
# Launch the `pyaedt.Edb` class, using EDB 2023.
# Launch the `pyedb.Edb` class, using EDB 2023.
# > Note that length dimensions passed to EDB are in SI units.

# +
# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edb = pyaedt.Edb(edbpath=targetfile, edbversion=edb_version)
edb = pyedb.Edb(edbpath=targetfile, edbversion=edb_version)
# -

# ## Parametrize the width of a trace.

edb.modeler.parametrize_trace_width(
"A0_N", parameter_name=pyaedt.generate_unique_name("Par"), variable_value="0.4321mm"
"A0_N", parameter_name=generate_unique_name("Par"), variable_value="0.4321mm"
)

# ## Create a cutout and plot it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from ansys.pyaedt.examples.constants import EDB_VERSION
import pyaedt
import pyedb

# -

Expand Down Expand Up @@ -79,18 +80,18 @@ def points(self):

# ## Launch EDB
#
# PyAEDT.Edb allows to open existing Edb project or create a new empty project.
# PyEDB.Edb allows to open existing Edb project or create a new empty project.

# +
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
aedb_path = os.path.join(temp_dir.name, "linear_array.aedb")

# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

# Create an instance of the Edb class.
edb = pyaedt.Edb(edbpath=aedb_path, edbversion=edb_version)
edb = pyedb.Edb(edbpath=aedb_path, edbversion=edb_version)
# -

# Add stackup layers
Expand Down Expand Up @@ -244,7 +245,7 @@ def points(self):
h3d = pyaedt.Hfss(
projectname="Demo_3DComp",
designname="Linear_Array",
specified_version="2023.2",
specified_version="2024.1",
new_desktop_session=True,
non_graphical=non_graphical,
close_on_exit=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ansys.pyaedt.examples.constants import EDB_VERSION
import pyaedt
import pyedb

# -

Expand All @@ -32,11 +33,11 @@
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
aedb_path = os.path.join(temp_dir.name, "pcb.aedb")

# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edb = pyaedt.Edb(edbpath=aedb_path, edbversion=edb_version)
edb = pyedb.Edb(edbpath=aedb_path, edbversion=edb_version)
# -

# Define the parameters.
Expand Down Expand Up @@ -303,7 +304,7 @@

h3d = pyaedt.Hfss3dLayout(
projectname=aedb_path,
specified_version="2023.2",
specified_version="2024.1",
non_graphical=non_graphical,
new_desktop_session=True,
)
Expand Down
13 changes: 7 additions & 6 deletions examples/00-EDB/05_Plot_nets.py → examples/EDB/05_Plot_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,30 @@
import tempfile

from ansys.pyaedt.examples.constants import EDB_VERSION
import pyaedt
import pyedb
from pyedb.misc.downloads import download_file

# -

# ## Download the EDB and copy it into the temporary folder.

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
targetfolder = pyaedt.downloads.download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)
targetfolder = download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)

# ## Create an instance of the Electronics Database using the `pyaedt.Edb` class.
# ## Create an instance of the Electronics Database using the `pyedb.Edb` class.
#
# > Note that units are SI.

# +
# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edb = pyaedt.Edb(edbpath=targetfolder, edbversion=edb_version)
edb = pyedb.Edb(edbpath=targetfolder, edbversion=edb_version)
# -

# Display the nets on a layer. You can display the net geometry directly in Python using
# ``matplotlib`` from the ``pyaedt.Edb`` class.
# ``matplotlib`` from the ``pyedb.Edb`` class.

edb.nets.plot("AVCC_1V3")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ansys.pyaedt.examples.constants import EDB_VERSION
import numpy as np
import pyaedt
import pyedb

# Create the EDB project.

Expand All @@ -34,14 +34,14 @@ def create_ground_planes(edb, layers):
# ## Create the EDB
#
# Create the EDB instance.
# If the path doesn't exist, PyAEDT automatically generates a new AEDB folder.
# If the path doesn't exist, PyEDB automatically generates a new AEDB folder.

# +
# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edb = pyaedt.Edb(edbpath=aedb_path, edbversion=edb_version)
edb = pyedb.Edb(edbpath=aedb_path, edbversion=edb_version)
# -

# Insert the stackup layers.
Expand Down
10 changes: 5 additions & 5 deletions examples/00-EDB/08_CPWG.py → examples/EDB/08_CPWG.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from ansys.pyaedt.examples.constants import AEDT_VERSION, EDB_VERSION
import numpy as np
import pyaedt
import pyedb
from pyedb.generic.general_methods import generate_unique_folder_name, generate_unique_name

# ## Set non-graphical mode

Expand All @@ -24,16 +26,14 @@
# ## Launch EDB

# +
aedb_path = os.path.join(
pyaedt.generate_unique_folder_name(), pyaedt.generate_unique_name("pcb") + ".aedb"
)
aedb_path = os.path.join(generate_unique_folder_name(), generate_unique_name("pcb") + ".aedb")
print(aedb_path)

# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edbapp = pyaedt.Edb(edbpath=aedb_path, edbversion=edb_version)
edbapp = pyedb.Edb(edbpath=aedb_path, edbversion=edb_version)
# -

# ## Define parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@

from ansys.pyaedt.examples.constants import EDB_VERSION
import pyaedt
import pyedb
from pyedb.misc.downloads import download_file

# -

# Download the AEDB file and copy it to a temporary folder.

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
target_aedb = pyaedt.downloads.download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)
target_aedb = download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)
print("Project folder is", target_aedb)

# ## Launch EDB
#
# Launch the ``pyaedt.Edb`` class using EDB 2023 R2. Length units are SI.
# Launch the ``pyedb.Edb`` class using EDB 2023 R2. Length units are SI.

# +
# Select EDB version (change it manually if needed, e.g. "2023.2")
# Select EDB version (change it manually if needed, e.g. "2024.1")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edbapp = pyaedt.Edb(target_aedb, edbversion=edb_version)
edbapp = pyedb.Edb(target_aedb, edbversion=edb_version)
# -

# ## Import definitions
Expand Down Expand Up @@ -188,7 +190,7 @@
# Set ``non_graphical=True`` to run the simulation in non-graphical mode.

h3d = pyaedt.Hfss3dLayout(
specified_version="2023.2",
specified_version="2024.1",
projectname=target_aedb,
non_graphical=False,
new_desktop_session=False,
Expand Down
Loading

0 comments on commit 86d0b6f

Please sign in to comment.