[Circuit renderer] Support user-provided input sizes for circuit rendering - #3658
[Circuit renderer] Support user-provided input sizes for circuit rendering#3658Dima Fedoriaka (fedimser) wants to merge 8 commits into
Conversation
|
Change in memory usage detected by benchmark. Memory Report for 6e24b73
|
There was a problem hiding this comment.
Pull request overview
This PR extends the Q# compiler’s circuit rendering pipeline to support user-specified qubit-array input lengths via a new inputSizes option on @CircuitRenderingOptions(...), flowing from frontend attribute parsing through HIR/FIR lowering and into circuit entry-expression generation.
Changes:
- Added
input_sizes: Option<Vec<u32>>toCircuitRenderingOptionsin both HIR and FIR, and plumbed it through HIR→FIR lowering. - Implemented parsing of
inputSizes=...in frontend lowering (;-separated list, positive integers). - Updated circuit entry-expression generation to allocate/slice qubits based on the configured sizes, with new unit tests covering single/multiple/missing/extra sizes.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| source/compiler/qsc_lowerer/src/lib.rs | Propagates input_sizes when lowering CircuitRenderingOptions from HIR to FIR. |
| source/compiler/qsc_hir/src/hir.rs | Adds input_sizes to HIR options and documents inputSizes semantics. |
| source/compiler/qsc_frontend/src/lower.rs | Parses inputSizes from @CircuitRenderingOptions(...) strings into HIR. |
| source/compiler/qsc_frontend/src/lower/tests.rs | Adds a frontend lowering test asserting inputSizes is parsed into HIR attrs. |
| source/compiler/qsc_fir/src/fir.rs | Adds input_sizes to FIR CircuitRenderingOptions. |
| source/compiler/qsc_circuit/src/operations.rs | Applies inputSizes to qubit-array parameters and uses sizes in entry-expression generation. |
| source/compiler/qsc_circuit/src/operations/tests.rs | Adds circuit entry-expression tests for size application behavior. |
| source/compiler/qsc_circuit/src/builder/tests.rs | Updates a QubitParam test literal to include the new size field. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
I would prefer array syntax for the list of sizes rather than semicolon separated integers. So |
But the comma is already reserved for key-value pair separator! So you can do this: Sure, we can support syntax |
I think maybe there is something deeper going on here, because you keep using quotes and mentioned a needing a parser. If you skip the quotes, you can make use of the existing Q# parser that should already handle all of this for you. Let me try to put together an example to show what I mean. |
|
Change in memory usage detected by benchmark. Memory Report for 54e86c5
|
|
Change in memory usage detected by benchmark. Memory Report for 62272f9
|
|
Change in memory usage detected by benchmark. Memory Report for b607e1a
|
|
Change in memory usage detected by benchmark. Memory Report for b0b67af
|
|
Change in memory usage detected by benchmark. Memory Report for bed3110
|
|
Change in memory usage detected by benchmark. Memory Report for d56c1ee
|
| The argument is a string containing comma-separated `key=value` pairs. Keys are case-insensitive. | ||
|
|
@CircuitRenderingOptions(inputSizes=[...]), which means that if a circuit is rendered for this operation, Qubit[]-typed inputs will have size as specified ininputSizesarray.Qubit[][], Qubit[], Qubit[][]andinput_sizes=[1,2,3,4,5], then for rendering we will alocate arraysQubit[1][2], Qubit[3], Qubit[4][5].@CircuitRenderingOptions(hideBox=true).Example