|
| 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