Download this example

Download this example as a Jupyter Notebook or as a Python script.


Import Sources#

This example shows how to import voltage and current sources. In this example, we are going to

  • Download an example board

  • Create a configuration file

    • Add a voltage source between two nets

    • Add a current source between two pins

    • Add a current source between two pin groups

    • Add a current source between two coordinates

    • Add a current source to the nearest pin

    • Add distributed sources

  • 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=8124
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 voltage source between two nets#

Keywords

  • name. Name of the voltage source.

  • Reference_designator. Reference designator of the component.

  • type. Type of the source. Supported types are ‘voltage’, ‘current’

  • impedance. Impedance of the port. Default is 5e7 Ohm for current sources, 1e-6 Ohm for voltage sources.

  • positive_terminal. Supported types are ‘net’, ‘pin’, ‘pin_group’, ‘coordinates’

    • contact_radius. Optional. Set circular equipotential region.

    • inline. Optional. When True, contact points are placed in a row.

    • num_of_contact. Optional. Number of contact points. Default is 1. Applicable only when inline is True.

  • negative_terminal. Supported types are ‘net’, ‘pin’, ‘pin_group’, ‘coordinates’

  • equipotential. Set equipotential region on pins when True.

[6]:
voltage_source = {
    "name": "V_SOURCE_5V",
    "reference_designator": "U4",
    "type": "voltage",
    "magnitude": 1,
    "positive_terminal": {"net": "5V", "contact_radius": "1mm"},
    "negative_terminal": {"net": "GND", "contact_radius": "1mm"},
    "equipotential": True,
}

Add a current source between two pins#

[7]:
current_source_1 = {
    "name": "I_CURRENT_1A",
    "reference_designator": "J5",
    "type": "current",
    "magnitude": 10,
    "positive_terminal": {"pin": "15"},
    "negative_terminal": {"pin": "14"},
}

Add a current source between two pin groups#

[8]:
pin_groups = [
    {"name": "IC2_5V", "reference_designator": "IC2", "pins": ["8"]},
    {"name": "IC2_GND", "reference_designator": "IC2", "net": "GND"},
]
[9]:
current_source_2 = {
    "name": "CURRENT_SOURCE_2",
    "type": "current",
    "positive_terminal": {"pin_group": "IC2_5V"},
    "negative_terminal": {"pin_group": "IC2_GND"},
}

Add a current source 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]:
current_source_3 = {
    "name": "CURRENT_SOURCE_3",
    "type": "current",
    "equipotential": True,
    "positive_terminal": {"coordinates": {"layer": "1_Top", "point": ["116mm", "41mm"], "net": "5V"}},
    "negative_terminal": {"coordinates": {"layer": "Inner1(GND1)", "point": ["116mm", "41mm"], "net": "GND"}},
}

Add a current source reference to the nearest pin#

Keywords

  • reference_net. Name of the reference net

  • search_radius. Reference pin search radius in meter

[11]:
current_source_4 = {
    "name": "CURRENT_SOURCE_4",
    "reference_designator": "J5",
    "type": "current",
    "positive_terminal": {"pin": "16"},
    "negative_terminal": {"nearest_pin": {"reference_net": "GND", "search_radius": 5e-3}},
}

Add distributed current sources#

Keywords

  • distributed. Whether to create distributed sources. When set to True, ports are created per pin

[12]:
sources_distributed = {
    "name": "DISTRIBUTED",
    "reference_designator": "U2",
    "type": "current",
    "distributed": True,
    "positive_terminal": {"net": "5V"},
    "negative_terminal": {"net": "GND"},
}

Add setups in configuration#

[13]:
cfg["pin_groups"] = pin_groups
cfg["sources"] = [
    voltage_source,
    current_source_1,
    current_source_2,
    current_source_3,
    current_source_4,
    sources_distributed,
]

Write configuration into as JSON file#

[14]:
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

[15]:
toml_string = toml.dumps(cfg)
print(toml_string)
[[pin_groups]]
name = "IC2_5V"
reference_designator = "IC2"
pins = [ "8",]

[[pin_groups]]
name = "IC2_GND"
reference_designator = "IC2"
net = "GND"

[[sources]]
name = "V_SOURCE_5V"
reference_designator = "U4"
type = "voltage"
magnitude = 1
equipotential = true

[sources.positive_terminal]
net = "5V"
contact_radius = "1mm"
[sources.negative_terminal]
net = "GND"
contact_radius = "1mm"
[[sources]]
name = "I_CURRENT_1A"
reference_designator = "J5"
type = "current"
magnitude = 10

[sources.positive_terminal]
pin = "15"
[sources.negative_terminal]
pin = "14"
[[sources]]
name = "CURRENT_SOURCE_2"
type = "current"

[sources.positive_terminal]
pin_group = "IC2_5V"
[sources.negative_terminal]
pin_group = "IC2_GND"
[[sources]]
name = "CURRENT_SOURCE_3"
type = "current"
equipotential = true

[sources.positive_terminal.coordinates]
layer = "1_Top"
point = [ "116mm", "41mm",]
net = "5V"
[sources.negative_terminal.coordinates]
layer = "Inner1(GND1)"
point = [ "116mm", "41mm",]
net = "GND"
[[sources]]
name = "CURRENT_SOURCE_4"
reference_designator = "J5"
type = "current"

[sources.positive_terminal]
pin = "16"
[sources.negative_terminal.nearest_pin]
reference_net = "GND"
search_radius = 0.005
[[sources]]
name = "DISTRIBUTED"
reference_designator = "U2"
type = "current"
distributed = true

[sources.positive_terminal]
net = "5V"
[sources.negative_terminal]
net = "GND"

Import configuration into example layout#

[16]:
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.047508
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):
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 sources finished. Time lapse 0:00:01.324917
PyEDB INFO: Applying materials finished. Time lapse 0:00:00
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
PyEDB INFO: Placing ports finished. Time lapse 0:00:00
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.
[16]:
True

Review#

[17]:
print(edbapp.siwave.sources)
{'V_SOURCE_5V': <pyedb.grpc.database.terminal.pingroup_terminal.PinGroupTerminal object at 0x000002BEDFBAB370>, 'I_CURRENT_1A': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEDFBAA650>, 'CURRENT_SOURCE_2': <pyedb.grpc.database.terminal.pingroup_terminal.PinGroupTerminal object at 0x000002BEF2AB4B50>, 'CURRENT_SOURCE_3': <pyedb.grpc.database.terminal.point_terminal.PointTerminal object at 0x000002BEF2AB5810>, 'CURRENT_SOURCE_4': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB5750>, 'U2_5V_39': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB56C0>, 'U2_5V_40': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB5510>, 'U2_5V_41': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB4B20>, 'U2_5V_42': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB50C0>, 'U2_5V_43': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB60B0>, 'U2_5V_44': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB60E0>, 'U2_5V_45': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB6140>, 'U2_5V_46': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB61A0>, 'U2_5V_47': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB6200>, 'U2_5V_48': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB6260>, 'U2_5V_49': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB62C0>, 'U2_5V_50': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB6320>, 'U2_5V_51': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB6380>, 'U2_5V_60': <pyedb.grpc.database.terminal.padstack_instance_terminal.PadstackInstanceTerminal object at 0x000002BEF2AB63E0>}

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.

[18]:
edbapp.save()
edbapp.close()
PyEDB INFO: RPC session released (open databases: 0)
[18]:
True
[19]:
# 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.

[20]:
temp_folder.cleanup()

Download this example

Download this example as a Jupyter Notebook or as a Python script.