Skip to main content

hydr_structures/structures/gate/trajectory/
evaluation.rs

1//! Opaque immutable point tensors with explicit gate-only projections.
2use numr::{dtype::DType, runtime::Runtime};
3
4use super::binding::GateTrajectoryData;
5use crate::structures::tensor::gate::trajectory::TrajectoryPointMetadata;
6use crate::structures::{StructureError, StructureOperatingPoint, StructureOperation};
7use numr::tensor::Tensor;
8use std::sync::Arc;
9
10#[derive(Debug)]
11pub(crate) struct GateTrajectoryEvaluationData<R: Runtime<DType = DType>> {
12    pub binding: Arc<GateTrajectoryData<R>>,
13    pub time_s: f64,
14    pub opening: Tensor<R>,
15    pub absolute_error: Tensor<R>,
16    pub metadata: Vec<TrajectoryPointMetadata>,
17}
18/// Immutable tensor-backed prescribed point. Projection never repeats interpolation.
19#[derive(Clone, Debug)]
20pub struct GateTrajectoryEvaluation<R: Runtime<DType = DType>> {
21    pub(crate) inner: Arc<GateTrajectoryEvaluationData<R>>,
22}
23/// One explicitly projected gate point and original-time support metadata.
24#[derive(Clone, Debug, PartialEq)]
25pub struct GateTrajectoryOutput {
26    /// Element index in the complete structure batch.
27    pub element: usize,
28    /// Original structure identity.
29    pub structure_id: String,
30    /// Original query time in seconds.
31    pub time_s: f64,
32    /// Represented opening in metres.
33    pub opening_m: f64,
34    /// Solvr absolute error enclosure in metres.
35    pub absolute_error_m: f64,
36    /// Right-sided original segment, except at the terminal knot.
37    pub segment_index: usize,
38    /// Original knot index when time equality holds.
39    pub exact_knot_index: Option<usize>,
40    /// Original zero knot or zero plateau contains the query.
41    pub closed_by_definition: bool,
42}
43impl<R: Runtime<DType = DType>> GateTrajectoryEvaluation<R> {
44    /// Original supported query time.
45    pub fn time_s(&self) -> f64 {
46        self.inner.time_s
47    }
48    /// Project gate rows in original gate subsequence order.
49    pub fn outputs(&self) -> Result<Vec<GateTrajectoryOutput>, StructureError> {
50        let data = &self.inner;
51        let n = data.binding.context.elements.len();
52        let opening = crate::structures::projection::read(&data.opening, n)?;
53        let error = crate::structures::projection::read(&data.absolute_error, n)?;
54        Ok(data
55            .binding
56            .slots
57            .iter()
58            .zip(&data.metadata)
59            .map(|(&element, metadata)| GateTrajectoryOutput {
60                element,
61                structure_id: data.binding.context.elements[element].id.clone(),
62                time_s: data.time_s,
63                opening_m: opening[element],
64                absolute_error_m: error[element],
65                segment_index: metadata.segment_index,
66                exact_knot_index: metadata.exact_knot_index,
67                closed_by_definition: metadata.closed_by_definition,
68            })
69            .collect())
70    }
71    /// Project gate-only identity-bound operation packets.
72    pub fn operations(&self) -> Result<Vec<StructureOperation>, StructureError> {
73        let data = &self.inner;
74        let opening = crate::structures::projection::read(
75            &data.opening,
76            data.binding.context.elements.len(),
77        )?;
78        Ok(data
79            .binding
80            .slots
81            .iter()
82            .map(|&element| StructureOperation {
83                structure_id: data.binding.context.elements[element].id.clone(),
84                operating_point: StructureOperatingPoint::GateOpening {
85                    opening_m: opening[element],
86                },
87            })
88            .collect())
89    }
90}