Skip to main content

hydr_structures/structures/control/snapshot/
package.rs

1//! Complete caller-owned continuation and trusted tensor snapshots.
2
3use super::super::{
4    ControlDecisionSchedule, ControlInitialState, ControlState, ControlStepDiagnostics,
5    OperatingControlBatch, OperatingControlDefinition, SampledControlTiming,
6};
7use crate::structures::{StructureElement, StructureError};
8use numr::dtype::DType;
9use numr::runtime::Runtime;
10
11/// Schema identity of the operating control snapshot package.
12pub const OPERATING_CONTROL_SNAPSHOT_SCHEMA: &str = "hydr-operating-control-checkpoint-2";
13/// Numerical contract identity of the operating control snapshot package.
14pub const OPERATING_CONTROL_CONTRACT_VERSION: &str = "hydr-operating-control-numr-cpu-1";
15
16/// Complete caller-owned control continuation. Preserve every original F64 bit when encoding.
17#[derive(Clone, Debug, PartialEq)]
18pub struct OperatingControlSnapshotData {
19    /// Package schema identity.
20    pub schema: String,
21    /// Numerical contract identity.
22    pub contract: String,
23    /// Complete immutable actual structure definitions.
24    pub elements: Vec<StructureElement>,
25    /// Original ordered controller definitions.
26    pub definitions: Vec<OperatingControlDefinition>,
27    /// Complete assumed initial memory and antecedents.
28    pub initial_states: Vec<ControlInitialState>,
29    /// Complete original future decision schedule.
30    pub schedule: ControlDecisionSchedule,
31    /// Original sampled applicability and timing policy.
32    pub timing: SampledControlTiming,
33    /// Accepted time in seconds.
34    pub time_s: f64,
35    /// Index of the first unprocessed original decision.
36    pub next_decision_index: usize,
37    /// Accepted original interval count.
38    pub accepted_steps: usize,
39    /// Complete current controller continuation.
40    pub states: Vec<ControlState>,
41    /// Complete last accepted interval, absent before any accepted interval.
42    pub last_step: Option<ControlStepDiagnostics>,
43}
44/// Trusted complete tensor clone without explicit projection or history chains.
45#[derive(Clone, Debug)]
46pub struct OperatingControlSnapshot<R: Runtime<DType = DType>> {
47    pub(super) batch: OperatingControlBatch<R>,
48}
49impl<R: Runtime<DType = DType>> OperatingControlSnapshot<R> {
50    /// Accepted snapshot time in seconds.
51    pub fn time(&self) -> f64 {
52        self.batch.time()
53    }
54    /// Explicitly project complete caller-owned values.
55    pub fn data(&self) -> Result<OperatingControlSnapshotData, StructureError> {
56        self.batch.snapshot_data()
57    }
58}
59impl<R: Runtime<DType = DType>> OperatingControlBatch<R> {
60    /// Clone complete trusted continuation without state projection.
61    pub fn snapshot(&self) -> OperatingControlSnapshot<R> {
62        OperatingControlSnapshot {
63            batch: self.clone(),
64        }
65    }
66    /// Explicitly project every value required for equivalent future continuation.
67    pub fn snapshot_data(&self) -> Result<OperatingControlSnapshotData, StructureError> {
68        Ok(OperatingControlSnapshotData {
69            schema: OPERATING_CONTROL_SNAPSHOT_SCHEMA.into(),
70            contract: OPERATING_CONTROL_CONTRACT_VERSION.into(),
71            elements: self.elements().to_vec(),
72            definitions: self.definitions().to_vec(),
73            initial_states: self.initial_states().to_vec(),
74            schedule: self.schedule().clone(),
75            timing: self.timing().clone(),
76            time_s: self.time,
77            next_decision_index: self.next_decision,
78            accepted_steps: self.steps,
79            states: self.states()?,
80            last_step: self.last_step()?,
81        })
82    }
83}