microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
source/pip/src/generic_estimator/factory/dispatch.rs
48lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use std::{borrow::Cow, ops::Deref, rc::Rc}; |
| 5 | |
| 6 | use pyo3::{types::PyDict, Bound}; |
| 7 | use resource_estimator::estimates::FactoryBuilder; |
| 8 | |
| 9 | use super::super::{code::PythonQEC, utils::SerializableBound}; |
| 10 | |
| 11 | use super::{PythonFactory, PythonFactoryBuilder}; |
| 12 | |
| 13 | /// A generic factory dispatcher to support declaring multiple factory builders |
| 14 | /// as input to generic resource estimation. |
| 15 | pub struct PythonFactoryBuilderDispatch<'py>(pub Vec<PythonFactoryBuilder<'py>>); |
| 16 | |
| 17 | impl<'py> Deref for PythonFactoryBuilderDispatch<'py> { |
| 18 | type Target = Vec<PythonFactoryBuilder<'py>>; |
| 19 | |
| 20 | fn deref(&self) -> &Self::Target { |
| 21 | &self.0 |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | impl<'py> FactoryBuilder<PythonQEC<'py>> for PythonFactoryBuilderDispatch<'py> { |
| 26 | type Factory = PythonFactory<'py>; |
| 27 | |
| 28 | fn find_factories( |
| 29 | &self, |
| 30 | ftp: &PythonQEC<'py>, |
| 31 | qubit: &Rc<Bound<'py, PyDict>>, |
| 32 | magic_state_type: usize, |
| 33 | output_error_rate: f64, |
| 34 | max_code_parameter: &SerializableBound<'py>, |
| 35 | ) -> Result<Vec<Cow<Self::Factory>>, String> { |
| 36 | self[magic_state_type].find_factories( |
| 37 | ftp, |
| 38 | qubit, |
| 39 | magic_state_type, |
| 40 | output_error_rate, |
| 41 | max_code_parameter, |
| 42 | ) |
| 43 | } |
| 44 | |
| 45 | fn num_magic_state_types(&self) -> usize { |
| 46 | self.len() |
| 47 | } |
| 48 | } |
| 49 | |