Skip to content

Commit c91ac5d

Browse files
authored
Allow QEC to encode multiple logical qubits (#1226)
This generalizes the `ErrorCorrection` trait to allow encoding multiple logical qubits, thereby enabling the modeling of codes such as LDPC. The change also lead to rename the `LogicalQubit` struct into `LogicalPatch` to account the possibility of multiple logical qubits in the name of the struct. The system does not change, since all the planar codes modeled in it encode one logical qubit.
1 parent f747d1f commit c91ac5d

File tree

16 files changed

+286
-217
lines changed

16 files changed

+286
-217
lines changed

resource_estimator/src/estimates.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ pub use physical_estimation::{
1313
mod layout;
1414
mod logical_qubit;
1515
pub use layout::Overhead;
16-
pub use logical_qubit::LogicalQubit;
16+
pub use logical_qubit::LogicalPatch;
1717
pub mod optimization;

resource_estimator/src/estimates/error.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ pub enum Error {
3737
#[error("No solution found for the provided maximum number of physical qubits.")]
3838
#[diagnostic(code("Qsc.Estimates.MaxPhysicalQubitsTooSmall"))]
3939
MaxPhysicalQubitsTooSmall,
40-
/// The number of physical qubits per logical qubit cannot be computed.
40+
/// The number of physical qubits required for a code cannot be computed.
4141
///
4242
/// ✅ This does not contain user data and can be logged
4343
/// 🧑‍💻 This indicates a user error
44-
#[error("The number of physical qubits per logical qubit cannot be computed: {0}")]
44+
#[error("The number of physical qubits required for a code cannot be computed: {0}")]
4545
#[diagnostic(code("Qsc.Estimates.PhysicalQubitComputationFailed"))]
4646
PhysicalQubitComputationFailed(String),
47+
/// The number of logical qubits provided by a code cannot be computed.
48+
///
49+
/// ✅ This does not contain user data and can be logged
50+
/// 🧑‍💻 This indicates a user error
51+
#[error("The number of logical qubits provided by a code cannot be computed: {0}")]
52+
#[diagnostic(code("Qsc.Estimates.LogicalQubitComputationFailed"))]
53+
LogicalQubitComputationFailed(String),
4754
/// The logical cycle time cannot be computed.
4855
///
4956
/// ✅ This does not contain user data and can be logged

resource_estimator/src/estimates/logical_qubit.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,32 @@
33

44
use crate::estimates::{Error, ErrorCorrection};
55

6-
use std::{
7-
fmt::{Debug, Display},
8-
rc::Rc,
9-
};
6+
use std::rc::Rc;
107

11-
/// Logical qubit model.
8+
/// A logical patch from an error correction code
129
///
13-
/// A logical qubit is derived from a physical qubit and a fault-tolerance
14-
/// protocol. Construction methods are provided that take as additional input
15-
/// the code distance, or alternatively the target error rate from which the
16-
/// code distance is computed.
17-
pub struct LogicalQubit<E: ErrorCorrection> {
10+
/// A logical patch is an instantiation of an error correcting code for some
11+
/// assignment to the code parameters. It stores all computed information such
12+
/// as the number of physical and logical qubits, cycle time, and logical error
13+
/// rate.
14+
pub struct LogicalPatch<E: ErrorCorrection> {
1815
physical_qubit: Rc<E::Qubit>,
1916
code_parameter: E::Parameter,
2017
physical_qubits: u64,
18+
logical_qubits: u64,
2119
logical_cycle_time: u64,
2220
logical_error_rate: f64,
2321
}
2422

25-
impl<E: ErrorCorrection> LogicalQubit<E> {
23+
impl<E: ErrorCorrection> LogicalPatch<E> {
2624
pub fn new(ftp: &E, code_parameter: E::Parameter, qubit: Rc<E::Qubit>) -> Result<Self, Error> {
2725
// safe to convert here because we check for negative values before
2826
let physical_qubits = ftp
29-
.physical_qubits_per_logical_qubit(&code_parameter)
27+
.physical_qubits(&code_parameter)
3028
.map_err(Error::PhysicalQubitComputationFailed)?;
29+
let logical_qubits = ftp
30+
.logical_qubits(&code_parameter)
31+
.map_err(Error::LogicalQubitComputationFailed)?;
3132
let logical_cycle_time = ftp
3233
.logical_cycle_time(&qubit, &code_parameter)
3334
.map_err(Error::LogicalCycleTimeComputationFailed)?;
@@ -39,6 +40,7 @@ impl<E: ErrorCorrection> LogicalQubit<E> {
3940
physical_qubit: qubit,
4041
code_parameter,
4142
physical_qubits,
43+
logical_qubits,
4244
logical_cycle_time,
4345
logical_error_rate,
4446
})
@@ -49,11 +51,16 @@ impl<E: ErrorCorrection> LogicalQubit<E> {
4951
&self.physical_qubit
5052
}
5153

52-
/// Returns the code distance.
54+
/// Returns the code parameter.
5355
pub fn code_parameter(&self) -> &E::Parameter {
5456
&self.code_parameter
5557
}
5658

59+
/// Returns the number of logical qubits in the patch.
60+
pub fn logical_qubits(&self) -> u64 {
61+
self.logical_qubits
62+
}
63+
5764
/// Returns the number of physical qubits to encode the logical qubit.
5865
pub fn physical_qubits(&self) -> u64 {
5966
self.physical_qubits
@@ -74,12 +81,3 @@ impl<E: ErrorCorrection> LogicalQubit<E> {
7481
1e9 / (self.logical_cycle_time as f64)
7582
}
7683
}
77-
78-
impl<E: ErrorCorrection> Debug for LogicalQubit<E>
79-
where
80-
E::Parameter: Display,
81-
{
82-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83-
write!(f, "LQubit(d={})", self.code_parameter())
84-
}
85-
}

0 commit comments

Comments
 (0)