set_property in pcell produce_impl

Hi, I am tring to store some information (like a coordinate) into a pcell when I generate it because I have some nested pcell (one pcell using some other pcells). I found the Cell class has set_property(), I tried to add property in pcell decl but It didn't work.
Here's the code:

include RBA
module TestLib
    Library.library_by_name("TestLib").delete if Library.library_by_name("TestLib") 
    class Test1 < PCellDeclarationHelper
        def initialize
            param :layer_a, TypeLayer, "layer_a", :default => LayerInfo::new(920601, 0, "Metal_GS/layer_a")
            # $layer_a$: 
            param :a, TypeString, "a", :default => "a"
            param :length, TypeString, "length", :default => "100000"
        def display_text_impl
        def produce_impl
            cell.shapes(layer_a_layer).insert(, length.to_i))
            cell.set_property("length", length)

    class TestLib < Library
        def initialize
            self.description = "TestLib Library"
            layout.register_pcell("Test1", Test1::new) #

Anyone could help? thx:)


  • edited December 2023

    Hi @Default,

    this will not work. The cell you see is not the target cell, but an internal cache located in the library.

    The only acceptable way of storing information is to use a hidden parameter.

    However, you cannot change a parameter value in "produce_impl". You can only change it in "coerce_parameters_impl". This is where to put logic that computes parameters. "produce_impl" is expected not to modify the PCell object.

    I strongly advise to follow these rules. The mentioned caching mechanism, the persistence layer and user expectation in general depend on two facts: first, that a PCell does not change the state in "produce_impl" and second, that the layout produced by "produce_impl" is a function of the parameters and nothing else. Stateful PCells can create a nightmarish user hell - something that I experienced myself with Cadence PCells. Just don't do it.


  • Thank you Matthias. I wonder what is the "hidden parameter"? is the Pcell parameter with ":hidden => true"?

  • Yes, exactly.

    Hidden parameters are a way to store information persistently (i.e. inside GDS files). That is the only way to store information generated inside PCells. Everything else is "write only".


  • edited April 19

    Thank you Matthias. Another question: I have a PCell which has a random number parameter so I don't know the parameter unless I draw it. Now I place a Text object in the layout when generating the PCell and I write some script to read the parameter inside the Text object.
    Is there any more efficient way to do that?

  • Hi @Default,

    You mean the PCell drawing code decides itself, what the parameter value is?

    In short: don't do such a thing.

    KLayout's design is based on the assumption that same parameters mean same layout. This is the basis for caching and persistency. Generating a random number violates this assumption and the results will be unpredictable.

    Maybe you can explain what you are trying to achieve and there is a different option.


Sign In or Register to comment.