Implement ProgramNode#16106
Conversation
This commit adds a new data structure to the new providers crate DataTree. The DataTree is a generic tree structure that will be used to define the operation ports in the QuantumProgram's tensor compute graph's nodes. Right now this is just one of the building blocks towards defining the QuantumProgram. As it isn't being used right now since the rest of the components don't exist yet, this is solely self tested. When subsequent components are added tests using the DataTree as part of Operation types and eventually in a QuantumProgram will be needed as well.
This commit adds a new type PathEntry that is used to outline a path through the DataTree into a leaf node. Along with this are two new methods to lookup a leaf node by a path and also to traverse the tree to get leaf nodes along with the path to that node.
This commit changes the type hierarchy for DataTree to move the struct from being a vec of enums of either leaves or branches. To each DataTree being an enum of either a leaf or branch and each branch contains a vec of DataTrees. This is a more natural form as the outer type can either be a leaf or branch and simplifies working with the tree.
|
One or more of the following people are relevant to this code:
|
Coverage Report for CI Build 25218259735Coverage decreased (-0.09%) to 87.477%Details
Uncovered Changes
Coverage Regressions9 previously-covered lines in 2 files lost coverage.
Coverage Stats
💛 - Coveralls |
cb4cdba to
bda047a
Compare
| fn name(&self) -> &'static str; | ||
|
|
||
| /// The namespace this program node belongs to. | ||
| fn namespace(&self) -> &'static str; |
There was a problem hiding this comment.
I'm not sure static here is the right choice, I would expect this to be an issue for custom node types defined in Python and/or C where they're defined outside of Qiskit. We can just make this &str and define our built-in program nodes as static strings.
| static EMPTY: OnceLock<DataTree<TensorType>> = OnceLock::new(); | ||
| EMPTY.get_or_init(DataTree::new) |
There was a problem hiding this comment.
Could you move the static definition outside of the method definition and give it a comment about having a single empty data tree definition to avoid reallocation on each store. The other thing is why do we need a OnceLock here? Couldn't we use a OnceCell, unless you're thinking we're going to be calling this from a threaded context. The other thought is lazy_static is an option here too.
There was a problem hiding this comment.
Could you move the static definition outside of the method definition
I'm happy to, but I'd like to know why. Isn't it a bit more readable to put it inside the method when only one method needs it?
The other thing is why do we need a OnceLock here? Couldn't we use a OnceCell
It's because static variables are always Sync and OnceCell is explicitly not Sync. Looking into lazy_static, it looks like it's been superseded by LazyOnce and LazyCell.
I made a change in 1c2eb52, but am happy to iterate it. It's worth getting the pattern right because many other nodes will want to copy it.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
1cf3d38 to
1c2eb52
Compare
|
One or more of the following people are relevant to this code:
|
This PR closes #16029 by defining a trait called
ProgramNode. It also implements a simple core node (Store) just to show the idea of what a simple node definition will be, albeit a slightly weird one in that it requires an empty input tree.PR Stack
AI/LLM disclosure