microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
billti/num2-sim

Branches

Tags

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

Clone

HTTPS

Download ZIP

source/resource_estimator/src/estimates/logical_qubit.rs

88lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use serde::Serialize;
5
6use crate::estimates::{Error, ErrorCorrection};
7
8use std::rc::Rc;
9
10/// A logical patch from an error correction code
11///
12/// A logical patch is an instantiation of an error correcting code for some
13/// assignment to the code parameters. It stores all computed information such
14/// as the number of physical and logical qubits, cycle time, and logical error
15/// rate.
16#[derive(Serialize)]
17#[serde(rename_all = "camelCase", bound = "E::Parameter: Serialize")]
18pub struct LogicalPatch<E: ErrorCorrection> {
19 #[serde(skip)]
20 physical_qubit: Rc<E::Qubit>,
21 code_parameter: E::Parameter,
22 physical_qubits: u64,
23 logical_qubits: u64,
24 logical_cycle_time: u64,
25 logical_error_rate: f64,
26}
27
28impl<E: ErrorCorrection> LogicalPatch<E> {
29 pub fn new(ftp: &E, code_parameter: E::Parameter, qubit: Rc<E::Qubit>) -> Result<Self, Error> {
30 // safe to convert here because we check for negative values before
31 let physical_qubits = ftp
32 .physical_qubits(&code_parameter)
33 .map_err(Error::PhysicalQubitComputationFailed)?;
34 let logical_qubits = ftp
35 .logical_qubits(&code_parameter)
36 .map_err(Error::LogicalQubitComputationFailed)?;
37 let logical_cycle_time = ftp
38 .logical_cycle_time(&qubit, &code_parameter)
39 .map_err(Error::LogicalCycleTimeComputationFailed)?;
40 let logical_error_rate = ftp
41 .logical_error_rate(&qubit, &code_parameter)
42 .map_err(Error::LogicalErrorRateComputationFailed)?;
43
44 Ok(Self {
45 physical_qubit: qubit,
46 code_parameter,
47 physical_qubits,
48 logical_qubits,
49 logical_cycle_time,
50 logical_error_rate,
51 })
52 }
53
54 /// Returns a reference to the logical qubit's underlying physical qubit model.
55 pub fn physical_qubit(&self) -> &E::Qubit {
56 &self.physical_qubit
57 }
58
59 /// Returns the code parameter.
60 pub fn code_parameter(&self) -> &E::Parameter {
61 &self.code_parameter
62 }
63
64 /// Returns the number of logical qubits in the patch.
65 pub fn logical_qubits(&self) -> u64 {
66 self.logical_qubits
67 }
68
69 /// Returns the number of physical qubits to encode the logical qubit.
70 pub fn physical_qubits(&self) -> u64 {
71 self.physical_qubits
72 }
73
74 /// Returns the logical cycle time.
75 pub fn logical_cycle_time(&self) -> u64 {
76 self.logical_cycle_time
77 }
78
79 /// Returns the qubit's logical error rate
80 pub fn logical_error_rate(&self) -> f64 {
81 self.logical_error_rate
82 }
83
84 /// Returns the number of logical cycles per second
85 pub fn logical_cycles_per_second(&self) -> f64 {
86 1e9 / (self.logical_cycle_time as f64)
87 }
88}
89