ICplxTrans' `to_bytes` and `from_bytes` use different primitive data types (int on write, float on read)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
The bug is in the reader in src/db/db/dbBinarySerialize.h around lines 446-463, where ICplxTrans displacement is read as R (double) but written as D (int). Start by reproducing the Python round trip from the issue and checking the displacement after from_bytes. Done when ICplxTrans(Trans(x=10000, y=-2000)) survives to_bytes/from_bytes unchanged and the existing binary format still works.
Written by the indexing model from the issue text.
Description
Hi Matthias,
I found an asymmetry in ICplxTrans.to_bytes() and ICPlxTrans.from_bytes (a clanker helped me analyze the precise error which seems to come from klayout).
Small clanker analysis bleow:
In KLayout 0.30.13, an ICplxTrans with a displacement does not survive a to_bytes() / from_bytes() round trip.
import klayout.db as kdb
original = kdb.ICplxTrans(kdb.Trans(x=10000, y=-2000))
restored = kdb.ICplxTrans.from_bytes(original.to_bytes())
print(original) # r0 *1 10000,-2000
print(restored) # r0 *1 0,nan
assert restored == original # fails
The displacement is present in the serialized bytes. In dbBinarySerialize.h (https://github.com/KLayout/klayout/blob/v0.30.13/src/db/db/dbBinarySerialize.h#L446-L463), the writer stores it using the output coordinate type D, but the reader reads it using the internal representation type R. For ICplxTrans, those are integer and double respectively, so the coordinate bytes are interpreted as floating point values.
Suggested minimal fix for the reader:
- db::vector<R> d;
+ db::vector<D> d;
read_binary (s, d);
double asin, acos, mag;
s >> asin >> acos >> mag;
- t = db::complex_trans<C, D, R> (d, asin, acos, mag);
+ t = db::complex_trans<C, D, R> (db::vector<R> (d), asin, acos, mag);
This keeps the existing binary format and reads its displacement using the type with which it was written.
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 305
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 11
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from KLayout/klayout
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
KLayout/klayout#2412 · 3 comments ·
Maintainers usually reply within 1 day
-
DRC functions not working properly with clip in placePossibly taken @klayoutmatthias claimed this today. Openbug
KLayout/klayout#2553 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
Maintainers usually reply within 1 day
-
Deep DRC can miss violations when a cell has many shapesMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
KLayout/klayout#2546 · 5 comments ·
Maintainers usually reply within 1 day
-
Python API: edge neighborhood nodes retain visitors after leaving scopePossibly taken @klayoutmatthias claimed this 4 days ago. Openbug
KLayout/klayout#2542 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
LaneDibello/Kotor-Patch-Manager#375 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day