Clip layout ruby to python conversion

Hello, the following ruby script is doing exactly what I want. (It takes two layouts as inputs and merge them in a new output layout) However, when I try to replicate the script in python, the outputs are not identical (For example hierarchy is not the same and there are some undesired extra polygons). Could anyone see what's the mistake?

Thanks in advance!

Ruby script:

# Read the first layout

file1 = 'input_layout1.oas'
file2 = 'input_layout2.oas'
output = 'merged_layout.oas'



layout = RBA::Layout.new
lmap = layout.read(file1)

# store and take away the cell names of all cells read so far
# (by setting the cell name to "" the cells basically become invisible for
# the following read)
cell_names = { }
#puts layout.cells
(0..(layout.cells-1)).each do |ci|
  cell_names[ci] = layout.cell_name(ci)


  layout.rename_cell(ci, "") # this prevents a name clash on the next read
end
# read the second file which basically performs the merge
load_layout_options = RBA::LoadLayoutOptions.new
load_layout_options.set_layer_map(lmap, true)
layout.read(file2, load_layout_options)

# rename the cells by using prefix "A" for layout 1 and "B" for layout 2

(0..(layout.cells-1)).each do |ci|
  if cell_names[ci]
    layout.rename_cell(ci, "A" + cell_names[ci])
  else

    layout.rename_cell(ci, "B" + layout.cell_name(ci))
  end
end

layout.write(output)

Python equivalent:

import pya

layout1_path = r'input_layout1.oas'
layout2_path = r'input_layout2.oas'
merged_path = r'merged_layout.oas'

layout = pya.Layout.new()
lmap = layout.read(layout1_path)


cell_names = { }
for cell in layout.each_cell():
    ci = cell.cell_index()
    cell_names[ci] = layout.cell_name(ci)


load_layout_options = load_layout_options = pya.LoadLayoutOptions()
load_layout_options.set_layer_map(lmap, True)
layout.read(layout2_path, load_layout_options)

for cell in layout.each_cell():
    ci = cell.cell_index()
    try:
        layout.rename_cell(ci, "A" + cell_names[ci])
    except:

        layout.rename_cell(ci, "B" + layout.cell_name(ci))
        layout.cell_name(ci)
        print(ci, 'else', layout.cell_name(ci))

layout.write(merged_path)

Comments

  • Hi,

    I think this line has not been translated:

    layout.rename_cell(ci, "") # this prevents a name clash on the next read
    

    and Python's. "try ... except .." in the second loop isn't the same as "if ... else ..." in Ruby.

    Matthias

Sign In or Register to comment.