It looks like you're new here. If you want to get involved, click one of these buttons!
Deal all,
I am trying to determine if two cells are consistent using db.LayoutDiff.compare. For me, two cells that have the same patten for the corresponding layer are consistent cells. Here is my code, which compares two cells that I think are the same, but the code determines that the two cells are different. Did I miss something important?
import klayout.db as db
import klayout.lay as lay
def compare_cells():
main_window = lay.Application.instance().main_window()
view = main_window.current_view()
layout = view.active_cellview().layout()
dbu = layout.dbu
cell1_name = "core$1"
cell2_name = "core$2"
cell1 = None
cell2 = None
for cell in layout.each_cell():
if cell.name == cell1_name:
cell1 = cell
if cell.name == cell2_name:
cell2 = cell
if not cell1 or not cell2:
raise ValueError(f"Error: Cannot find cells '{cell1_name}' or '{cell2_name}'")
compare_engine = db.LayoutDiff()
flag = db.LayoutDiff.Verbose
tolerance = int(0.001 / dbu)
is_same = compare_engine.compare(cell1, cell2, flag, tolerance)
print(f"Cells are {'CONSISTENT' if is_same else 'DIFFERENT'}")
compare_cells()
In addition, I have chosen to use Verbose mode, but there is no detailed information output. I think I'm missing some part of the code, could you provide a sample of the Verbose mode output?Any insights or suggestions would be greatly appreciated. Thank you in advance!
Comments
the issues here are:
xor_engine is not defined as LayoutDiff() probably a typo and should be compare_engine
I would like to remove this comment because of the incorrect information
Apologies for the previous errors. I've carefully reviewed and corrected all issues in the code.
@Joel_Even I am not really eager to correct the nonsense that ChatGPT/Copilot/etc produce. Some cheery people tell us that guys like me will no longer be needed in the near future. This means war.
The concept of
LayoutDiff
is explained here: https://www.klayout.de/doc-qt5/code/class_LayoutDiff.html#k_1. This text has been written by a human of blood and flesh, and I'd appreciate if you honor that by donating a few (or more) seconds of brain activity to it. I think it's worth it.And first try what the built-in diff (Tools/Diff tool) says about the two layouts. It's the same engine that is in use. If that feature tells you that the layouts are identical,
LayoutDiff
should do as well.Matthias
Thanks for the advice, now I'm sure where the problem is. The difference between the two cells when using the Diff Tool is "Cell core$1 in A is renamed to core$2 in B". While with the XOR Tool there is no difference between the two cells. Perhaps using XOR would be more suitable in such case.