microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
source/resource_estimator/examples/basic_logical_counts.rs
72lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | #![allow(clippy::cast_precision_loss)] |
| 5 | |
| 6 | // This example illustrates how to use the Resource Estimator crate to perform a |
| 7 | // standard resource estimation on top of the qubit and QEC models provided by |
| 8 | // the systems architecture that we ship. We are using logical resource counts |
| 9 | // to compute the post-layout logical overhead based on the PSSPC layout method |
| 10 | // as described in [https://arxiv.org/abs/2211.07629]. |
| 11 | |
| 12 | use std::rc::Rc; |
| 13 | |
| 14 | use resource_estimator::{ |
| 15 | estimates::{ErrorBudget, PhysicalResourceEstimation}, |
| 16 | system::{floquet_code, LogicalResourceCounts, PhysicalQubit, TFactoryBuilder}, |
| 17 | }; |
| 18 | |
| 19 | fn main() { |
| 20 | // There are 5 ingredients that we need to perform resource estimation. |
| 21 | |
| 22 | // 1) A quantum error correction code; in this example we are using a |
| 23 | // Floquet code. |
| 24 | let code = floquet_code(); |
| 25 | |
| 26 | // 2) A qubit model; in this example we are using a Majorana type qubit |
| 27 | // using a physical error rate of 1e-6. |
| 28 | let qubit = Rc::new(PhysicalQubit::qubit_maj_ns_e6()); |
| 29 | |
| 30 | // 3) A factory builder to provide magic states; in this example we are |
| 31 | // using a T factory builder that can create T factories using multiple |
| 32 | // distillation rounds. |
| 33 | let builder = TFactoryBuilder::default(); |
| 34 | |
| 35 | // 4) The logical resource overhead; in this example we are using logical |
| 36 | // resource counts that compute the logical post-layout overhead based on |
| 37 | // the PSSPC algorithm. |
| 38 | let logical_counts = Rc::new(LogicalResourceCounts { |
| 39 | num_qubits: 100, |
| 40 | t_count: 10, |
| 41 | rotation_count: 10, |
| 42 | rotation_depth: 5, |
| 43 | ccz_count: 100, |
| 44 | ccix_count: 0, |
| 45 | measurement_count: 10, |
| 46 | }); |
| 47 | |
| 48 | // 5) An error budget; in this example we are using a uniform error budget |
| 49 | // of 0.1% distributed uniformly among logical errors, rotation synthesis |
| 50 | // errors, and T state production errors. |
| 51 | let budget = ErrorBudget::from_uniform(0.001); |
| 52 | |
| 53 | // After we have set up all required inputs for the resource estimation |
| 54 | // task, we can set up an estimation instance. |
| 55 | let estimation = PhysicalResourceEstimation::new(code, qubit, builder, logical_counts); |
| 56 | |
| 57 | // In this example, we perform a standard estimation without any further |
| 58 | // constraints. |
| 59 | let result = estimation |
| 60 | .estimate(&budget) |
| 61 | .expect("estimation does not fail"); |
| 62 | |
| 63 | // There is a lot of data contained in the resource estimation result |
| 64 | // object, but in this sample we are only printing the total number of |
| 65 | // physical qubits and the runtime in seconds (the value is returned in nano |
| 66 | // seconds). |
| 67 | println!("Number of physical qubits: {}", result.physical_qubits()); |
| 68 | println!( |
| 69 | "Runtime: {:.2e} secs", |
| 70 | result.runtime() as f64 / 1e9 |
| 71 | ); |
| 72 | } |
| 73 | |