DRC Input Output

edited January 2020 in Layout

Hello Matthias,
my code should combine some DRC operations (booleans). It worked well in version 0.25 but in version 0.26 it throws me an error.


Here is the code:
`
comment: 2. Boolean Operation (Difference lr1 vs lr2)
lr1 = input(120,0)
lr2 = layout("@2").input(15,0)
target("@2")
diff = lr2-lr1
diff.output(15,0)

comment: 3. Boolean Operation (Union Layer15(@1) and Layer15(@2)
lr1 = input(15,0)
target("@1")
align = lr1.or(lr2)
align.output(15,0)
`


The Error Message:

Operation cancelled in Layout::get_info in MacroInterpreter::execute
C:/Users/.../KLayout/drc/greylines - cutout layer.lydrc:52:in execute_drc' :/built-in-macros/drc_interpreters.lym:18:ininstance_eval'
:/built-in-macros/drc_interpreters.lym:18:in execute_drc' :/built-in-macros/drc_interpreters.lym:65:inexecute'


It happens in step 3. But if I comment out step 3 it happens in step 2 already.
I hope you can help me with this.

Kind regards,
Christian

(Sorry for the bad editting)

Comments

  • edited January 2020

    Hi Christian,

    I tried to reproduce the problem, but I failed. Here is the experiment by which I tried to grasp the problem:

    lr1 = input(1,0)
    lr2 = layout("@2").input(1,0)
    target("@2")
    diff = lr2-lr1
    diff.output(100,0)
    
    lr1 = input(100,0)
    target("@1")
    align = lr1.or(lr2)
    align.output(100,0)
    

    I load two times the same layout into the same view. The layout has layer 1, so I have two identical layouts, each with layer 1. After I run this script, I get an empty layer 100 in layout 2 and a copy of layer 1 in layer 100 as expected. No error.

    I'm using the most recent version, 0.26.3.

    Is this the idea or am I doing something wrong?

    Matthias

  • Your version works fine. But there is a difference to my code:

    • first operation: diff.output should be put out to layer 15@2 (which is stored in lr2)
    • this new layer should then be part of the second operation

    Then this error happens:

    Internal error: ../../../src/tl/tl/tlReuseVector.h:277 mp_v->is_used (m_n) was not true in Region::| in MacroInterpreter::execute
      C:/Users/.../KLayout/drc/test.lydrc:11:in `execute_drc'
      :/built-in-macros/drc_interpreters.lym:18:in `instance_eval'
      :/built-in-macros/drc_interpreters.lym:18:in `execute_drc'
      :/built-in-macros/drc_interpreters.lym:65:in `execute'
    

    I guess I have to re-assign this new layer to lr2 in the second operation like in the following code:

    lr1 = input(100,0)
    lr2 = layout("@2").input(1,0)
    target("@2")
    diff = lr2-lr1
    diff.output(1,0)
    
    lr1 = input(1,0)
    lr2 = layout("@2").input(1,0)
    target("@1")
    align = lr1.or(lr2)
    align.output(1,0)
    

    But then I get another error and I don't know why:

    basic_string::_M_create in Layout::get_info in MacroInterpreter::execute
      C:/Users/.../KLayout/drc/greylines - cutout layer.lydrc:52:in `execute_drc'
      :/built-in-macros/drc_interpreters.lym:18:in `instance_eval'
      :/built-in-macros/drc_interpreters.lym:18:in `execute_drc'
      :/built-in-macros/drc_interpreters.lym:65:in `execute'
    

    Here is the full code I use in a DRC script:

    source("@1")
    
    # 1. Merge Shapes to reduce runtime
    lr1 = input(120,0)
    lr2 = input(121,0)
    lr3 = input(122,0)
    lr4 = input(123,0)
    
    lr1.merge()
    lr2.merge()
    lr3.merge()
    lr4.merge()
    
    #print lr1.is_merged?
    
    #Sidestep: Edges (61) - Cutout Layer (10-12)
    lr1 = input(10,0)
    lr2= input(61,0)
    cut = lr1&lr2
    target("@1")
    new=(lr1-cut)
    new.output(10,0)
    
    lr1 = input(11,0)
    lr2= input(61,0)
    cut = lr1&lr2
    new=lr1-cut
    target("@1")
    new.output(11,0)
    
    lr1 = input(12,0)
    lr2= input(61,0)
    cut = lr1&lr2
    new=lr1-cut
    target("@1")
    new.output(12,0)
    
    # 2. Boolean Operation (Difference CutOutLayer vs GreylinesLayer)
    lr1 = input(120,0)
    lr2 = layout("@2").input(15,0)
    target("@2")
    diff = lr2-lr1
    diff.output(150,0)
    
    # 3. Boolean Operation (Union Layer15(@1) und Layer15(@2)
    lr1 = input(150,0)
    lr2 = layout("@2").input(15,0)
    target("@1")
    align = lr1.or(lr2)
    align.output(15,0)
    
    # 4. Size shapes with 10µm as parameter
    lr1 = input(120,0)
    lr2 = input(121,0)
    lr3 = input(122,0)
    lr4 = input(123,0)
    
    lr1.size(10).output(120,0)
    lr2.size(10).output(121,0)
    lr3.size(10).output(122,0)
    lr4.size(10).output(123,0)
    

    Like before it works in 0.25 versions but not in 0.26.
    Another thing I recognized: it works fine in both versions if some output operations are commented out (e.g. #sidestep).

    Thanks for your help!
    Christian

  • Hi Christian,

    I'm afraid that's a bug.

    The problem is the frequent switching of the target - usually there is just one target specification. But I admit this is a valid use case and should be supported.

    I have created a ticket for this here: https://github.com/KLayout/klayout/issues/476

    As a workaround (works for 0.26.3), you can use this piece of code in front of your DRC script. It will clear the list of output layers where the DRC script tracks the result layers upon "target" calls:

    class DRC::DRCEngine
      if !self.method_defined?(:_finish_org)
        alias :_finish_org :_finish
        def _finish(final = true)
          begin
            _finish_org(final)
          ensure
            @output_layers = []
          end
        end
      end
    end 
    

    Please remove this code once the bug is fixed.

    Kind regards,

    Matthias

  • Thanks Matthias! It works now :smile:

Sign In or Register to comment.