Headless vs non-headless

I created a gds that works fine when I open it via Klayout; but when I try to
open it in headless mode, both the geometries that I've drawn and the layers that I've
assigned, are wrong. What could be causing this problem?
Thank you,



  • Hi Alessandro,

    stupid question: how can you "open" a layout in headless mode? "headless" to me means: without display ...


  • Hi,
    yes maybe it was better to say "run". When I run it through the cmd prompt

  • Is this Windows?

    And then, what's the command you're using?

    "klayout myfile.gds" should give you exactly the file you saved, provided this "klayout" is the same binary.


  • Yes, it is windows. I'm using this:
    klayout_app.exe -b -r mydrcrules.lydrc -rd input_file=mygds.gds -rd db_file_out=mydbfileout.lyrdb -rd output_file=mygdsout.gds

  • Thanks for this line. It's actually the intended use model ... however this takes me to the next question. I assume that "mydrcrules.lydrc" does something with the layout (e.g. perform boolean operations).

    I guess the .lydrc file also contains a statement like "source($input_file)" and "target($output_file)". It also needs to have "input(layer, datatype)" statements.

    In which sense is the file "wrong" then? Wrong geometry? Missing layers?


  • We have included the "source($input_file)" and "target($output_file)" statements. The "input(layer, datatype)" statement is only included for the input layers. We have not specified the output layers using "input(layer, datatype)", is this required?


    layerA = input (1, 0)
    layerA.width(20.um, projection).output(A_width_check)

    When the DRC file is run in Klayout via the UI, the layer is named "A_width_check". When the same DRC is run in headless mode, a layer number is assigned, and this is different to the layer number assigned in headless mode.

    The output when using the UI is a layer called "A_width_check" with number/datatype (99, 0).
    When run in headless mode, the layer/datatype is (2,0) with no name.

  • edited August 2019

    Thanks for this example. I think I understand the issue.

    You should include layer and datatype into the output statement, like

    layerA.width(20.um, projection).output(17, 0, A_width_check)

    Otherwise, KLayout will pick a number itself and this will differ in batch from. In interactive mode, it will pick another free number which isn't clashing with the input file. In batch mode I think the number just starts with 1. Using a fixed layer/datatype pair will avoid this.

    But then, the "output" statement won't work with "report", but only with a target layout. If you want output to work both with report and target layout, I'm afraid you have to use "ifs" to differentiate:

    check = layerA.width(20.um, projection)
    if $target_file
      check.output(17, 0, A_width_check)


    if $target_file
      A_width_check = [ 17, 0, "A width_check" ]
      A_width_check = [ "A width check" ]
    layerA.width(20.um, projection).output(*A_width_check)



  • Thank you! Problem solved.

Sign In or Register to comment.