fill_pattern command: Missing & extra lines

Hi, I'm doing some photonics layout, and need to do "manhattanization" of some of the layers that surround waveguides which have to be on a Manhattan grid. I do it with a KLayout Ruby script with the fill_pattern command, but I am seeing horizontal partial missing & extra rows. Here's a self-contained script and its output on one of the layers.

Can you please advise if I need to make a code change, or if somehow the command I'm using doesn't match what I'm trying to do? I'm doing the command on a top cell which does contain hierarchy.

# Read about DRC scripts in the User Manual in "Design Rule Check (DRC)"
cv = RBA::CellView::active
layout = cv.layout
file_in = cv.filename
file_out = file_in
file_out["."] = "_manhattanized."
cell_in = cv.cell_name
cell_out = cell_in + "_manhattanized"

full = input(62,1)


#Manhattanize specific layer(s)
[67, 319].each do |l1|
  target=input(l1).sized(10.nm).sized(-10.nm)#deal with any waveguide gaps
  p = fill_pattern("sq1").shape(999,1, box(0, 0, w, w))#999,1 TEMP LAYER.
  target.fill(p, hstep(w,0), vstep(0,w), auto_origin)#Fills cell with boxes
  input(999,1).sized(10.nm).output(l1)#merges boxes to be fewer polygons
  null.output(999,1)#Replaces the target layer
  layout.prune_cell(layout.cell_by_name("sq1"), -1)


options =

options.add_cell(cv.cell_index) #top cell should be selected before script starts.

Here is a BEFORE layout, layer 67/0, one of the layers to be manhattanized:

Here is the AFTER layout of the same region/layer:

Overall the errors I have observed using variations of this script is horizontal gaps in fill 1 or 2 squares high, and also sometimes horizontal lines 1 square high that extend to the right from the geometry like this:

Thanks for the help!


  • I'm sorry, I could not reproduce the problem with a test case of mine. Maybe you can attach a GDS file that allows reproducing the problem. And what is the version and OS in your case?

    In general, you're using the fill feature for something it was never intended for. This feature is meant for producing dummy tiles or holes in solid areas for homogenizing the density. For this application, exact coverage is not the primary goal. It will always give you an inner approximation of the polygons and is pretty inefficient.

    And the script is weird mix of DRC and plain script. If you want to stay within DRC world more consistently, use

    • source.layout instead of cv.layout
    • source.path instead of cv.filename
    • source.cell_name instead of cv.cell_name
    • = .. instead of layout.rename_cell(...)

    null = full - full is a waste of CPU cycles. null = polygon_layer does the same in zero time. "prune_cells" should not be required if you do not write empty cells (maybe "sq1" gives a name clash on second iteration and an individualized name has to be used).


  • Matthias,

    Thank you very much for getting back to me. This was done Klayout 0.27.1 and Windows 10 Enterprise v 20H2.

    Given that the fill feature is not intended to do what I'm trying to do with it, I'm working with my team to get a Cadence or Calibre solution, which I think will be the path of least resistance. If we can't do that for any reason, I'll comment here again, and at that point attempt to reproduce the issue in a non-confidential GDS that I can upload.

    Thanks also for the pointers on cleaning up my code to stay within the DRC command set.


Sign In or Register to comment.