Package: lyipc
Inter-process communication for KLayout (lyipc)Approaches for integrated circuit layout fall into two main categories: GUI-driven, interactive design; and script-driven, non-interactive programming. The latter is more repeatable, modifiable, and reusable once the script has been written; however, the layout object state and its evolution through time is realtively opaque to the programmer.lyipcis used as a graphical debugging workflow that uses the KLayout viewer but is not necessarily dependent on the klayout scripting language or IDE. The idea is to create a communication link between two processes:A server that is launched from within the klayout.app GUIA client that can control various aspects of that klayout.app GUIBy separating the processes, the KLayout server GUI can be fully featured, initializing a large virtual program memory, while the client can be lightweight and in any sort of python environment or layout language (e.g. phidl, gdspy, nazca, etc.).Detail: a debug process flow looks like this[process #1] From klayout.appFrom menu item, start a simple server (Cmd-I)[process #2: programmer] From the geometry creation programImportlyipcclient packageStop this program in a debugger like PDB or Spyder (examine/change program variables)Write to a file "x.gds", and callipc.load("x.gds"), orCall on a layout object such asipc.kqp(my_Device)[process #2: lyipc] The lyipc.client module willInitiate a socket connection on port 11078Send a command that means load[process #1] Upon receiving a connection requestReceived command is parsedAn action is taken. In this case, load that file into the current view[process #2: lyipc] closes the socket and continues executionOther usesRemote debuggingXOR error visualization withlytestAnimation: timed sequence of layoutsTracing: refresh display at every step of the programInstallationFrom PyPIpipinstalllyipcYou then have to install it into klayout with this commandlygadgets_linklyipcSuppress reload promptWhen an open file changes on disk, by default, KLayout asks whether to reload it. This blocks lyipc until a human clicks the prompt. Disable checks by going to klayout.app's preferences > Application > General, and uncheck the box for "Check for file updates."From klayout salt package managerAs of 0.1.12, this is no longer supported.UsageServer side-- press Ctrl+I--or go to "Tools>Inter-process communication server"Warning: clients have the ability to close and reload layout views that are unsaved, including ones in other tabs.It is often useful to start a second instance of klayout.app: one for persistent viewing/editing, and one to host the lyipc server.Client sideTo load a layout file called "mylayout.gds" in the remote window, put these linesimportlyipc.clientasipcipc.load('mylayout.gds')You can also send layout objects in memory directly. This is the more commonly used approachfromlyipcimportkqpkqp(my_Device)wheremy_Deviceis a layout object, such as aCellin pya or aDevicein phidl.kqphas an optional argument "fresh" (defaults to False). When False, the current layout is reloaded, keeping viewbox, layers, etc. When True, the new object is loaded as a fresh layout.Usage examples for klayout and non-klayout clients are included in this repo in the "examples" folder.Command line interfaceAs of v0.2.14, there is a CLI entry pointlyipc_reloadfor convenience.
With no arguments, it reloads the current view. When a filename is provided,lyipc_reloadwill detect that it needs a fresh load. With--fresh(or-f), the file is always loaded as a new file.lyipc_reload -f x.gdsis similar toopen x.gdson some systems.lyipc_reloadoutput.gds# Opens fresh if neededpythonscript_that_affect_outputgds
lyipc_reloadoutput.gds# Reloads without closinglyipc_reload# Same thing, unless the user has closed the viewRemote debug and jobsUsing ssh, rsync, sshfs, and lyipc, you can work on a remote, high performance computer the same way you work on your laptop - without being able to notice the difference. These features are still somewhat experimental. You must first configure two-way RSA authentication. Here is the process:[laptop] initiates klayout IPC configured for incoming connections[remote HPC] point the "LYIPCTARGET" environment variable to your laptop[remote HPC via sshfs] expose remote filesystem for editing on your laptop[remote HPC via ssh] command to run script[remote HPC] kqp is called, which writes a temporary gds file[laptop via rsync] receives the temporary file[laptop via lyipc server] receives command to load that file into the klayout windowNetwork IPC (Done)Run a server on one computer. Configure something in lyipc in the second computer. Send lyipc commands. At first, do load with the gds already on the first computer. Next, combine with rsync and gds on local computer with client.loadremote build (Done)[laptop user] lyipc-job script.py[laptop] rsync script.py[HPC] python script.py[HPC] rsync output.gdsfile transfer and IPC and lytest (done)Set some configuration of lytest, which sets some configuration of lyipc. Runlytest diff file1.gds file2.gds. These files are shipped to remote. XOR is run there. Error is detected and sent back to the klayout GUI of the first computer. This will involve actual file transfer.Edit: this did not set anything in lytest. It was a matter of lyipc:set_target_hostnameand the HPC usingship_fileto get things back down.Notes: to send a file for testing, to call commands and get printouts, to rsync (either direction) -- you need a one-way RSA authorization. If you want to run remote tests that pop up in the local GUI, that currentlyrequires a two-way RSA authorization. When the HPC is running, its lytest has the ball (kind of). It decides when to send a pair of files to lyipc. Then lyipc notices that it has to ship those files remotely, requiring rsync. Huh, what if the QTcpSocket in lyipc could send a notice back down that said: rsync this thing from me; it is ready.Author: Alex Tait, June 2018National Institute of Standards and Technology, Boulder, CO, USA