It looks like you're new here. If you want to get involved, click one of these buttons!
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
Comments
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:
Some methods and properties are safe to use/modify within loops. For instance objects these are (no warranty):
cell=
,cell_index=
trans=
,cplx_trans=
and transformation methodstransform
,transform_into
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
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
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
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:
Since that gave me the error mentioned in the title (at the
transform
line), I tried your "array trick":Or, another variant:
But that still gave me the error. I also saw that simply
shp.to_s
just before (or instead of) thetransform
call also causes this error. Is there perhaps another trick I should learn?Thanks, Chris
Hi Chris,
I suspect some other issue before. Maybe you modified the shapes container before this loop?
This piece of code works for me:
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
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
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