Skip to content

Commit 9ffc188

Browse files
committed
Add ProgramNode
1 parent 23e7055 commit 9ffc188

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/providers/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ name = "qiskit_providers"
1212
rustworkx-core.workspace = true
1313
anyhow.workspace = true
1414
num-complex.workspace = true
15+
thiserror.workspace = true
1516

1617
[dependencies.hashbrown]
1718
workspace = true

crates/providers/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@
1111
// that they have been altered from the originals.
1212

1313
mod data_tree;
14+
mod program_node;
15+
mod store;
1416
pub mod tensor;
17+
1518
pub use data_tree::{DataTree, PathEntry};
19+
pub use program_node::ProgramNode;
20+
pub use store::Store;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This code is part of Qiskit.
2+
//
3+
// (C) Copyright IBM 2026
4+
//
5+
// This code is licensed under the Apache License, Version 2.0. You may
6+
// obtain a copy of this license in the LICENSE.txt file in the root directory
7+
// of this source tree or at https://www.apache.org/licenses/LICENSE-2.0.
8+
//
9+
// Any modifications or derivative works of this code must retain this
10+
// copyright notice, and modified files need to carry a notice indicating
11+
// that they have been altered from the originals.
12+
13+
use crate::data_tree::DataTree;
14+
use crate::tensor::{Tensor, TensorType};
15+
16+
/// A node in a quantum program graph that transforms tensors.
17+
pub trait ProgramNode {
18+
/// The name of this program node.
19+
fn name(&self) -> &'static str;
20+
21+
/// The namespace this program node belongs to.
22+
fn namespace(&self) -> &'static str;
23+
24+
/// The namespace and name as one string.
25+
fn full_name(&self) -> String {
26+
format_args!("{}.{}", self.namespace(), self.name()).to_string()
27+
}
28+
29+
/// The inputs expected at `call` time.
30+
fn input_types(&self) -> &DataTree<TensorType>;
31+
32+
/// The outputs promised on `call` return.
33+
fn output_types(&self) -> &DataTree<TensorType>;
34+
35+
/// Whether this program node implements the call method.
36+
fn implements_call(&self) -> bool;
37+
38+
/// The action of this program node.
39+
fn call(&self, args: &DataTree<Tensor>) -> anyhow::Result<DataTree<Tensor>>;
40+
}

0 commit comments

Comments
 (0)