Skip to content

Commit

Permalink
Parameter to set maximum number of distillation rounds in default sea…
Browse files Browse the repository at this point in the history
…rch (#1669)

This adds a parameter `maxDistillationRounds` to the `constraints` group
in resource estimation, which allows to modify the allowed number of
distillation rounds in the first search for T factories. The default
value is 3. Making this number larger will slow down resource estimation
due to the larger exploration space of possible T factories.
  • Loading branch information
msoeken authored Jun 27, 2024
1 parent 81001ec commit c941c67
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 44 deletions.
8 changes: 4 additions & 4 deletions resource_estimator/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ fn estimate_single<L: Overhead + LayoutReportData + PartitioningOverhead + Seria
let mut estimation = PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
TFactoryBuilder::new(
distillation_unit_templates,
job_params.constraints().max_distillation_rounds,
),
logical_resources,
partitioning,
);
Expand All @@ -105,9 +108,6 @@ fn estimate_single<L: Overhead + LayoutReportData + PartitioningOverhead + Seria
if let Some(max_physical_qubits) = job_params.constraints().max_physical_qubits {
estimation.set_max_physical_qubits(max_physical_qubits);
}
estimation
.factory_builder_mut()
.set_distillation_unit_templates(distillation_unit_templates);

match job_params.estimate_type() {
EstimateType::Frontier => {
Expand Down
4 changes: 2 additions & 2 deletions resource_estimator/src/system/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
pub const MAX_CODE_DISTANCE: u64 = 50;

/// Maximum number of distillation rounds
pub const MAX_DISTILLATION_ROUNDS: usize = 3;
pub const MAX_DISTILLATION_ROUNDS: u64 = 3;

/// Maximum number of extra distillation rounds in case none is found for [`MAX_DISTILLATION_ROUNDS`]
pub const MAX_EXTRA_DISTILLATION_ROUNDS: usize = 4;
pub const MAX_EXTRA_DISTILLATION_ROUNDS: u64 = 4;

/// (Γ_R in paper for layout)
#[allow(clippy::doc_markdown)]
Expand Down
25 changes: 19 additions & 6 deletions resource_estimator/src/system/data/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use crate::system::constants::MAX_DISTILLATION_ROUNDS;

use super::super::serialization::time;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
#[serde(
rename_all(serialize = "camelCase", deserialize = "camelCase"),
deny_unknown_fields
Expand All @@ -18,13 +20,24 @@ pub struct Constraints {
pub max_duration: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_physical_qubits: Option<u64>,
#[serde(default = "Constraints::max_distillation_rounds_default")]
pub max_distillation_rounds: u64,
}

impl Default for Constraints {
fn default() -> Self {
Self {
logical_depth_factor: None,
max_t_factories: None,
max_duration: None,
max_physical_qubits: None,
max_distillation_rounds: Self::max_distillation_rounds_default(),
}
}
}

impl Constraints {
pub fn is_default(&self) -> bool {
self.logical_depth_factor.is_none()
&& self.max_t_factories.is_none()
&& self.max_duration.is_none()
&& self.max_physical_qubits.is_none()
fn max_distillation_rounds_default() -> u64 {
MAX_DISTILLATION_ROUNDS
}
}
2 changes: 1 addition & 1 deletion resource_estimator/src/system/data/job_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct JobParams {
#[serde(default)]
qubit_params: Rc<PhysicalQubit>,

#[serde(default, skip_serializing_if = "Constraints::is_default")]
#[serde(default)]
constraints: Constraints,

#[serde(default, skip_serializing_if = "Profiling::is_default")]
Expand Down
32 changes: 16 additions & 16 deletions resource_estimator/src/system/optimization/tfactory_exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
system::modeling::default_t_factory,
};

use super::super::constants::{MAX_DISTILLATION_ROUNDS, MAX_EXTRA_DISTILLATION_ROUNDS};
use super::super::constants::MAX_EXTRA_DISTILLATION_ROUNDS;

use super::code_distance_iterators::{iterate_for_code_distances, search_for_code_distances};
use super::distillation_units_map::DistillationUnitsMap;
Expand Down Expand Up @@ -215,13 +215,15 @@ pub(crate) fn find_nondominated_tfactories<'a>(
distillation_unit_templates: &[TFactoryDistillationUnitTemplate],
output_t_error_rate: f64,
max_code_distance: u64,
max_distillation_rounds: u64,
) -> Vec<Cow<'a, TFactory>> {
let points = find_nondominated_population::<Point2D<TFactory>>(
ftp,
qubit,
distillation_unit_templates,
output_t_error_rate,
max_code_distance,
max_distillation_rounds,
);

points
Expand All @@ -237,6 +239,7 @@ fn find_nondominated_population<P>(
distillation_unit_templates: &[TFactoryDistillationUnitTemplate],
output_t_error_rate: f64,
max_code_distance: u64,
max_distillation_rounds: u64,
) -> Population<P>
where
P: Point + Ord + ToString + From<TFactory> + TFactoryExhaustiveSearchOptions,
Expand Down Expand Up @@ -274,13 +277,13 @@ where

let mut searcher = TFactoryExhaustiveSearch::<P>::new(output_t_error_rate);

for num_rounds in 1..=MAX_DISTILLATION_ROUNDS {
process_for_num_rounds(&mut searcher, &distillation_units_map, num_rounds);
for num_rounds in 1..=max_distillation_rounds {
process_for_num_rounds(&mut searcher, &distillation_units_map, num_rounds as usize);
}

if searcher.frontier_factories.items().is_empty() || P::ITERATE_MAX_NUM_ROUNDS {
for num_rounds in MAX_DISTILLATION_ROUNDS + 1..=MAX_EXTRA_DISTILLATION_ROUNDS {
process_for_num_rounds(&mut searcher, &distillation_units_map, num_rounds);
for num_rounds in max_distillation_rounds + 1..=MAX_EXTRA_DISTILLATION_ROUNDS {
process_for_num_rounds(&mut searcher, &distillation_units_map, num_rounds as usize);
}
}

Expand Down Expand Up @@ -341,22 +344,18 @@ fn process_for_specifications_combination<P>(

pub struct TFactoryBuilder {
distillation_unit_templates: Vec<TFactoryDistillationUnitTemplate>,
max_distillation_rounds: u64,
}

impl TFactoryBuilder {
pub fn set_distillation_unit_templates(
&mut self,
#[must_use]
pub fn new(
distillation_unit_templates: Vec<TFactoryDistillationUnitTemplate>,
) {
self.distillation_unit_templates = distillation_unit_templates;
}
}

impl Default for TFactoryBuilder {
fn default() -> Self {
max_distillation_rounds: u64,
) -> Self {
Self {
distillation_unit_templates:
TFactoryDistillationUnitTemplate::default_distillation_unit_templates(),
distillation_unit_templates,
max_distillation_rounds,
}
}
}
Expand All @@ -378,6 +377,7 @@ impl FactoryBuilder<Protocol> for TFactoryBuilder {
&self.distillation_unit_templates,
output_t_error_rate,
*max_code_distance,
self.max_distillation_rounds,
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::{
estimates::{optimization::Point2D, Factory},
system::modeling::TFactory,
system::{constants::MAX_DISTILLATION_ROUNDS, modeling::TFactory},
};

use super::{
Expand All @@ -24,6 +24,7 @@ fn test_one_t_error_rate() {
&TFactoryDistillationUnitTemplate::default_distillation_unit_templates(),
1e-18,
35,
MAX_DISTILLATION_ROUNDS,
);
let elapsed = start.elapsed();

Expand Down Expand Up @@ -143,6 +144,7 @@ fn required_logical_tstate_error_too_high() {
&distillation_unit_templates,
output_t_error_rate,
max_code_distance,
MAX_DISTILLATION_ROUNDS,
);

assert_eq!(population.items().len(), 1);
Expand All @@ -165,6 +167,7 @@ fn find_tfactories<'a>(ftp: &Protocol, qubit_name: &str) -> Vec<Cow<'a, TFactory
&create_test_templates(),
output_t_error_rate,
ftp.max_code_distance(),
MAX_DISTILLATION_ROUNDS,
)
}

Expand Down
1 change: 1 addition & 0 deletions resource_estimator/src/system/test_report.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"tstates": 0.0003333333333333333
},
"jobParams": {
"constraints": { "maxDistillationRounds": 3 },
"errorBudget": 0.001,
"estimateType": "singlePoint",
"qecScheme": {
Expand Down
38 changes: 24 additions & 14 deletions resource_estimator/src/system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use crate::estimates::{
PhysicalResourceEstimation, PhysicalResourceEstimationResult,
};

use super::estimate_physical_resources;
use super::{
constants::MAX_DISTILLATION_ROUNDS, estimate_physical_resources,
modeling::TFactoryDistillationUnitTemplate,
};

use crate::system::{
data::{ErrorBudgetSpecification, JobParams, LogicalResourceCounts},
Expand Down Expand Up @@ -140,7 +143,7 @@ pub fn test_no_tstates() {
let estimation = PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(layout_overhead),
partitioning,
);
Expand All @@ -159,7 +162,7 @@ pub fn single_tstate() -> Result<()> {
let estimation = PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(layout_overhead),
partitioning,
);
Expand All @@ -183,7 +186,7 @@ pub fn perfect_tstate() -> Result<()> {
let estimation = PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(layout_overhead),
partitioning,
);
Expand Down Expand Up @@ -231,7 +234,7 @@ pub fn test_hubbard_e2e() -> Result<()> {
let estimation = PhysicalResourceEstimation::new(
ftp,
qubit.clone(),
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(layout_overhead),
partitioning,
);
Expand Down Expand Up @@ -270,7 +273,7 @@ pub fn test_hubbard_e2e() -> Result<()> {

let same_ftp = Protocol::default();
let output_t_error_rate = part.required_output_error_rate();
let builder = TFactoryBuilder::default();
let builder = create_factory_builder();
let tfactories = builder
.find_factories(
&same_ftp,
Expand Down Expand Up @@ -326,7 +329,7 @@ pub fn test_hubbard_e2e_measurement_based() -> Result<()> {
let estimation = PhysicalResourceEstimation::new(
ftp,
qubit.clone(),
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(layout_overhead),
partitioning,
);
Expand Down Expand Up @@ -363,7 +366,7 @@ pub fn test_hubbard_e2e_measurement_based() -> Result<()> {

let output_t_error_rate = part.required_output_error_rate();
let same_ftp = Protocol::floquet_code();
let builder = TFactoryBuilder::default();
let builder = create_factory_builder();
let tfactories = builder
.find_factories(
&same_ftp,
Expand Down Expand Up @@ -418,7 +421,7 @@ pub fn test_hubbard_e2e_increasing_max_duration() -> Result<()> {
let estimation = PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(layout_overhead),
partitioning,
);
Expand Down Expand Up @@ -446,7 +449,7 @@ pub fn test_hubbard_e2e_increasing_max_num_qubits() -> Result<()> {
let estimation = PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(layout_overhead),
partitioning,
);
Expand Down Expand Up @@ -489,7 +492,7 @@ fn prepare_chemistry_estimation_with_expected_majorana(
PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(counts),
partitioning,
)
Expand Down Expand Up @@ -660,7 +663,7 @@ fn prepare_factorization_estimation_with_optimistic_majorana(
PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(counts),
partitioning,
)
Expand Down Expand Up @@ -793,7 +796,7 @@ fn prepare_ising20x20_estimation_with_pessimistic_gate_based(
PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(counts),
partitioning,
)
Expand Down Expand Up @@ -895,7 +898,7 @@ fn prepare_bit_flip_code_resources_and_majorana_n6_qubit(
PhysicalResourceEstimation::new(
ftp,
qubit,
TFactoryBuilder::default(),
create_factory_builder(),
Rc::new(counts),
partitioning,
)
Expand Down Expand Up @@ -986,6 +989,13 @@ fn test_report() {
);
}

fn create_factory_builder() -> TFactoryBuilder {
TFactoryBuilder::new(
TFactoryDistillationUnitTemplate::default_distillation_unit_templates(),
MAX_DISTILLATION_ROUNDS,
)
}

fn find_factory<'a>(
tfactories: &[Cow<'a, TFactory>],
duration: u64,
Expand Down

0 comments on commit c941c67

Please sign in to comment.