Skip to content

Commit 319759e

Browse files
authored
REFACTOR: Pyedb examples merge (#304)
1 parent 0a09d15 commit 319759e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3464
-41
lines changed

doc/source/conf.py

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
from sphinx.builders.latex import LaTeXBuilder
2727
from sphinx.util import logging
2828

29+
os.environ["PYAEDT_NON_GRAPHICAL"] = "1"
30+
os.environ["PYAEDT_DOC_GENERATION"] = "1"
31+
2932
LaTeXBuilder.supported_image_types = ["image/png", "image/pdf", "image/svg+xml"]
3033

3134
logger = logging.getLogger(__name__)
@@ -260,6 +263,7 @@ def convert_examples_into_notebooks(app):
260263
"interference_type.py",
261264
"interference.py",
262265
"hfss_emit.py",
266+
"component_conversion.py",
263267
)
264268

265269
# NOTE: Only convert the examples if the workflow isn't tagged as coupling HTML and PDF build.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# # EDB: Edit Control File and import gds
2+
#
3+
# This example demonstrates how to import a gds layout for subsequent
4+
# simulation with HFSS.
5+
6+
# Perform imports.
7+
8+
# +
9+
import os
10+
import shutil
11+
import tempfile
12+
13+
import pyedb
14+
from pyedb.dotnet.edb_core.edb_data.control_file import ControlFile
15+
from pyedb.misc.downloads import download_file
16+
17+
# -
18+
19+
# ## Fetch Example Data
20+
#
21+
# Download the EDB folder and copy it to a temporary folder.
22+
# The following files are used in this example:
23+
#
24+
# - _sky130_fictious_dtc_exmple_contol_no_map.xml_
25+
# defines physical information such
26+
# as material properties, stackup layers, and boundary conditions.
27+
# - _dummy_layermap.map_
28+
# maps properties to stackup layers.
29+
30+
# +
31+
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
32+
control_fn = "sky130_fictitious_dtc_example_control_no_map.xml"
33+
gds_fn = "sky130_fictitious_dtc_example.gds"
34+
layer_map = "dummy_layermap.map"
35+
36+
local_path = download_file("gds", destination=temp_dir.name)
37+
c_file_in = os.path.join(local_path, control_fn)
38+
c_map = os.path.join(local_path, layer_map)
39+
gds_in = os.path.join(local_path, gds_fn)
40+
gds_out = os.path.join(temp_dir.name, "gds_out.gds")
41+
shutil.copy2(gds_in, gds_out)
42+
# -
43+
44+
# ## Control file
45+
#
46+
# A Control file is an xml file which purpose if to provide additional information during
47+
# import phase. It can include, materials, stackup, setup, boundaries and settings.
48+
# In this example we will import an existing xml, integrate it with a layer mapping file of gds
49+
# and then adding setup and boundaries.
50+
51+
c = ControlFile(c_file_in, layer_map=c_map)
52+
53+
# ## Set up simulation
54+
#
55+
# This code sets up a simulation with HFSS and adds a frequency sweep.
56+
57+
setup = c.setups.add_setup("Setup1", "1GHz", 0.02, 10)
58+
setup.add_sweep("Sweep1", "0.01GHz", "5GHz", "0.1GHz")
59+
60+
# ## Provide additional stackup settings
61+
#
62+
# After import, you can change the stackup settings and add or remove layers or materials.
63+
64+
c.stackup.units = "um"
65+
c.stackup.dielectrics_base_elevation = -100
66+
c.stackup.metal_layer_snapping_tolerance = "10nm"
67+
for via in c.stackup.vias:
68+
via.create_via_group = True
69+
via.snap_via_group = True
70+
71+
# ## Define boundary settings
72+
#
73+
# Boundaries can include ports, components and boundary extent.
74+
75+
c.boundaries.units = "um"
76+
c.boundaries.add_port("P1", x1=223.7, y1=222.6, layer1="Metal6", x2=223.7, y2=100, layer2="Metal6")
77+
c.boundaries.add_extent()
78+
comp = c.components.add_component("B1", "BGA", "IC", "Flip chip", "Cylinder")
79+
comp.solder_diameter = "65um"
80+
comp.add_pin("1", "81.28", "84.6", "met2")
81+
comp.add_pin("2", "211.28", "84.6", "met2")
82+
comp.add_pin("3", "211.28", "214.6", "met2")
83+
comp.add_pin("4", "81.28", "214.6", "met2")
84+
c.import_options.import_dummy_nets = True
85+
86+
# ## Write XML file
87+
#
88+
# After all settings are ready, you can write an XML file.
89+
90+
c.write_xml(os.path.join(temp_dir.name, "output.xml"))
91+
92+
# ## Open EDB
93+
#
94+
# Import the gds and open the edb.
95+
96+
# +
97+
# Select EDB version (change it manually if needed, e.g. "2024.2")
98+
edb_version = "2024.2"
99+
print(f"EDB version: {edb_version}")
100+
101+
edb = pyedb.Edb(gds_out, edbversion=edb_version, technology_file=os.path.join(temp_dir.name, "output.xml"))
102+
# -
103+
104+
# ## Plot stackup
105+
#
106+
# Plot the stackup.
107+
108+
edb.stackup.plot(first_layer="met1")
109+
110+
# ## Close EDB
111+
#
112+
# Close the project.
113+
114+
edb.close_edb()
115+
116+
# Clean up the temporary folder.
117+
118+
temp_dir.cleanup()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# # EDB: plot nets with Matplotlib
2+
#
3+
# This example shows how to use the ``Edb`` class to view nets, layers and
4+
# via geometry directly in Python. The methods demonstrated in this example
5+
# rely on
6+
# [matplotlib](https://matplotlib.org/cheatsheets/_images/cheatsheets-1.png).
7+
8+
# ## Perform required imports
9+
#
10+
# Perform required imports, which includes importing a section.
11+
12+
# +
13+
import tempfile
14+
15+
import pyedb
16+
from pyedb.misc.downloads import download_file
17+
18+
# -
19+
20+
# ## Download the EDB and copy it into the temporary folder.
21+
22+
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
23+
targetfolder = download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)
24+
25+
# ## Create an instance of the Electronics Database using the `pyedb.Edb` class.
26+
#
27+
# > Note that units are SI.
28+
29+
# +
30+
# Select EDB version (change it manually if needed, e.g. "2024.2")
31+
edb_version = "2024.2"
32+
print(f"EDB version: {edb_version}")
33+
34+
edb = pyedb.Edb(edbpath=targetfolder, edbversion=edb_version)
35+
# -
36+
37+
# Display the nets on a layer. You can display the net geometry directly in Python using
38+
# ``matplotlib`` from the ``pyedb.Edb`` class.
39+
40+
edb.nets.plot("AVCC_1V3")
41+
42+
# You can view multiple nets by passing a list containing the net
43+
# names to the ``plot()`` method.
44+
45+
edb.nets.plot(["GND", "GND_DP", "AVCC_1V3"], color_by_net=True)
46+
47+
# You can display all copper on a single layer by passing ``None``
48+
# as the first argument. The second argument is a list
49+
# of layers to plot. In this case, only one
50+
# layer is to be displayed.
51+
52+
edb.nets.plot(None, ["1_Top"], color_by_net=True, plot_components_on_top=True)
53+
54+
# Display a side view of the layers and padstack geometry using the
55+
# ``Edb.stackup.plot()`` method.
56+
57+
edb.stackup.plot(scale_elevation=False, plot_definitions=["c100hn140", "c35"])
58+
59+
# ## Creating coaxial port on component U1 and all ddr4_dqs nets
60+
# Selecting all nets from ddr4_dqs and component U1 and create coaxial ports
61+
# On corresponding pins.
62+
63+
comp_u1 = edb.components.instances["U1"]
64+
signal_nets = [net for net in comp_u1.nets if "ddr4_dqs" in net.lower()]
65+
edb.hfss.create_coax_port_on_component("U1", net_list=signal_nets)
66+
edb.components.set_solder_ball(component="U1", sball_diam="0.3mm", sball_height="0.3mm")
67+
68+
# ## Renaming all ports
69+
# Renaming all port with _renamed string as suffix example.
70+
71+
for port_name, port in edb.ports.items():
72+
port.name = f"{port_name}_renamed"
73+
74+
75+
# Close the EDB.
76+
77+
edb.close_edb()
78+
79+
# Remove all files and the temporary directory.
80+
81+
temp_dir.cleanup()
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# # EDB: geometry creation
2+
3+
# This example shows how you can use EDB to create a layout.
4+
# ## Final expected project
5+
#
6+
# <img src="_static/diff_via.png" width="500">
7+
#
8+
# ## Import EDB layout object
9+
# Import the EDB layout object and initialize it on version 2023 R2.
10+
11+
# +
12+
import os
13+
import tempfile
14+
15+
import pyedb
16+
17+
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
18+
aedb_path = os.path.join(temp_dir.name, "create_via.aedb")
19+
print(f"AEDB file path: {aedb_path}")
20+
21+
# Select EDB version (change it manually if needed, e.g. "2024.2")
22+
edb_version = "2024.2"
23+
print(f"EDB version: {edb_version}")
24+
25+
edb = pyedb.Edb(edbpath=aedb_path, edbversion=edb_version)
26+
# -
27+
28+
# ## Add stackup layers
29+
# Add stackup layers.
30+
# A stackup can be created layer by layer or imported from a CSV file or XML file.
31+
32+
edb.stackup.add_layer("GND")
33+
edb.stackup.add_layer("Diel", "GND", layer_type="dielectric", thickness="0.1mm", material="FR4_epoxy")
34+
edb.stackup.add_layer("TOP", "Diel", thickness="0.05mm")
35+
36+
# ## Create signal net and ground planes
37+
# Create a signal net and ground planes.
38+
39+
points = [[0.0, 0], [100e-3, 0.0]]
40+
edb.modeler.create_trace(points, "TOP", width=1e-3)
41+
points = [[0.0, 1e-3], [0.0, 10e-3], [100e-3, 10e-3], [100e-3, 1e-3], [0.0, 1e-3]]
42+
edb.modeler.create_polygon(points, "TOP")
43+
points = [[0.0, -1e-3], [0.0, -10e-3], [100e-3, -10e-3], [100e-3, -1e-3], [0.0, -1e-3]]
44+
edb.modeler.create_polygon(points, "TOP")
45+
46+
47+
# ## Create vias with parametric positions
48+
# Create vias with parametric positions.
49+
50+
edb.padstacks.create("MyVia")
51+
edb.padstacks.place([5e-3, 5e-3], "MyVia")
52+
edb.padstacks.place([15e-3, 5e-3], "MyVia")
53+
edb.padstacks.place([35e-3, 5e-3], "MyVia")
54+
edb.padstacks.place([45e-3, 5e-3], "MyVia")
55+
edb.padstacks.place([5e-3, -5e-3], "MyVia")
56+
edb.padstacks.place([15e-3, -5e-3], "MyVia")
57+
edb.padstacks.place([35e-3, -5e-3], "MyVia")
58+
edb.padstacks.place([45e-3, -5e-3], "MyVia")
59+
60+
61+
# ## Generate geometry plot
62+
63+
edb.nets.plot(None, color_by_net=True)
64+
65+
# ## Generate stackup plot
66+
67+
edb.stackup.plot(plot_definitions="MyVia")
68+
69+
# ## Save and close EDB
70+
# Save and close EDB.
71+
72+
if edb:
73+
edb.save_edb()
74+
edb.close_edb()
75+
print("EDB saved correctly to {}. You can import in AEDT.".format(aedb_path))
76+
77+
# ### Clean up temporary directory
78+
#
79+
# The following command removes the project and the temporary directory.
80+
# If you'd like to save this project, save it to a folder of your choice
81+
# prior to running the following cell.
82+
83+
temp_dir.cleanup()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# # EDB: IPC2581 export
2+
#
3+
# This example shows how you can use PyAEDT to export an IPC2581 file.
4+
#
5+
# Perform required imports, which includes importing a section.
6+
7+
# +
8+
import os
9+
import tempfile
10+
11+
import pyedb
12+
from pyedb.generic.general_methods import generate_unique_name
13+
from pyedb.misc.downloads import download_file
14+
15+
# -
16+
17+
# ## Download the AEDB file and copy it in the temporary folder.
18+
19+
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
20+
targetfile = download_file("edb/ANSYS-HSD_V1.aedb", destination=temp_dir.name)
21+
ipc2581_file_name = os.path.join(temp_dir.name, "Ansys_Hsd.xml")
22+
print(targetfile)
23+
24+
# ## Launch EDB
25+
#
26+
# Launch the `pyedb.Edb` class, using EDB 2023.
27+
# > Note that length dimensions passed to EDB are in SI units.
28+
29+
# +
30+
# Select EDB version (change it manually if needed, e.g. "2024.2")
31+
edb_version = "2024.2"
32+
print(f"EDB version: {edb_version}")
33+
34+
edb = pyedb.Edb(edbpath=targetfile, edbversion=edb_version)
35+
# -
36+
37+
# ## Parametrize the width of a trace.
38+
39+
edb.modeler.parametrize_trace_width("A0_N", parameter_name=generate_unique_name("Par"), variable_value="0.4321mm")
40+
41+
# ## Create a cutout and plot it.
42+
43+
signal_list = []
44+
for net in edb.nets.netlist:
45+
if "PCIe" in net:
46+
signal_list.append(net)
47+
power_list = ["GND"]
48+
edb.cutout(
49+
signal_list=signal_list,
50+
reference_list=power_list,
51+
extent_type="ConvexHull",
52+
expansion_size=0.002,
53+
use_round_corner=False,
54+
number_of_threads=4,
55+
remove_single_pin_components=True,
56+
use_pyaedt_extent_computing=True,
57+
extent_defeature=0,
58+
)
59+
edb.nets.plot(None, None, color_by_net=True)
60+
61+
# ## Export the EDB to an IPC2581 file.
62+
63+
edb.export_to_ipc2581(ipc2581_file_name, "inch")
64+
print("IPC2581 File has been saved to {}".format(ipc2581_file_name))
65+
66+
# ## Close EDB
67+
68+
edb.close_edb()
69+
70+
# ## Clean up the temporary directory
71+
72+
temp_dir.cleanup()

0 commit comments

Comments
 (0)