KLayout PCell establishment

YJYYJY
edited March 2020 in Python scripting

Hi!
I try to build PCells in KLayout using pya.PCellDeclarationHelper with the third-party Python libraries, like IPkiss.
I build Python scripts in Ipkiss to draw the layout and generate a *.gds file.

I'd like to know:
Is there any way to pass the GDS file directly into pya.PCellDeclarationHelper and return layout image in KLayout panel?

The coed I tried is :

class WgYSplitter_temp(pya.PCellDeclarationHelper):
  def __init__(self):
    super(WgYSplitter_temp, self).__init__()
    TECHNOLOGY = get_technology_by_name('***')
    self.param('core_width',self.TypeDouble,'Core_width [um]',default=0.45)
    self.param('cladding_width',self.TypeDouble,'Cladding_width [um]',default=4.45)

  def display_text_impl(self):
    return 'WgYSplitter_%.4f_%.4f' %(self.core_width, self.cladding_width)

  def coerce_parameters_impl(self):
    pass

  def produce_impl(self):

    core_width = self.core_width
    cladding_width = self.cladding_width

    import os
    #print('*****************************************************************************************')
    path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../Script_Python"))
    cmd ='python TestScripts.py'+' '+str(core_width)+' '+str(cladding_width)
    os.chdir(path)
    os.system(cmd)
    # some actions like:
    #return self.layout().read(file_path.gds)
    print ('GDS generation finished')

This code can correctly link KLayout with my Python scripts using the third-party libraries, but cannot return the layout image in KLayout.
If there are some methods in pya.PCellDeclarationHelper behaving the same action like self.layout().read(file) in pya.Library, the PCell establishment could be simplified.
Of course, I tried using os.popen instead of os.system to pass datas, but the code could be complex...

Thanks!

Comments

  • Hi,

    please format your code so it becomes readable. A line with triple backticks before and after the code is enough.

    But if you have a Python module which generates your code - why not importing this module into KLayout and using it directly rather than starting an external process?

    Matthias

  • You know, I used to get a lot of mileage out of Cadence's
    classical graphical PCells (which were perfectly capable
    for simple W, L, M kinds of variations). But coding, I have no
    abilities (and not much motivation to step away from circuit
    design and layout, to go develop them). When PCells became
    a CAD programming exercise, from that point I left PCell
    creation to the CAD group. But now I don't have a CAD group.

    Is there any chance of a graphical PCell functionality?
    Stretch-lines and conditional stepping / instantiation, as
    graphical objects and element properties?

    Maybe something that takes these kinds of "hand / eye
    expressions" and "compiles" them to a code-PCell for
    those of us who are not good coders? A "Visual PCell
    builder"?

  • Hi, Matthias

    Many thanks for your reply.
    I feel quite sorry for the bad formatting of the code, since I'm not familiar with the rules.

    In fact, the biggest problem comes from the incompatiblity of Python version.
    The Python version in KLayout is 3.x, however the Python Modules I used are based on 2.x.
    That's why I start the extrnal process.
    I'd like to know if there is any way to solve the problem.

    Thanks!

  • Hi Jim,

    I know the graphical PCell concept but frankly it's a pretty complex feature. That's not something to be done easily within in the few hours between day and night. I'm sure a simple implementation is easy, but I'm also sure it's limitations will soon become obvious.

    @YJY: KLayout can be built with Python 2 as well. So maybe it's finally easier to build KLayout with Python 2 than trying to get a cross-process solution running in a reliable way. And please edit you post for the formatting - editing is open for one week after the post has been published.

    Matthias

Sign In or Register to comment.