Generate QLT IR for all bloq examples - #1926
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces tools and libraries to build and verify an on-disk library of Qualtran-L1 (.qlt) files from BloqExamples, including a new driver script, shell script, and core build logic. Feedback on the changes highlights three critical issues: first, the use of Unix-only signal APIs (setitimer and SIGALRM) in _library.py will cause crashes on Windows and in multi-threaded environments; second, the newly added __str__ methods on both Join and Split bloqs reference a non-existent num_bits attribute on QDType instead of num_qubits, which will raise an AttributeError when called.
| if not seconds or seconds <= 0: | ||
| yield | ||
| return |
There was a problem hiding this comment.
The signal.setitimer and signal.SIGALRM APIs are Unix-only and will raise an AttributeError on Windows. Additionally, signal.signal can only be called from the main thread; calling it from a background thread (e.g., in a multi-threaded test runner or worker pool) will raise a ValueError. To prevent hard crashes in these environments, we should check for the presence of these APIs and ensure we are running on the main thread before attempting to set a timeout.
import threading
if (
not seconds
or seconds <= 0
or not hasattr(signal, 'SIGALRM')
or not hasattr(signal, 'setitimer')
or threading.current_thread() is not threading.main_thread()
):
yield
return
Build an on-disk library of verified Qualtran-L1 (
.qlt) files from bloqs.Given a
(bloq, name)pair and a root directory,build_library_entryruns thefull L1 pipeline for that bloq:
.qltfile (qualtran.l1.dump_l1)..qltfile back into bloqs (qualtran.l1.load_module).StandardQualtranArchitectureAgnosticVirtualMachine.This is the basic infrastructure. Future PRs will investigate and/or fix the failure cases.