feat: add quantum memory layout #118
Conversation
|
I have created the PR with main branch instead of arch-scafold branch cc @Doomsk |
|
Hey @Gmin2 thanks for opening this PR. You have signalled that this PR was partially done with help of an LLM. Can you replace the X% by an estimate? Regarding your comment, it's better to have it merged to the arc_scaffold branch rather than the main one. |
Done
Done and also I had run a small example that was given in the haeder example in the issue and run it and it produce Should i also include the example ?? cc @Doomsk |
|
@Gmin2 thanks! You can include as tests it they are relevant and add any other useful point you think is worth mentioning, such as why you chose the fields you chose from the |
|
Hey @Doomsk why my pr was not reviewed at all?? |
|
@Gmin2 glad that you finally replied. I was waiting for the tests and you never replied. |
Closes #113
this adds the quantum counterpart to hhat_core, right next to it. The difference is that it counts qubits instead of bytes and uses no alignment or padding, primitives report their qubit count (@Bool is 1, up to @U8 at 8), structs sum their members back-to-back, and a two-variant enum takes one qubit. There's also a small cache so layouts aren't recomputed, a primitive instruction type that carries an ancilla count, and a public QuantumProgram that's built when a variable is cast and works out the total qubits (data plus ancillas) and the classical register size. Along the way I fixed a bug where any struct with quantum members panicked in the classical layout pass.
I checked it by driving the layout with the language's own examples: @bell_t comes out as 2 qubits (fields at 0 and 1), @polarization as 1, and a nested type as 7. Running the full @v:@bell_t example with a dummy @sync instruction gives two data qubits plus its ancillas and a one-bit creg (only @v.@t is cast), so totals move 2, 3, 4, 5 — matching the OpenQASM sketch in the issue. Arrays are still left as a todo!().
Generative AI/LLM disclosure
I used an AI assistant to help me understand how the existing type and layout system works, how Ty, TypeLayout and the classical LayoutCache fit together and how quantum types should map onto it (qubit counts, structs, enums, ancillas).
Code and Logic Architecture/Design:
Code content:
Code review:
Code tests: