Skip to content

KLayout 0.30.0 - Windows - Saved Working .oas, now getting Error: "Same cell name...but differnt IDs:.." #2088

Closed

Description

@liamgconnolly
Image

Was working on the file, saved many times while KLayout was open and no issues. Restarted my computer the next day and went to reopen, but was greeted with this error.

From reading: https://www.klayout.de/forum/discussion/2205/error-opening-an-oasis-file-created-in-klayout

I can see with dump_oas_gds2 (https://github.com/klayoutmatthias/dump_oas_gds2) that there are indeed 2 cells named Cross (object comes from the lithography tool kit library), but I'm not exactly sure about how to remedy the issue and remake the OAS file and I'd really love not to lose a day or so of work

oas_dump.txt

Activity

  1. klayoutmatthias commented on Jul 12, 2025

    @klayoutmatthias
    Collaborator

    Hi @liamgconnolly,

    It's possible to create cells with the same name through scripting. It's the responsibility of the script author to make sure cells names are unique. The scripting API does not enforce this condition. In that sense I think the lithography tool kit library should be reviewed for potential flaws in that direction.

    Here is a script that creates such a file:

    import klayout.db as kdb
    
    ly = kdb.Layout()
    l1 = ly.layer(1, 0)
    cell_a = ly.create_cell("A")
    cell_b = ly.create_cell("B")
    cell_b.name = "A"
    # but this fails:
    ly.write("broken.oas")
    

    But the OASIS writer refuses to write this case:

    Image

    I verified that this not only happens in scripted writes, but also interactively.

    So how did you then manage to write an OASIS file with the same cell name? The safety check is in KLayout since 2020, so your version should be fresh enough. If there is a loophole, I'd be interested to see how this happened, so I can close it.

    About how to fix it: as you are able to run "dump_oas", you can identify the location of the second (or first) "Cross" cell. I prepared a case like this by editing the binary file. There are two cells called "A":

    000000127   0d 00                    CELL (0)
    000000129   03 01 41                 CELLNAME ("A")
    000000132   1c 17 00                 PROPERTY (id=0)
    000000135   08 7f                    value[0]=127 (type 8)
    000000137   03 01 41                 CELLNAME ("A")
    000000140   1c 17 00                 PROPERTY (id=0)
    000000143   08 7d                    value[0]=125 (type 8)
    000000145   02                       END
    000000146   01                       tables entry (1)
    

    If the cell name table is not CBLOCK-compressed, you can use a binary editor to change the name to something unique without changing the length. For example "Kross" instead of "Cross" in one place.

    I used "gvim" in binary mode (gvim -b). If you switch to hex mode (Tools/Convert to HEX) you can edit the position of the first name character (it should be plain ASCII). Here I am changing "A" to "B":

    Image

    Convert back to Binary, save and your layout should load again.

    If the cell name table is CBLOCK-compressed (which is likely), things are more difficult. If you are able to send the file on a private channel, I can try fixing it using a patched reader.

    I tried the following patch:

    diff --git a/src/db/db/dbCommonReader.cc b/src/db/db/dbCommonReader.cc
    index b1becdcfb..ffc80be09 100644
    --- a/src/db/db/dbCommonReader.cc
    +++ b/src/db/db/dbCommonReader.cc
    @@ -156,7 +156,8 @@ CommonReaderBase::rename_cell (db::Layout &layout, size_t id, const std::string
       }
     
       if (iname != m_name_map.end () && iname->second.first != null_id && iname->second.first != id) {
    -    common_reader_error (tl::sprintf (tl::to_string (tr ("Same cell name %s, but different IDs: %ld and %ld")), cn, id, iname->second.first));
    +    iname = m_name_map.end ();  // PATCH for ISSUE #2088
    +    // PATCH for ISSUE #2088: common_reader_error (tl::sprintf (tl::to_string (tr ("Same cell name %s, but different IDs: %ld and %ld")), cn, id, iname->second.first));
       }
     
       if (iid != m_id_map.end () && iname != m_name_map.end ()) {
    

    It seems to accept the broken file from above, but leaves one cell as an empty name. If can be renamed then.

    In any case, creating duplicate cell names is a serious flaw. please approach the people doing the litho toolkit - maybe they are doing something weird that screws up KLayout.

    Matthias

  2. liamgconnolly commented on Jul 14, 2025

    @liamgconnolly
    Author

    Thank you for the detailed and thoughtful response Matthias!

    I believe the problem arose after duplicating a collection of shapes including the offending alignment cross (I was able to open a much much older version of the file and see what had changed compared to my newer version, or at least my memory of it). But I'll certainly raise an issue with the actual package (https://github.com/UUhy/LTK).

    Sadly, I believe the file is compressed. I tried messing around with it a bit in a hex editor, and I couldn't get things to work (but of course I'm not exactly an expert here so who knows).

  3. liamgconnolly commented on Jul 14, 2025

    @liamgconnolly
    Author

    Solved thanks to the patch above and rebuilding from source. Many thanks to @klayoutmatthias

  4. klayoutmatthias commented on Jul 14, 2025

    @klayoutmatthias
    Collaborator

    Very good. I can try to turn this message into a warning with a fallback name that is different. Due to the nature of OASIS there is not absolute warranty and OASIS spec is explicit about duplicate cell names (an error).

    I still like to understand how this can happen, but as there may be other odd OASIS files around. So handling this case gracefully makes sense.

    If there are news about a potential loophole in KLayout's OASIS writer, let me know.

    Matthias

  5. liamgconnolly commented on Jul 14, 2025

    @liamgconnolly
    Author

    If I had to guess, I believe it came from duplicating a collection of LTK Cross objects (just simple alignment marks), then selecting them all, then Edit -> Selection -> Change Layer.

    It's a pretty small library though, not sure the author will see the issue in the repo.

    That said, turning the explicit error message -> exit KLayout behavior into a warning + name change would certainly be something nice to have

  6. klayoutmatthias commented on Jul 14, 2025

    @klayoutmatthias
    Collaborator

    Yet, the OASIS writer should have refused to write it .. strange

  7. liamgconnolly commented on Jul 15, 2025

    @liamgconnolly
    Author

    If you want to take a look at the working file I had emailed you, I believe I'm able to replicate the issue by duplicating a collection of the crosses, moving them to a different place on the die, and then while they're all still selected, using the Edit --> Selection --> Change Layer to a different layer.

  8. klayoutmatthias commented on Jul 15, 2025

    @klayoutmatthias
    Collaborator

    Hi @liamgconnolly,

    I finally could reproduce the problem. Thanks a lot for your patience and effort helping to reproduce the issue. I appreciate that attitude as the primary strength of Open Source!

    Technically the problem is partially on my side and partially on LTK's side. BTW: LTK is a nice package - no offense meant!

    What happens is that: LTK generates cell names which are not OASIS compliant. Specifically they contain a blank. For example Shape: Vernier. KLayout will substitute the blank by a * for OASIS compliance. Now, if you load a file with such a name, you have a cell called Shape:*Vernier. Now, when you create a new one, it is again called Shape: Vernier with a blank. The writer checks these names - they are different - but after that, it will replace the blank with a "*" and by doing so, it creates a name clash.

    That should be easy to fix, now I know what causes the problem. I would rephrase the request to LTK so they consider generating compliant names - specifically without a blank. However, there is a problem - when they simply change the names, you cannot open existing files any more. As this is not user friendly, that is not a good solution I'm afraid.

    Hence, I will look for a solution inside KLayout. It's not going to be difficult.

    As of now, I suggest to turn off character substitution as a workaround. Just leave the "Substitution character" field empty:

    Image

    Formally, this will create invalid OASIS files, but only in terms of name strings. If needed, it can be fixed by saving once again with the substitution character in place.

    I will reopen the ticket as this is somewhat of a bug and it needs fixing.

    Best regards,

    Matthias

  9. added this to the 0.30.3 milestone on Jul 15, 2025
  10. added a commit that references this issue on Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions