Download this example
Download this example as a Jupyter Notebook or as a Python script.
Import Ports#
This example shows how to import ports. In this example, we are going to
Download an example board
Create a configuration file
Add a circuit port between two nets
Add a circuit port between two pins
Add a circuit port between two pin groups
Add a circuit port between two coordinates
Add a coax port
Add a port reference to the nearest pin
Add distributed ports
Import the configuration file
Perform imports and define constants#
Perform required imports.
[1]:
import json
import tempfile
import time
from pathlib import Path
import toml
from ansys.aedt.core.examples.downloads import download_file
from pyedb import Edb
Define constants.
[2]:
AEDT_VERSION = "2026.1"
NG_MODE = False
Download the example PCB data.
[3]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
file_edb = download_file(source="pyaedt/edb/ANSYS-HSD_V1.aedb", local_path=temp_folder.name)
Load example layout#
[4]:
edbapp = Edb(edbpath=file_edb, version=AEDT_VERSION)
C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\pyedb\generic\design_types.py:375: UserWarning: You are using PyEDB with grpc, which is currently in beta. Some feature might be missing or not working as expected. Please report any issue you find to the PyEDB team.
warnings.warn(GRPC_BETA_WARNING, UserWarning)
PyEDB INFO: Logger is initialized in EDB.
PyEDB INFO: legacy v0.75.0
PyEDB INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyEDB INFO: Using PyEDB with gRPC as Beta until ANSYS 2027R1 official release.
PyEDB INFO: Logger is initialized in EDB.
PyEDB INFO: legacy v0.75.0
PyEDB INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyEDB INFO: Grpc session started
PyEDB INFO: Grpc session started: pid=6652
PyEDB INFO: RPC session acquired (open databases: 1)
PyEDB INFO: Database ANSYS-HSD_V1.aedb Opened in 2026.1
PyEDB INFO: Cell main Opened
PyEDB INFO: Refreshing the Components dictionary.
PyEDB INFO: Builder was initialized.
PyEDB INFO: EDB initialized.
Create an empty dictionary to host all configurations#
[5]:
cfg = dict()
Add a circuit port between two nets#
Keywords
name. Name of the port.
Reference_designator. Reference designator of the component.
type. Type of the port. Supported types are ‘circuit’, ‘coax’, ‘gap_port’, ‘wave_port’, ‘diff_wave_port’.
impedance. Impedance of the port. Default is 50 Ohm.
positive_terminal. Positive terminal of the port. Supported types are ‘net’, ‘pin’, ‘pin_group’, ‘coordinates’.
negative_terminal. Negative terminal of the port. Supported types are ‘net’, ‘pin’, ‘pin_group’, ‘coordinates’, ‘nearest_pin’.
[6]:
port_1 = {
"name": "port_1",
"reference_designator": "X1",
"type": "circuit",
"positive_terminal": {"net": "PCIe_Gen4_TX2_N"},
"negative_terminal": {"net": "GND"},
}
Add a circuit port between two pins#
[7]:
port_2 = {
"name": "port_2",
"reference_designator": "C375",
"type": "circuit",
"positive_terminal": {"pin": "1"},
"negative_terminal": {"pin": "2"},
}
Add a circuit port between two pin groups#
[8]:
pin_groups = [
{"name": "U9_5V_1", "reference_designator": "U9", "pins": ["32", "33"]},
{"name": "U9_GND", "reference_designator": "U9", "net": "GND"},
]
[9]:
port_3 = {
"name": "port_3",
"type": "circuit",
"positive_terminal": {"pin_group": "U9_5V_1"},
"negative_terminal": {"pin_group": "U9_GND"},
}
Add a circuit port between two coordinates#
Keywords
layer. Layer on which the terminal is placed
point. XY coordinate the terminal is placed
net. Name of the net the terminal is placed on
[10]:
port_4 = {
"name": "port_4",
"type": "circuit",
"positive_terminal": {"coordinates": {"layer": "1_Top", "point": ["104mm", "37mm"], "net": "AVCC_1V3"}},
"negative_terminal": {"coordinates": {"layer": "Inner6(GND2)", "point": ["104mm", "37mm"], "net": "GND"}},
}
Add a coax port#
[11]:
port_5 = {"name": "port_5", "reference_designator": "U1", "type": "coax", "positive_terminal": {"pin": "AM17"}}
Add a port reference to the nearest pin#
Keywords
reference_net. Name of the reference net
search_radius. Reference pin search radius in meter
[12]:
port_6 = {
"name": "port_6",
"reference_designator": "U15",
"type": "circuit",
"positive_terminal": {"pin": "D7"},
"negative_terminal": {"nearest_pin": {"reference_net": "GND", "search_radius": 5e-3}},
}
Add distributed ports#
Keywords
distributed. Whether to create distributed ports. When set to True, ports are created per pin
[13]:
ports_distributed = {
"name": "ports_d",
"reference_designator": "U7",
"type": "circuit",
"distributed": True,
"positive_terminal": {"net": "VDD_DDR"},
"negative_terminal": {"net": "GND"},
}
Add setups in configuration#
[14]:
cfg["pin_groups"] = pin_groups
cfg["ports"] = [port_1, port_2, port_3, port_4, port_5, port_6, ports_distributed]
Write configuration into as json file#
[15]:
file_json = Path(temp_folder.name) / "edb_configuration.json"
with open(file_json, "w") as f:
json.dump(cfg, f, indent=4, ensure_ascii=False)
Equivalent toml file looks like below
[16]:
toml_string = toml.dumps(cfg)
print(toml_string)
[[pin_groups]]
name = "U9_5V_1"
reference_designator = "U9"
pins = [ "32", "33",]
[[pin_groups]]
name = "U9_GND"
reference_designator = "U9"
net = "GND"
[[ports]]
name = "port_1"
reference_designator = "X1"
type = "circuit"
[ports.positive_terminal]
net = "PCIe_Gen4_TX2_N"
[ports.negative_terminal]
net = "GND"
[[ports]]
name = "port_2"
reference_designator = "C375"
type = "circuit"
[ports.positive_terminal]
pin = "1"
[ports.negative_terminal]
pin = "2"
[[ports]]
name = "port_3"
type = "circuit"
[ports.positive_terminal]
pin_group = "U9_5V_1"
[ports.negative_terminal]
pin_group = "U9_GND"
[[ports]]
name = "port_4"
type = "circuit"
[ports.positive_terminal.coordinates]
layer = "1_Top"
point = [ "104mm", "37mm",]
net = "AVCC_1V3"
[ports.negative_terminal.coordinates]
layer = "Inner6(GND2)"
point = [ "104mm", "37mm",]
net = "GND"
[[ports]]
name = "port_5"
reference_designator = "U1"
type = "coax"
[ports.positive_terminal]
pin = "AM17"
[[ports]]
name = "port_6"
reference_designator = "U15"
type = "circuit"
[ports.positive_terminal]
pin = "D7"
[ports.negative_terminal.nearest_pin]
reference_net = "GND"
search_radius = 0.005
[[ports]]
name = "ports_d"
reference_designator = "U7"
type = "circuit"
distributed = true
[ports.positive_terminal]
net = "VDD_DDR"
[ports.negative_terminal]
net = "GND"
Import configuration into example layout#
[17]:
edbapp.configuration.load(config_file=file_json)
edbapp.configuration.run()
PyEDB INFO: Updating nets finished. Time lapse 0:00:00
PyEDB INFO: Updating components finished. Time lapse 0:00:00
PyEDB INFO: Creating pin groups finished. Time lapse 0:00:00.159239
PyEDB INFO: Placing sources finished. Time lapse 0:00:00
PyEDB INFO: Applying materials finished. Time lapse 0:00:00
C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\pyedb\configuration\cfg_pin_groups.py:71: FutureWarning: Call to deprecated function create_pin_group. use edb.components.create_pin_group method instead
self._pedb.siwave.create_pin_group(self.reference_designator, pins, self.name)
C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\pyedb\configuration\cfg_pin_groups.py:76: FutureWarning: Call to deprecated function create_pin_group. use edb.components.create_pin_group method instead
if not self._pedb.siwave.create_pin_group(self.reference_designator, pins, self.name):
PyEDB INFO: Applying padstack definitions and instances completed in 0.1592 seconds.
PyEDB INFO: Applying S-parameters finished. Time lapse 0:00:00
PyEDB INFO: Applying package definitions finished. Time lapse 0:00:00
PyEDB INFO: Applying modeler finished. Time lapse 0:00:00
C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\pyedb\configuration\cfg_ports_sources.py:564: FutureWarning: Call to deprecated function create_pin_group. use edb.components.create_pin_group method instead
name, temp = self._pedb.siwave.create_pin_group(reference_designator, pin_names, pg_name)
PyEDB INFO: Placing ports finished. Time lapse 0:00:04.156289
PyEDB INFO: Placing terminals completed in 0.0000 seconds.
PyEDB INFO: Placing probes finished. Time lapse 0:00:00
PyEDB INFO: Applying operations completed in 0.0000 seconds.
PyEDB INFO: Applying setups completed in 0.0000 seconds.
[17]:
True
Review#
[18]:
edbapp.ports
[18]:
{'port_1': <pyedb.grpc.database.ports.ports.GapPort at 0x161b245c100>,
'port_2': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c53f9420>,
'port_3': <pyedb.grpc.database.ports.ports.GapPort at 0x161c53fa9e0>,
'port_4': <pyedb.grpc.database.ports.ports.GapPort at 0x161c53f8dc0>,
'port_5': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161b245e860>,
'port_6': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c2818d60>,
'U7_VDD_DDR_T9': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c2818e80>,
'U7_VDD_DDR_R1': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c3d3b610>,
'U7_VDD_DDR_L9': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c4e35390>,
'U7_VDD_DDR_L1': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c28188b0>,
'U7_VDD_DDR_J9': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c2818f40>,
'U7_VDD_DDR_J8': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f49ba0>,
'U7_VDD_DDR_J2': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f4a5f0>,
'U7_VDD_DDR_J1': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f48d60>,
'U7_VDD_DDR_G9': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f49030>,
'U7_VDD_DDR_G7': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f4a7a0>,
'U7_VDD_DDR_G1': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f49cf0>,
'U7_VDD_DDR_F8': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f486d0>,
'U7_VDD_DDR_F2': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f4a410>,
'U7_VDD_DDR_D9': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f4b6d0>,
'U7_VDD_DDR_D1': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f49b40>,
'U7_VDD_DDR_C1': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f4ba90>,
'U7_VDD_DDR_B9': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f49ed0>,
'U7_VDD_DDR_B3': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f48100>,
'U7_VDD_DDR_A9': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f4a650>,
'U7_VDD_DDR_A1': <pyedb.grpc.database.ports.ports.CoaxPort at 0x161c6f484f0>}
Save and close Edb#
The temporary folder will be deleted once the execution of this script is finished. Replace edbapp.save() with edbapp.save_as(“C:/example.aedb”) to keep the example project.
[19]:
edbapp.save()
edbapp.close()
PyEDB INFO: RPC session released (open databases: 0)
[19]:
True
[20]:
# Wait 3 seconds before cleaning the temporary directory.
time.sleep(3)
Clean up#
All project files are saved in the folder temp_folder.name. If you’ve run this example as a Jupyter notebook, you can retrieve those project files. The following cell removes all temporary files, including the project folder.
[21]:
temp_folder.cleanup()
Download this example
Download this example as a Jupyter Notebook or as a Python script.