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

DOC: adding temporary removed EDB examples #9

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 doc/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ goto end

:html
%SPHINXBUILD% -M html %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% -v %O%
goto end

:pdf
%SPHINXBUILD% -M latex %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
Expand Down
7 changes: 6 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ def check_example_error(app, pagename, templatename, context, doctree):
"""
# Check if the HTML contains an error message
if pagename.startswith("examples") and not pagename.endswith("/index"):
if any(map(lambda msg: msg in context["body"], ["UsageError", "NameError"])):
if any(
map(
lambda msg: msg in context["body"],
["UsageError", "NameError", "DeadKernelError", "NotebookError"],
)
):
logger.error(f"An error was detected in file {pagename}")
app.builder.config.html_context["build_error"] = True

Expand Down
207 changes: 207 additions & 0 deletions examples/00-EDB/01_edb_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# # EDB: SIwave DC-IR Analysis
#
# This example demonstrates the use of EDB to interact with a PCB
# layout and run DC-IR analysis in SIwave.
# Perform required imports

# +
import os
import tempfile
import time

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

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
targetfile = pyaedt.downloads.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)
aedt_file = targetfile[:-4] + "aedt"
# -

# ## Launch Ansys Electronics Database (EDB)
#
# Instantiate an instance of the `pyaedt.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")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

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

# ## Identify nets and components
#
# The ``Edb.nets.netlist`` and ``Edb.components.components`` properties contain information
# about all of the nets and components. The following cell uses this information to print the
# number of nets and components.

print("Nets {}".format(len(edb.nets.netlist)))
start = time.time()
print("Components {}".format(len(edb.components.components.keys())))
print("elapsed time = ", time.time() - start)

# ## Identify pin positions
#
# This code shows how to obtain all pins for a specific component and
# print the ``[x, y]`` position of each pin.

pins = edb.components["U2"].pins
count = 0
for pin in edb.components["U2"].pins.values():
if count < 10: # Only print the first 10 pin coordinates.
print(pin.position)
elif count == 10:
print("...and many more.")
else:
pass
count += 1

# Get all nets connected to a specific component. Print
# the pin and the name of the net that it is connected to.

connections = edb.components.get_component_net_connection_info("U2")
n_print = 0 # Counter to limit the number of printed lines.
print_max = 15
for m in range(len(connections["pin_name"])):
ref_des = connections["refdes"][m]
pin_name = connections["pin_name"][m]
net_name = connections["net_name"][m]
if net_name != "" and (n_print < print_max):
print('{}, pin {} -> net "{}"'.format(ref_des, pin_name, net_name))
n_print += 1
elif n_print == print_max:
print("...and many more.")
n_print += 1

# Compute rats.

rats = edb.components.get_rats()

# ## Identify connected nets
#
# The ``get_dcconnected_net_list()`` method retrieves a list of
# all DC-connected power nets. Each group of connected nets is returned
# as a [set](https://docs.python.org/3/tutorial/datastructures.html#sets).
# The first argument to the method is the list of ground nets, which are
# not considered in the search for connected nets.

GROUND_NETS = ["GND", "GND_DP"]
dc_connected_net_list = edb.nets.get_dcconnected_net_list(GROUND_NETS)
for pnets in dc_connected_net_list:
print(pnets)

# ## Power Tree
#
# The power tree provides connectivity through all components from the VRM to
# the device.

VRM = "U1"
OUTPUT_NET = "AVCC_1V3"
powertree_df, component_list_columns, net_group = edb.nets.get_powertree(OUTPUT_NET, GROUND_NETS)

# Print some information about the power tree.

print_columns = ["refdes", "pin_name", "component_partname"]
ncol = [component_list_columns.index(c) for c in print_columns]

# This prints the header. Replace "pin_name" with "pin" to
# make the header align with the values.

# +
print("\t".join(print_columns).replace("pin_name", "pin"))

for el in powertree_df:
s = ""
count = 0
for e in el:
if count in ncol:
s += "{}\t".format(e)
count += 1
s.rstrip()
print(s)
# -

# ## Remove unused components
#
# Delete all RLC components that are connected with only one pin.
# The ``Edb.components.delete_single_pin_rlc()`` method
# provides a useful way to
# remove components that are not needed for the simulation.

edb.components.delete_single_pin_rlc()

# You can also remove unused components explicitly by name.

edb.components.delete("C380")

# Nets can also be removed explicitly.

edb.nets.delete("PDEN")

# Print the top and bottom elevation of the stackup obtained using
# the ``Edb.stackup.limits()`` method.

s = 'Top layer name: "{top}", Elevation: {top_el:.2f} '
s += 'mm\nBottom layer name: "{bot}", Elevation: {bot_el:2f} mm'
top, top_el, bot, bot_el = edb.stackup.limits()
print(s.format(top=top, top_el=top_el * 1e3, bot=bot, bot_el=bot_el * 1e3))

# ## Set up for SIwave DCIR analysis
#
# Create a voltage source and then set up a DCIR analysis.

edb.siwave.create_voltage_source_on_net("U1", "AVCC_1V3", "U1", "GND", 1.3, 0, "V1")
edb.siwave.create_current_source_on_net("IC2", "NetD3_2", "IC2", "GND", 1.0, 0, "I1")
setup = edb.siwave.add_siwave_dc_analysis("myDCIR_4")
setup.use_dc_custom_settings = True
setup.set_dc_slider = 0
setup.add_source_terminal_to_ground("V1", 1)

# ## Solve
#
# Save the modifications and run the analysis in SIwave.

edb.save_edb()
edb.nets.plot(None, "1_Top", plot_components_on_top=True)

siw_file = edb.solve_siwave()

# ## Export results
#
# Export all quantities calculated from the DC-IR analysis.
# The following method runs SIwave in batch mode from the command line.
# Results are written to the edb folder.

outputs = edb.export_siwave_dc_results(
siw_file,
setup.name,
)

# Close EDB. After EDB is closed, it can be opened by AEDT.

edb.close_edb()

# ## View Layout in SIwave
#
# The SIwave user interface can be visualized and manipulated
# using the SIwave user interface. This command works on Window OS only.

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

# siwave.export_siwave_report("myDCIR_4", report_file)
# siwave.close_project()
# siwave.quit_application()
# -

# Clean up the temporary files and directory.

temp_dir.cleanup()
73 changes: 73 additions & 0 deletions examples/00-EDB/02_edb_to_ipc2581.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# # EDB: IPC2581 export
#
# This example shows how you can use PyAEDT to export an IPC2581 file.
#
# Perform required imports, which includes importing a section.

# +
import os
import tempfile

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

# -

# ## 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)
ipc2581_file_name = os.path.join(temp_dir.name, "Ansys_Hsd.xml")
print(targetfile)

# ## Launch EDB
#
# Launch the `pyaedt.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")
edb_version = EDB_VERSION
print(f"EDB version: {edb_version}")

edb = pyaedt.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"
)

# ## Create a cutout and plot it.

signal_list = []
for net in edb.nets.netlist:
if "PCIe" in net:
signal_list.append(net)
power_list = ["GND"]
edb.cutout(
signal_list=signal_list,
reference_list=power_list,
extent_type="ConvexHull",
expansion_size=0.002,
use_round_corner=False,
number_of_threads=4,
remove_single_pin_components=True,
use_pyaedt_extent_computing=True,
extent_defeature=0,
)
edb.nets.plot(None, None, color_by_net=True)

# ## Export the EDB to an IPC2581 file.

edb.export_to_ipc2581(ipc2581_file_name, "inch")
print("IPC2581 File has been saved to {}".format(ipc2581_file_name))

# ## Close EDB

edb.close_edb()

# ## Clean up the temporary directory

temp_dir.cleanup()
Loading
Loading