Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

  1.  

    Hi all, I am using KLayout 24.9 (2016-11-27 r3488).

    Trying to call set_property in a loop on a large number of instances (> 30000) failed for me with the following line:

    Internal error: c:\klayout\0.24\src\tlReuseVector.h:255 mp_v->is_used (m_n) was not true in Instance::cell in Action::triggered
    

    Could this be caused by an out-of-memory situation, or do I have another problem in my script?

    If it is of interest, I can try to create a script (by removing anything unrelated) to reproduce the error, but I thought I ask first whether this is a known problem.

    Thanks, Chris

    • CommentAuthorMatthias
    • CommentTimeMar 7th 2017 edited
     

    Hi Chris,

    this message basically says that KLayout can't find an object it likes to iterate over. This can happen if you modify the objects "substantially" while iterating over them. Setting a property is a "substantial" modification since it may turn a property-less instance into one with properties and vice versa.

    What you experience as "objects" (i.e. Instance) are basically pointers into the internal data structures of KLayout. I am trying to make them look like objects, but still some use scenarios are not supported. Providing some code may help me to improve the implementation.

    In general, my recommendation is not to modify objects while iterating over them. It always safer to collect the objects you want to modify first and then modify them. Like this:

    cell = ... # some cell
    
    instances_to_modify = []
    cell.each_inst do |inst|
      instances_to_modify << inst
    end
    
    instances_to_modify.each do |inst|
      inst.set_property(42, "meaning of life")
    end
    

    Some methods and properties are safe to use/modify within loops. For instance objects these are (no warranty):

    • Target cell: cell=, cell_index=
    • Transformation: trans=, cplx_trans= and transformation methods transform, transform_into
    • Array properties: a=, b=, na=, nb=
    • change_pcell_parameter, change_pcell_parameters
    • convert_to_static
    • delete
    • parent_cell= (with restrictions)

    Other properties and methods are not necessarily safe to use while iterating. At least no currently.

    Matthias

  2.  

    Hi Matthias,

    Thank you very much for this information, I had indeed used a single loop to go through and modify the list of instances. Separating the loop into a "collect" loop followed by another "modify" loop as you suggested resolved the issue.

    Also thanks for the list of methods intended to support in-place modification of objects, I'll try to avoid modifying objects via other methods in the same loop in the future.

    In any case, it is good to know what the error message means "in layman's terms" so that I come across it again, at least I know what to watch out for :-)

    Thanks again for making such a powerful tool available to the rest of us!

    Chris

    • CommentAuthorMatthias
    • CommentTimeMar 13th 2017
     

    Hi Chris,

    I wish I could give a better message in this case :-)

    But that's actually a deeply buried assertion which is a general hint that something is inconsistent.

    Matthias

  3.  

    Hi Matthias,

    I've come across another case of this error (note I meanwhile have switched to KLayout 0.24.10), but this time I don't see any obvious way around the problem. Here is what I initially wanted to do:

    alv.object_selection.each do |obj_inst_path|
      if !obj_inst_path.is_cell_inst? && !obj_inst_path.shape.is_text?
        shp = obj_inst_path.shape.dup  # also tried without dup here
        shp.transform(obj_inst_path.trans)
        # ... do something with the shape ...
      end
    end
    

    Since that gave me the error mentioned in the title (at the transform line), I tried your "array trick":

    selected_shapes_transs = []
    alv.object_selection.each do |obj_inst_path|
      if !obj_inst_path.is_cell_inst? && !obj_inst_path.shape.is_text?
        selected_shapes_transs << [obj_inst_path.shape, obj_inst_path.trans]
      end
    end
    selected_shapes_transs.each do |shp,trans|
      shp.transform(trans)
      # ... do something with the shape ...
    end
    

    Or, another variant:

    obj_inst_paths = []
    alv.object_selection.each do |obj_inst_path|
      if !obj_inst_path.is_cell_inst? && !obj_inst_path.shape.is_text?
        obj_inst_paths << obj_inst_path
      end
    end
    obj_inst_paths.each do |obj_inst_path|
      shp = obj_inst_path.shape
      shp.transform(obj_inst_path.trans)
      # ... do something with the shape ...
    end
    

    But that still gave me the error. I also saw that simply shp.to_s just before (or instead of) the transform call also causes this error. Is there perhaps another trick I should learn?

    Thanks, Chris

    • CommentAuthorMatthias
    • CommentTimeMay 8th 2017
     

    Hi Chris,

    I suspect some other issue before. Maybe you modified the shapes container before this loop?

    This piece of code works for me:

    alv = RBA::LayoutView::current
    alv.object_selection.each do |obj_inst_path|
      if !obj_inst_path.is_cell_inst? && !obj_inst_path.shape.is_text?
        shp = obj_inst_path.shape.dup  # also tried without dup here
        puts shp.to_s
      end
    end
    

    I guess this is what you mean.

    Here is one potential explanation: maybe you modified the shapes the selection points to. That basically means the selected shapes become invalid. Maybe that is a direct or a side effect of another step that happened before.

    Matthias

  4.  

    Hi Matthias,

    Thanks for the hint, my problem must have indeed been related to modified shapes: For example, I executed a prototype of the script which (inadvertently) modified the shape, and while I subsequently had fixed the script, the layout was still in the "modified" state it seems - causing the script, although correct at that point, to fail.

    Re-loading the layout (or sometimes just re-selecting the shape) fixed the issue... I guess I need to be more careful while debugging my scripts in the future.

    Thanks for your continued support!

    Regards, Chris

    • CommentAuthorMatthias
    • CommentTimeMay 10th 2017
     

    Very good :-)

    My advice is in general to clear the selection when you have modified a layout in a script. That may be a little inconvenient but will avoid such issues later.

    Kind regards,

    Matthias