Python standalone module - Please give feedback

I have started development on a standalone Python module. That is a Python module which provides KLayout's Python classes without the application. You can load this module into your own interpreter and use the ecosystem of your choice.

For more details see https://github.com/klayoutmatthias/klayout/wiki/pykl---Standalone-KLayout-Python-Module

I'd like to get some feedback on this, although it's in an early stage yet.

Matthias

Comments

  • Hi Matthias, I am very interested in that. Let me know if I can help testing. I did read through your code (very beautiful, by the way) but I can't claim I understand the wrapping for Python completely. Let me have a look.

  • Hi Matthias, I am very happy to hear this news. I think klayout is a great software. Since my project included other parts, it is a bit tricky to run in klayout. If there are independent Python packages, I believe that klayout can be used for more applications. thanks for your job . (๑•̀ㅂ•́)و✧
  • Sounds like a great idea. As you say, the PyQt and GSI interoperability would be great, though not sure if technically feasible.

  • Hi All, I actually don't see a need to wrap the Qt GUI classes into a Python module. The point of the GUI is to run the app, so I don't see why I would start the app from Python. On the other hand, the Python module is a way to modify the content in the database programatically rather than with GUI commands. So the way I work is to first generate the gds file (by linking the klayout batch mode to PyCharm - best Python IDE ever - and then looking at the output with the KLayout in GUI mode (it updates automatically when it sees that the gds has changed).
    Maybe other people have different use cases, please chime in.

  • Hi All, I downloaded the pymod branch and built it on Linux but I didn't get a pykl module or directory in the build directory. Is there a build option needed to get the pykl module? Thanks.

  • My build options are:
    ./build.sh \
    -qt${qt_version} \
    -qmake ${qt_used}/bin/qmake \
    -python ${python_used}/bin/python3 \
    -pylib ${python_used}/lib/libpython3.6m.so \
    -pyinc ${python_used}/include/python3.6m \
    -option -lutil \
    -j4 \
    -noruby \
    -prefix ${prefix} \

  • Hi Matthias, how do you want to handle the discussion, on this forum or using your klayout email? I am one step further, I got the repo from github, compiled again, and now find the pykl module (but not in the installed build directory, only in the build-release directory in the source directory). However, I get an error:
    ImportError: dynamic module does not define module export function (PyInit_db)
    in Python 3, and
    ImportError: dynamic module does not define init function (initdb)
    in Python 2.
    The pykl directory contains .so files, but no .py files. Do you build a static library instead of a dynamic library to make this work.
    Thanks, Erwin

  • I suspect it's an issue with my Python setup, I'll try on Ubuntu instead.

  • I built on Ubuntu. The build finishes. The install fails with:
    /usr/bin/ld: cannot find -lklayout_ext
    This is when I do "make install" in the build-debug directory (which may be the wrong thing to do).
    If I manually copy the init.py file to pykl and try to load, I get
    from pykl.db import db
    Traceback (most recent call last):
    File "", line 1, in
    ImportError: dynamic module does not define module export function (PyInit_db)
    Any idea what I am doing wrong? Thx.

  • OK, I found the issue tracker on GitHub so in the future I post there ...

  • Hi Erwin,

    thanks for your lot of feedback :-)

    First apologies for the early version of Python branch - it's not building everywhere but I'm improving it constantly.

    Regarding the module structure, the db and tl modules are the basic ones. They are rather lean and offer the basic functionality: loading/saving, layout generation/manipulation, the functionality of the DRC module, booleans etc. I recently added the net tracer functionality to this module.

    I did not want to entirely drop the whole UI functionality as it may be useful - for example for offline rendering. But this functionality will pull in all the Qt bindings, hence it's not lean. On the other hand, this feature would offer a way to integrate the layout view into a PyQt application which to me feels like an interesting feature. I just have not worked out the details yet.

    Regarding the communication - if you prefer Github please feel free to post here: https://github.com/klayoutmatthias/klayout/issues/130. But I'll also follow this discussion.

    Thanks,

    Matthias

  • Excellent idea! Interesting how it will co-exist with/replace shapely and gdspy. Will give it a try soon.

  • Great!!!
    I have wanted this feature for long time.
    Now, I have to use boost.python to change klayout code and map out klayout classed as python module.

  • edited July 2018

    @dion Why boost.python? KLayout has it's own Python export feature.

    BTW: there is already a setup.py in the pymod branch. It awaits port to Windows, but on Linux and MacOS it's working.

    Matthias

  • before pymod development, I use boost.python to export python module for klayout 0.24 version.
    Now, I will try pymod.

Sign In or Register to comment.