Skip to content

Implement ProgramNode#16106

Open
ihincks wants to merge 13 commits intoQiskit:mainfrom
ihincks:ih/quantum_program_operation
Open

Implement ProgramNode#16106
ihincks wants to merge 13 commits intoQiskit:mainfrom
ihincks:ih/quantum_program_operation

Conversation

@ihincks
Copy link
Copy Markdown
Contributor

@ihincks ihincks commented Apr 29, 2026

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

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code: Claude 4.6

mtreinish and others added 6 commits April 28, 2026 13:34
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.
@ihincks ihincks requested a review from a team as a code owner April 29, 2026 19:58
@ihincks ihincks added Rust This PR or issue is related to Rust code in the repository mod: providers Related to the backend and job abstractions labels Apr 29, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@ihincks ihincks marked this pull request as draft April 29, 2026 20:04
@ihincks ihincks mentioned this pull request Apr 29, 2026
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 29, 2026

Coverage Report for CI Build 25218259735

Coverage decreased (-0.09%) to 87.477%

Details

  • Coverage decreased (-0.09%) from the base build.
  • Patch coverage: 248 uncovered changes across 3 files (646 of 894 lines covered, 72.26%).
  • 9 coverage regressions across 2 files.

Uncovered Changes

File Changed Covered %
crates/providers/src/tensor.rs 341 170 49.85%
crates/providers/src/data_tree.rs 464 397 85.56%
crates/providers/src/store.rs 86 76 88.37%

Coverage Regressions

9 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
crates/qasm2/src/parse.rs 6 97.63%
crates/qasm2/src/lex.rs 3 91.77%

Coverage Stats

Coverage Status
Relevant Lines: 122243
Covered Lines: 106935
Line Coverage: 87.48%
Coverage Strength: 961849.58 hits per line

💛 - Coveralls

@ShellyGarion ShellyGarion added this to the 2.5.0 milestone Apr 30, 2026
@ihincks ihincks force-pushed the ih/quantum_program_operation branch 2 times, most recently from cb4cdba to bda047a Compare April 30, 2026 20:30
Comment thread crates/providers/src/program_node.rs Outdated
Comment on lines +19 to +22
fn name(&self) -> &'static str;

/// The namespace this program node belongs to.
fn namespace(&self) -> &'static str;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, fixed in 1c2eb52

Comment thread crates/providers/src/program_node.rs Outdated
Comment thread crates/providers/src/store.rs Outdated
Comment on lines +70 to +71
static EMPTY: OnceLock<DataTree<TensorType>> = OnceLock::new();
EMPTY.get_or_init(DataTree::new)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

@ihincks ihincks May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ihincks ihincks force-pushed the ih/quantum_program_operation branch from 1cf3d38 to 1c2eb52 Compare May 1, 2026 14:32
@ihincks ihincks marked this pull request as ready for review May 1, 2026 14:57
@qiskit-bot
Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod: providers Related to the backend and job abstractions Rust This PR or issue is related to Rust code in the repository

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

Implement ProgramNode trait

5 participants