ICplxTrans' `to_bytes` and `from_bytes` use different primitive data types (int on write, float on read)

Đang mở Phù hợp với người mới
#2,554 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp, python
Lĩnh vực
backend

Hướng nghiên cứu

Lỗi nằm ở bộ đọc trong src/db/db/dbBinarySerialize.h quanh các dòng 446-463, nơi độ dịch chuyển của ICplxTrans được đọc là R (double) nhưng ghi là D (int). Bắt đầu bằng cách tái hiện vòng khứ hồi Python trong issue và kiểm tra độ dịch chuyển sau from_bytes. Hoàn thành khi ICplxTrans(Trans(x=10000, y=-2000)) đi qua to_bytes/from_bytes mà không thay đổi và định dạng nhị phân hiện có vẫn hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
1.2k
Fork
305
Merge trung bình
3 ngày 2 giờ
Pull request đã merge (30 ngày)
11

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của KLayout/klayout

Tất cả issue của KLayout/klayout

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.