microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
source/resource_estimator/src/estimates/factory.rs
60lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use std::{borrow::Cow, rc::Rc}; |
| 5 | |
| 6 | use crate::estimates::ErrorCorrection; |
| 7 | |
| 8 | /// Helper structs when dispatching multiple magic states to different factories |
| 9 | mod dispatch; |
| 10 | pub use dispatch::{BuilderDispatch2, FactoryDispatch2}; |
| 11 | |
| 12 | /// Helper structs for when no factories are used |
| 13 | mod empty; |
| 14 | pub use empty::NoFactories; |
| 15 | |
| 16 | /// Generic factory model based on multiple rounds of distillation |
| 17 | mod round_based; |
| 18 | pub use round_based::{ |
| 19 | DistillationRound, DistillationUnit, FactoryBuildError, PhysicalQubitCalculation, |
| 20 | RoundBasedFactory, |
| 21 | }; |
| 22 | |
| 23 | pub trait FactoryBuilder<E: ErrorCorrection> |
| 24 | where |
| 25 | Self::Factory: Clone, |
| 26 | { |
| 27 | type Factory; |
| 28 | |
| 29 | fn find_factories( |
| 30 | &self, |
| 31 | ftp: &E, |
| 32 | qubit: &Rc<E::Qubit>, |
| 33 | magic_state_type: usize, |
| 34 | output_error_rate: f64, |
| 35 | max_code_parameter: &E::Parameter, |
| 36 | ) -> Result<Vec<Cow<Self::Factory>>, String>; |
| 37 | |
| 38 | fn num_magic_state_types(&self) -> usize { |
| 39 | 1 |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | pub trait Factory |
| 44 | where |
| 45 | Self::Parameter: Clone, |
| 46 | { |
| 47 | type Parameter; |
| 48 | |
| 49 | fn physical_qubits(&self) -> u64; |
| 50 | fn duration(&self) -> u64; |
| 51 | /// The number of magic states produced by the factory |
| 52 | fn num_output_states(&self) -> u64; |
| 53 | fn normalized_volume(&self) -> f64 { |
| 54 | ((self.physical_qubits() * self.duration()) as f64) / (self.num_output_states() as f64) |
| 55 | } |
| 56 | /// The maximum code parameter setting for a magic state factory. This is |
| 57 | /// used to constrain the search space, when looking for magic state |
| 58 | /// factories. |
| 59 | fn max_code_parameter(&self) -> Option<Cow<Self::Parameter>>; |
| 60 | } |