microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.22.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/pip/src/generic_estimator/factory/dispatch.rs

48lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use std::{borrow::Cow, ops::Deref, rc::Rc};
5
6use pyo3::{Bound, types::PyDict};
7use resource_estimator::estimates::FactoryBuilder;
8
9use super::super::{code::PythonQEC, utils::SerializableBound};
10
11use super::{PythonFactory, PythonFactoryBuilder};
12
13/// A generic factory dispatcher to support declaring multiple factory builders
14/// as input to generic resource estimation.
15pub struct PythonFactoryBuilderDispatch<'py>(pub Vec<PythonFactoryBuilder<'py>>);
16
17impl<'py> Deref for PythonFactoryBuilderDispatch<'py> {
18 type Target = Vec<PythonFactoryBuilder<'py>>;
19
20 fn deref(&self) -> &Self::Target {
21 &self.0
22 }
23}
24
25impl<'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