use crate::execution::ExecutionContext;
use crate::resource::WorkLedger;
use super::reconstruction::reconstruct;
use super::resources::estimate_work;
use super::resources::memory_preflight;
use super::{
INDIRECT_ZERO_FILL, IstError, IstInput, IstOptions, IstOutput, M_MEASURED, N_LOGICAL,
validate_options,
};
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct PhaseCovariantGroupRetainedIstV1;
impl PhaseCovariantGroupRetainedIstV1 {
pub const N_LOGICAL: usize = N_LOGICAL;
pub const M_MEASURED: usize = M_MEASURED;
pub const INDIRECT_ZERO_FILL: usize = INDIRECT_ZERO_FILL;
pub fn new() -> Self {
Self
}
pub fn estimated_work(self, input: &IstInput, options: IstOptions) -> Result<u128, IstError> {
validate_options(options)?;
estimate_work(input, options.max_iterations, false)
}
pub fn reconstruct(
self,
input: &IstInput,
work: &mut WorkLedger,
options: IstOptions,
) -> Result<IstOutput, IstError> {
self.reconstruct_with_context(input, options, &mut ExecutionContext::new(work))
}
pub fn reconstruct_with_context(
self,
input: &IstInput,
options: IstOptions,
control: &mut ExecutionContext<'_>,
) -> Result<IstOutput, IstError> {
if input.nlogical != N_LOGICAL || input.measured_indices.len() != M_MEASURED {
return Err(IstError::InvalidInput);
}
reconstruct(input, options, control, false)
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct GeneralGridPhaseCovariantGroupRetainedIstV1;
impl GeneralGridPhaseCovariantGroupRetainedIstV1 {
pub fn estimated_work(self, input: &IstInput, options: IstOptions) -> Result<u128, IstError> {
validate_options(options)?;
estimate_work(input, options.max_iterations, true)
}
pub fn resources(
self,
input: &IstInput,
) -> Result<crate::resource::ResourceEstimate, IstError> {
let memory = memory_preflight(input, true)?;
Ok(crate::resource::ResourceEstimate::new(
memory.output_bytes,
0,
memory.peak_working_bytes,
))
}
pub fn reconstruct_with_context(
self,
input: &IstInput,
options: IstOptions,
control: &mut ExecutionContext<'_>,
) -> Result<IstOutput, IstError> {
reconstruct(input, options, control, true)
}
}