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

DOCS: Add EDB configuration example. #604

Merged
merged 21 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

legacy_pyaedt_integration/index
legacy_standalone/index
use_configuration/index


Examples
Expand Down
83 changes: 83 additions & 0 deletions examples/use_configuration/import_stackup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# # Import Stackup
# This example shows how to import stackup file.

# ## Import the required packages

# +
import json
from pathlib import Path
import tempfile

from IPython.display import display
import pandas as pd
from pyaedt.downloads import download_file

from pyedb import Edb

AEDT_VERSION = "2024.1"
NG_MODE = False

# -

# Download the example PCB data.

temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
file_edb = download_file(source="edb/ANSYS-HSD_V1.aedb", destination=temp_folder.name)

# ## Load example layout.

edbapp = Edb(file_edb, edbversion=AEDT_VERSION)

# ## Review original stackup definition

# Get original stackup definition in a dictionary. Alternatively, stackup definition can be exported in a json file by
# edbapp.configuration.export()

data_cfg = edbapp.configuration.get_data_from_db(stackup=True)


df = pd.DataFrame(data=data_cfg["stackup"]["layers"])
display(df)

# ## Modify stackup

# Modify top layer thickness

data_cfg["stackup"]["layers"][0]["thickness"] = 0.00005

# Add a solder mask layer

data_cfg["stackup"]["layers"].insert(
0, {"name": "soler_mask", "type": "dielectric", "material": "Megtron4", "fill_material": "", "thickness": 0.00002}
)

# Review modified stackup

df = pd.DataFrame(data=data_cfg["stackup"]["layers"])
display(df.head(3))

# Write stackup definition into a json file

file_cfg = Path(temp_folder.name) / "edb_configuration.json"
with open(file_cfg, "w") as f:
json.dump(data_cfg, f, indent=4, ensure_ascii=False)


# ## Load stackup from json configuration file

edbapp.configuration.load(file_cfg, apply_file=True)

# Plot stackup

edbapp.stackup.plot()

# Check top layer thickness

edbapp.stackup["1_Top"].thickness

# ## Cleanup
#
# All project files are saved in the folder ``temp_file.dir``. If you've run this example as a Jupyter notbook you
# can retrieve those project files. The following cell removes all temporary files, including the project folder.
edbapp.close()
temp_folder.cleanup()
8 changes: 8 additions & 0 deletions examples/use_configuration/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Use configuration
~~~~~~~~~~~~~~~~~
The following examples illustrate the use of configuration files in PyEDB.

.. nbgallery::

import_stackup.py
set_up_edb_for_signal_integrity_analysis.py
184 changes: 184 additions & 0 deletions examples/use_configuration/set_up_edb_for_signal_integrity_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# # Set up EDB for Power Integrity Analysis
# This example shows how to set up the electronics database (EDB) for power integrity analysis from a single
# configuration file.

# ## Preparation
# Import the required packages

import json

# +
import os
import tempfile

from pyaedt import Hfss3dLayout
from pyaedt.downloads import download_file

from pyedb import Edb

AEDT_VERSION = "2024.1"
NG_MODE = False

# -

# Download the example PCB data.

temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
download_file(source="touchstone", name="GRM32_DC0V_25degC_series.s2p", destination=temp_folder.name)
file_edb = download_file(source="edb/ANSYS-HSD_V1.aedb", destination=temp_folder.name)

# Load example layout.

edbapp = Edb(file_edb, edbversion=AEDT_VERSION)

# ## Create a configuration file
# In this example, we are going to use a configuration file to set up the layout for analysis.
# ### Initialize a dictionary
# Create an empty dictionary to host all configurations.

cfg = dict()

# ### Assign S-parameter model to capactitors.

# Set S-parameter library path.

cfg["general"] = {"s_parameter_library": os.path.join(temp_folder.name, "touchstone")}

# Assign the S-parameter model. Keywords
# - **name**. Name of the S-parameter model in AEDT.
# - **component**_definition. Known as component part number of part name.
# - **file_path**. Touchstone file or full path to the touchstone file.
# - **apply_to_all**. When set to True, assign the S-parameter model to all components share the same
# component_definition. When set to False, Only components in "components" are assigned.
# - **components**. when apply_to_all=False, components in the list are assigned an S-parameter model.
# When apply_to_all=False, components in the list are NOT assigned.
# - **reference_net**. Reference net of the S-parameter model.

cfg["s_parameters"] = [
{
"name": "GRM32_DC0V_25degC_series",
"component_definition": "CAPC0603X33X15LL03T05",
"file_path": "GRM32_DC0V_25degC_series.s2p",
"apply_to_all": False,
"components": ["C110", "C206"],
"reference_net": "GND",
}
]

# ### Define ports
# Create a circuit port between power and ground nets. Keywords
# - **name**. Name of the port.
# - **reference_desinator**.
# - **type**. Type of the port. Supported types are 'ciruict', 'coax'.
# - **positive_terminal**. Positive terminal of the port. Supported types are 'net', 'pin', 'pin_group', 'coordinates'.
# - **negative_terminal**. Positive terminal of the port. Supported types are 'net', 'pin', 'pin_group', 'coordinates'.

cfg["ports"] = [
{
"name": "port1",
"reference_designator": "U1",
"type": "circuit",
"positive_terminal": {"net": "1V0"},
"negative_terminal": {"net": "GND"},
}
]

# ### Define SIwave SYZ analysis setup
# Keywords
# - **name**. Name of the setup.
# - **type**. Type of the analysis setup. Supported types are 'siwave_ac', 'siwave_dc', 'hfss'.
# - **pi_slider_position**. PI slider position. Supported values are from '0', '1', '2'. 0:speed, 1:balanced,
# 2:accuracy.
# - **freq_sweep**. List of frequency sweeps.
# - **name**. Name of the sweep.
# - **type**. Type of the sweep. Supported types are 'interpolation', 'discrete', 'broadband'.
# - **frequencies**. Frequency distribution.
# - **distribution**. Supported distributions are 'linear_count', 'linear_scale', 'log_scale'.
# - **start**. Start frequency. Example, 1e6, "1MHz".
# - **stop**. Stop frequency. Example, 1e9, "1GHz".
# - **increment**.

cfg["setups"] = [
{
"name": "siwave_syz",
"type": "siwave_ac",
"pi_slider_position": 1,
"freq_sweep": [
{
"name": "Sweep1",
"type": "interpolation",
"frequencies": [{"distribution": "log_scale", "start": 1e6, "stop": 1e9, "increment": 20}],
}
],
}
]

# ### Define Cutout
# Keywords
# - **signal_list**. List of nets to be kept after cutout.
# - **reference_list**. List of nets as reference planes.
# - **extent_type**. Supported extend types are 'Conforming', 'ConvexHull', 'Bounding'.
# For optional input arguments, refer to method pyedb.Edb.cutout()

cfg["operations"] = {
"cutout": {
"signal_list": ["1V0"],
"reference_list": ["GND"],
"extent_type": "ConvexHull",
}
}

# ## Save the configuration as a JSON file
# The configuration file can be saved in JSON format and applied to layout data using the EDB.

file_json = os.path.join(temp_folder.name, "edb_configuration.json")
with open(file_json, "w") as f:
json.dump(cfg, f, indent=4, ensure_ascii=False)

# ## Load configuration into EDB

# Load configuration file

edbapp.configuration.load(config_file=file_json)

# Apply configuration to EDB.

edbapp.configuration.run()

# Save and close EDB.

edbapp.save()
edbapp.close()

# The configured EDB file is saved in a temp folder.

print(temp_folder.name)

# ## Analyze in HFSS 3D Layout

# ### Load edb into HFSS 3D Layout.

h3d = Hfss3dLayout(edbapp.edbpath, version=AEDT_VERSION, non_graphical=NG_MODE, new_desktop=True)

# ### Analyze

h3d.analyze()

# ### Plot impedance

solutions = h3d.post.get_solution_data(expressions="Z(port1,port1)")
solutions.plot()

# ## Shut Down Electronics Desktop

h3d.close_desktop()

# All project files are saved in the folder ``temp_file.dir``. If you've run this example as a Jupyter notbook you
# can retrieve those project files. The following cell removes all temporary files, including the project folder.

# ## Cleanup
#
# All project files are saved in the folder ``temp_file.dir``. If you've run this example as a Jupyter notbook you
# can retrieve those project files. The following cell removes all temporary files, including the project folder.

temp_folder.cleanup()
Loading