Skip to main content

hydr_structures/structures/
proposal.rs

1//! Opaque immutable proposal tensors with explicit output projection.
2use numr::tensor::Tensor;
3use numr::{dtype::DType, runtime::Runtime};
4
5use super::{StructureError, StructureHeads, StructureOutput};
6use crate::structures::tensor::{TensorStructureContext, TensorStructureResult};
7use std::sync::Arc;
8
9#[derive(Debug)]
10pub(super) struct ProposalData<R: Runtime<DType = DType>> {
11    pub context: Arc<TensorStructureContext<R>>,
12    pub heads: Vec<StructureHeads>,
13    pub result: TensorStructureResult<R>,
14    pub operations: super::operation_projection::ProposalOperations<R>,
15}
16
17/// Immutable constitutive proposals. No donor availability or paired exchange acceptance follows.
18#[derive(Clone, Debug)]
19pub struct StructureProposal<R: Runtime<DType = DType>> {
20    pub(super) inner: Arc<ProposalData<R>>,
21}
22impl<R: Runtime<DType = DType>> StructureProposal<R> {
23    pub(super) fn new(
24        context: Arc<TensorStructureContext<R>>,
25        heads: Vec<StructureHeads>,
26        operations: Vec<super::StructureOperation>,
27        result: TensorStructureResult<R>,
28    ) -> Self {
29        Self {
30            inner: Arc::new(ProposalData {
31                context,
32                heads,
33                result,
34                operations: super::operation_projection::ProposalOperations::Supplied(operations),
35            }),
36        }
37    }
38    pub(crate) fn from_trajectory(
39        context: Arc<TensorStructureContext<R>>,
40        heads: Vec<StructureHeads>,
41        evaluation: Arc<super::GateTrajectoryEvaluationData<R>>,
42        other: Vec<super::StructureOperation>,
43        result: TensorStructureResult<R>,
44    ) -> Self {
45        Self {
46            inner: Arc::new(ProposalData {
47                context,
48                heads,
49                result,
50                operations: super::operation_projection::ProposalOperations::Trajectory {
51                    evaluation,
52                    other,
53                },
54            }),
55        }
56    }
57    pub(crate) fn from_derived(
58        context: Arc<TensorStructureContext<R>>,
59        heads: Vec<StructureHeads>,
60        manual: Vec<super::StructureOperation>,
61        derived_slots: Vec<usize>,
62        opening: Tensor<R>,
63        pumps: Option<crate::structures::tensor::DerivedPumpOperationData<R>>,
64        result: TensorStructureResult<R>,
65    ) -> Self {
66        Self {
67            inner: Arc::new(ProposalData {
68                context: Arc::clone(&context),
69                heads,
70                result,
71                operations: super::operation_projection::ProposalOperations::Derived {
72                    context,
73                    slots: derived_slots,
74                    opening,
75                    pumps: pumps.map(Box::new),
76                    manual,
77                },
78            }),
79        }
80    }
81    /// Project complete ordered operations without repeating trajectory evaluation.
82    pub fn operations(&self) -> Result<Vec<super::StructureOperation>, StructureError> {
83        super::operation_projection::project(&self.inner.operations)
84    }
85    /// Project original support, physical regime, ideal-flap status, and active law operands.
86    pub fn outputs(&self) -> Result<Vec<StructureOutput>, StructureError> {
87        super::projection::outputs(&self.inner)
88    }
89}