Add QuantumProgram to providers crate - #16924
Open
Ian Hincks (ihincks) wants to merge 1 commit into
Open
Conversation
Coverage Report for CI Build 34398812926Coverage increased (+0.02%) to 88.045%Details
Uncovered Changes
Coverage Regressions10 previously-covered lines in 2 files lost coverage.
Coverage Stats
💛 - Coveralls |
Collaborator
|
One or more of the following people are relevant to this code:
|
3 tasks
Ian Hincks (ihincks)
force-pushed
the
ihincks/qp-06-quantum-program
branch
from
September 9, 2026 17:39
55b75f0 to
8b926bd
Compare
A quantum program is a collection of program functions, the last of which is its entry point, together with one input structure and one output structure. A caller hands over a data tree of inputs arranged as the program declares and receives a tree of outputs arranged the same way, so an answer arrives organised the way it was asked for. Everything between those two boundaries stays positional, since the structures are where all naming lives. The structures describe the entry point, because the entry point is what a caller invokes, so a program carries one pair and a function carries none. Assembling one checks that there is a function to enter at — every accessor reads through the last one — and then that each structure has as many leaves as the entry point has parameter and result instructions. Correspondence between a structure's leaves and a function's slots rests on order, and that leaf count is the only structural check there is: nothing maps between the two, so whoever builds a program adds its boundary instructions in the order its structures declare. Evaluating checks the supplied arrangement against the declared one before computing anything, and reports both structures whole, so that a caller sees the arrangement that was wanted beside the one it supplied. Rendering a structure as a skeleton, `[counts: [_, _], shots: _]`, is what makes that message legible. The declared type of every input and output is available without evaluating, arranged in the structure it belongs to, and `DataTree::dotted_paths` addresses each output from the output structure. The structure is the thing worth keeping, since a set of paths cannot reconstruct it: an empty branch contributes no leaves, and so no path.
Matthew Treinish (mtreinish)
force-pushed
the
ihincks/qp-06-quantum-program
branch
from
September 9, 2026 20:04
8b926bd to
9a432c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the
QuantumProgramstruct with owns a vector ofQuantumFunction.The
QuantumProgramhas some well-typedness/type safety requirements. These requirementsultimately stem from the expense of quantum compute resources: we never want to end
up in a situation where a program fails and quantum resources are effectively wasted
because the program was somehow malformed and a runtime error occurs during the classical
parts of a program. We want every instruction to have a well-defined result type, and the that
the validitiy of and result type of every operation is determined statically from the IR
itself.
To this end, the
QuantumProgramenforces several structural invariants intended to prevent malformed programs from reaching execution time. In particular, the IR maintains:Notably, some operations permit implicit type promotion (e.g. combining
i32andf64). However, the resulting type is still determined statically and recorded in the IR.On construction, each function is traversed looking for function call instructions.
All function calls must point at a function that exists at a (strictly) previous
location in the list, and the type signature must be correct. If it is not, then
program construction fails. Functions are already checked for self-consistency during their construction.
As a result of the function call rule, we use the convention that the last function in
a program is its entry point; code after this is by construction dead code.
We also assign
DataTree<TensorType>structures to both the input and output of theentry function. These are zipped against the positional slots of the function's inputs
and ouputs in the DFS order defined by the data tree API. These data trees are for
the convenience of users who want to format the stucture of their data, or assign names
to them.
AI/LLM disclosure
Stack created with GitHub Stacks CLI • Give Feedback 💬