Add quantum memory layout for quantum data#145
Conversation
|
@spital according to the AI policies of the repository, no fully automated PRs are allowed. I'm closing it. |
|
As mentioned in the last PR Hi Doomsk, Thank you for taking the time to comment. I understand and respect the repository policy. I also understand that, regardless of what tools I used while working on this, I am responsible for the code I submit and for anything it ships. This PR was not a "spray and pray" submission. I spent a lot of time getting it to this state, reviewing the changes, testing them, and trying to make sure the result is useful to the project. I believe the PR is still worth a technical review, but I respect your decision either way. My motivation here is simply to contribute something valuable to open source while I am looking for paid remote work. I do not have any questions at this point. If you are curious about how I approached the work, feel free to ping me here or on the unitaryhack-26 Discord and I would be happy to chat. Thanks again. |
|
@spital you didn't even check the PR message the LLM placed, where it had to fill in the AI disclosure and it marked all the fields as "The content are fully performed by generative AI/LLM". I won't spend more time discussing it here. However, feel free to reach me out on Discord. |
Closes #113
(replaces #124 )
Summary
Adds a padding-free quantum memory layout layer for
hhat_core, plus a publicQuantumProgramaggregate for tracking quantum variables, instruction ancillaqubits, casted quantum attributes, and classical register width needed by later
Q3L lowering/emitters.
The implementation focuses on the reusable layout and accounting layer requested
in #113. It does not claim to complete the full cast-time Q3L lowering pipeline.
What's included
@bool,@u2,@u3,@u4,@u8) while keeping those types zero-sized/zero-aligned in the classicalCranelift-facing layout.
padding.
current enum contract.
TypeLayoutvalues into quantum layouts.QuantumProgramAPIs for variables, quantum instructions, ancillacounts, casted attributes, and classical register accounting.
classical_registers()double-counting risk at the reader andproducer call sites.
Design notes
qubits.
quantum offsets.
classical_registers()intentionally counts one classical register bit permeasured qubit recorded through casted attributes or explicit instruction
registers. Callers should record each measured qubit through one path.
TypeLayoutintegration is scaffolded around the currentLayoutCachelimitations. The direct quantum layout cache already supportstwo-variant enums and static arrays.
Testing
cargo test -p hhat_core- 13 passed, doctests passed.cargo test --workspace --exclude hhat_lang- all tests passed.RUSTDOCFLAGS='-D rustdoc::broken_intra_doc_links' cargo doc -p hhat_core --no-deps- passed.Coverage includes primitive quantum widths, simple and nested quantum structs,
two-variant quantum enums, static arrays, mixed classical/quantum structs,
TypeLayoutconversion, casted classical registers, and ancilla sweeps from0 through 3.
Out of scope / known existing issues
cargo test -p hhat_langstill fails on the pre-existing hardcoded fixturepath assertion in
src/ir/project.rs:241.cargo clippy -p hhat_corestill reports 8 pre-existing warnings inlayout/adt.rsandlayout/base.rs; none are in the new quantum layoutmodule.
unrelated formatting churn.
Follow-up work after this lands
path.
TypeLayoutconversion once the classicalLayoutCacheexposes the needed enum/array layout information.
Generative AI/LLM disclosure
I used Codex, Claude, and Hermes as AI assistants to help prototype, review, compare related approaches, and draft PR text. I manually reviewed the resulting diff, checked the live GitHub issue/PR state and unitaryHACK policy, refined the implementation, and ran the tests listed above locally. The PR is submitted with human oversight; any remaining mistakes are mine.
Code and Logic Architecture/Design:
Code content:
Code review:
Code tests: