use numr::{dtype::DType, runtime::Runtime};
use super::binding::GateTrajectoryData;
use crate::structures::tensor::gate::trajectory::TrajectoryPointMetadata;
use crate::structures::{StructureError, StructureOperatingPoint, StructureOperation};
use numr::tensor::Tensor;
use std::sync::Arc;
#[derive(Debug)]
pub(crate) struct GateTrajectoryEvaluationData<R: Runtime<DType = DType>> {
pub binding: Arc<GateTrajectoryData<R>>,
pub time_s: f64,
pub opening: Tensor<R>,
pub absolute_error: Tensor<R>,
pub metadata: Vec<TrajectoryPointMetadata>,
}
#[derive(Clone, Debug)]
pub struct GateTrajectoryEvaluation<R: Runtime<DType = DType>> {
pub(crate) inner: Arc<GateTrajectoryEvaluationData<R>>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct GateTrajectoryOutput {
pub element: usize,
pub structure_id: String,
pub time_s: f64,
pub opening_m: f64,
pub absolute_error_m: f64,
pub segment_index: usize,
pub exact_knot_index: Option<usize>,
pub closed_by_definition: bool,
}
impl<R: Runtime<DType = DType>> GateTrajectoryEvaluation<R> {
pub fn time_s(&self) -> f64 {
self.inner.time_s
}
pub fn outputs(&self) -> Result<Vec<GateTrajectoryOutput>, StructureError> {
let data = &self.inner;
let n = data.binding.context.elements.len();
let opening = crate::structures::projection::read(&data.opening, n)?;
let error = crate::structures::projection::read(&data.absolute_error, n)?;
Ok(data
.binding
.slots
.iter()
.zip(&data.metadata)
.map(|(&element, metadata)| GateTrajectoryOutput {
element,
structure_id: data.binding.context.elements[element].id.clone(),
time_s: data.time_s,
opening_m: opening[element],
absolute_error_m: error[element],
segment_index: metadata.segment_index,
exact_knot_index: metadata.exact_knot_index,
closed_by_definition: metadata.closed_by_definition,
})
.collect())
}
pub fn operations(&self) -> Result<Vec<StructureOperation>, StructureError> {
let data = &self.inner;
let opening = crate::structures::projection::read(
&data.opening,
data.binding.context.elements.len(),
)?;
Ok(data
.binding
.slots
.iter()
.map(|&element| StructureOperation {
structure_id: data.binding.context.elements[element].id.clone(),
operating_point: StructureOperatingPoint::GateOpening {
opening_m: opening[element],
},
})
.collect())
}
}