Skip to main content

hydr_structures/structures/controlled_gate/snapshot/
package.rs

1//! Complete owning child packages without an extra decision-history bridge.
2
3use super::super::ControlledGateBatch;
4use crate::structures::{GateActuatorSnapshotData, OperatingControlSnapshotData, StructureError};
5use numr::dtype::DType;
6use numr::runtime::Runtime;
7
8/// Schema identity of the controlled gate snapshot package.
9pub const CONTROLLED_GATE_SNAPSHOT_SCHEMA: &str = "hydr-controlled-gate-checkpoint-1";
10/// Numerical contract identity of the controlled gate snapshot package.
11pub const CONTROLLED_GATE_CONTRACT_VERSION: &str = "hydr-controlled-gate-numr-cpu-1";
12
13/// Complete caller-owned sampled controls and actual gate response continuation.
14///
15/// Encoding must preserve every child field and original F64 bit, including signed zeros.
16#[derive(Clone, Debug, PartialEq)]
17pub struct ControlledGateSnapshotData {
18    /// Package schema identity.
19    pub schema: String,
20    /// Numerical contract identity.
21    pub contract: String,
22    /// Complete original model, current control memory, and bounded accepted decision receipts.
23    pub controls: OperatingControlSnapshotData,
24    /// Complete original model, actual position proofs, and bounded accepted response receipts.
25    pub actuators: GateActuatorSnapshotData,
26}
27/// Trusted complete composite clone without numerical projection or recursive prior composites.
28#[derive(Clone, Debug)]
29pub struct ControlledGateSnapshot<R: Runtime<DType = DType>> {
30    pub(super) batch: ControlledGateBatch<R>,
31}
32impl<R: Runtime<DType = DType>> ControlledGateSnapshot<R> {
33    /// Common accepted snapshot time in seconds.
34    pub fn time(&self) -> f64 {
35        self.batch.time()
36    }
37    /// Explicitly project both complete caller-owned packages.
38    pub fn data(&self) -> Result<ControlledGateSnapshotData, StructureError> {
39        self.batch.snapshot_data()
40    }
41}
42impl<R: Runtime<DType = DType>> ControlledGateBatch<R> {
43    /// Clone both complete accepted children without derived-state array readback.
44    pub fn snapshot(&self) -> ControlledGateSnapshot<R> {
45        ControlledGateSnapshot {
46            batch: self.clone(),
47        }
48    }
49    /// Explicitly project complete child continuation without inventing additional historical evidence.
50    pub fn snapshot_data(&self) -> Result<ControlledGateSnapshotData, StructureError> {
51        Ok(ControlledGateSnapshotData {
52            schema: CONTROLLED_GATE_SNAPSHOT_SCHEMA.into(),
53            contract: CONTROLLED_GATE_CONTRACT_VERSION.into(),
54            controls: self.controls.snapshot_data()?,
55            actuators: self.actuators.snapshot_data()?,
56        })
57    }
58}