Import all technologies of a folder

Dear Klayout developers,
I want to import all technogies of a folder with a ruby file. I discover that it can be created and modified by https://www.klayout.de/doc-qt5/code/class_Technology.html#m_technologies_from_xml.
I have the .lyt files in each technology folder. However when I try to import a .lyt with the instruction technology_from_xml, the continuos error is that there is a parse error.
Any idea to do this file? It has to be easy but I also try to use load_options and it happens the same problem

Comments

  • Could you please provide details? Like how you call the function and what's the error message?

    Matthias

  • I attach you the layer property file changing the format from .lyt to .txt because the forum doesn't allow to attach other file formats.

    My initial code is:

    include RBA

    Enter your Ruby code here

    mitech = RBA::Technology.technology_from_xml('haspfhohap.lyt')

    And the error message is:
    XML parser error: error occurred while parsing element in line 1, column 1 in Technology::technology_from_xml
    pruebas.rb:4:in technology_from_xml' pruebas.rb:4:in

    '

    Thank you Mattias

  • Is it really difficult to use code formatting in this forum? This is hardly readable. There is a nice editor and you can use the "Code" paragraph formatting so I don't have to guess what this garbage is supposed to mean.

    And "technology_from_xml" reads and XML string. So don't pass the file name, but the content of the file. Like (error handling missing):

    xml_text = File.open("haspfhohap.lyt").read
    mitech = RBA::Technology.technology_from_xml(xml_text)
    

    Matthias

  • oh, sorry matthias. I just copy the code and I don't see the final preview.
    Thank you for your answer.

  • edited February 2021

    Dear Matthias,

    At the beginning, it seems that it works and it generates the technology.

    CODE 1

    include RBA
    f = File.open('haspfhohap.lyt')
    xml_text = f.read
    mitech = RBA::Technology.technology_from_xml(xml_text)
    f.close
    

    So I develop a code to read all the technology folders and technologies in a file

    CODE 2

    folder = File.join(ENV['HOME'],'\\Technology files\\')
    
    technologies = Dir.entries(folder).select {|entry| File.directory? File.join(folder,entry) and !(entry =='.' || entry == '..') }
    def get_lyt_file_paths(path, &block)
      Dir.glob( '*.lyt',base: path ).each(&block)
    end
    
    for index in 0 ... technologies.size
      files_to_process = []
      folder_path = folder+technologies[index]
      get_lyt_file_paths(folder_path) {|f| files_to_process << f }
      if files_to_process.length >0
        puts folder_path+"\\"+files_to_process[0]
                    xml_text =  File.open(folder_path+"\\"+files_to_process[0]).read
                    RBA::Technology.technology_from_xml(xml_text)
      end
    end
    

    It seems that the second works because it doesn't show any error.
    However, it seems that in the process to develop that code I crash something inside Klayout because I try to run the first code again and It doesn't work. I have unistall klayout, delete the Klayout folder in Users, reboot computer in each step to have a clean instalation of klayout, everything to have a clean installation of klayout. I have Windows operating system.

    However, now the first code doesn't works. The macro runs and it doesn't show any error, but the technology is not appear in the manager of technologies. I also use the functions _manage and _create, and it seems that internally is create the technology, but it doesn't appears in the manager of technologies.

    Matthias, do you know how to fix this? I think it's something to do with the kernel or something, but it's strange that when reinstalling everything from scratch, the most basic example doesn't work.

  • UPDATE:
    Finally I can do a workaround, creating a technology for each technology, loading the .lyp and chaging the explicit_base_path

    include RBA
    folder = File.join(ENV['HOME'],'\\Technology files\\')
    RBA::Technology.clear_technologies
    technologies = Dir.entries(folder).select {|entry| File.directory? File.join(folder,entry) and !(entry =='.' || entry == '..') }
    def get_lyt_file_paths(path, &block)
      Dir.glob( '*.lyt',base: path ).each(&block)
    end
    
    for index in 0 ... technologies.size
      files_to_process = []
      mifolder = folder+technologies[index]
      get_lyt_file_paths(mifolder) {|f| files_to_process << f }
      if files_to_process.length >0
        f = File.open(mifolder+"\\"+files_to_process[0]);
                    xml_text =  f.read
                    mytech = RBA::Technology.create_technology(technologies[index])
                    mytech.load(mifolder+"\\"+files_to_process[0])
                    mytech.explicit_base_path=mifolder+"\\"
                    puts mytech.default_base_path
                   # mytech = RBA::Technology.technology_from_xml(xml_text);
                    f.close;
      end
    end
    
    
  • Rebooting will never put KLayout into a different state. Reinstalling doesn't change something either. If you want to clean your KLayout installation remove the KLayout folder in "%HOME%\KLayout" (on Windows). That's it. I think what you're observing is that Ruby garbage collector hits you.

    You have not told me what you want to do with the technologies you load.

    You're not storing the technology objects somewhere. I assume this makes Ruby garbage collect them on a more or less random occasion. This happens when you use "technology_from_xml". I wonder how these technologies become available to the system. They should not be registered and not become visible.

    "create_technology" registers the technology and this will make Ruby not clean up the object. Hence this approach is immune against the GC issue.

    TLDR: keep the last approach.

    Matthias

Sign In or Register to comment.