Skip to content

Commit

Permalink
Control how physical qubits are computed in factories (#1940)
Browse files Browse the repository at this point in the history
This adds the possibility to change the behavior, how physical qubits
are computed in a round based factory. The default behavior is to take
the max among all distillation rounds, but one can set to calculate the
sum over all units instead. This change is accessible via the job
params.
  • Loading branch information
msoeken authored Sep 30, 2024
1 parent c8c1338 commit b192d38
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resource_estimator/src/estimates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use error_correction::{CodeWithThresholdAndDistance, CodeWithThresholdAndDis
mod factory;
pub use factory::{
BuilderDispatch2, DistillationRound, DistillationUnit, FactoryBuildError, FactoryDispatch2,
NoFactories, RoundBasedFactory,
NoFactories, PhysicalQubitCalculation, RoundBasedFactory,
};
mod physical_estimation;
pub use physical_estimation::{
Expand Down
42 changes: 37 additions & 5 deletions resource_estimator/src/estimates/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub struct RoundBasedFactory<P> {
rounds: Vec<DistillationRound<P>>,
input_error_rate_before_each_round: Vec<f64>,
failure_probability_after_each_round: Vec<f64>,
physical_qubit_calculation: PhysicalQubitCalculation,
}

impl<P: Clone> RoundBasedFactory<P> {
Expand All @@ -159,6 +160,7 @@ impl<P: Clone> RoundBasedFactory<P> {
rounds,
input_error_rate_before_each_round,
failure_probability_after_each_round,
physical_qubit_calculation: PhysicalQubitCalculation::default(),
}
}

Expand All @@ -178,6 +180,7 @@ impl<P: Clone> RoundBasedFactory<P> {
rounds,
input_error_rate_before_each_round,
failure_probability_after_each_round,
physical_qubit_calculation: PhysicalQubitCalculation::default(),
};

pipeline.compute_units_per_round(units, 1)?;
Expand Down Expand Up @@ -207,6 +210,18 @@ impl<P: Clone> RoundBasedFactory<P> {
Ok(())
}

#[must_use]
pub fn physical_qubit_calculation(&self) -> PhysicalQubitCalculation {
self.physical_qubit_calculation
}

pub fn set_physical_qubit_calculation(
&mut self,
physical_qubit_calculation: PhysicalQubitCalculation,
) {
self.physical_qubit_calculation = physical_qubit_calculation;
}

#[must_use]
pub fn rounds(&self) -> &[DistillationRound<P>] {
&self.rounds
Expand Down Expand Up @@ -321,11 +336,19 @@ impl<P: Clone> Factory for RoundBasedFactory<P> {
type Parameter = P;

fn physical_qubits(&self) -> u64 {
self.rounds
.iter()
.map(DistillationRound::physical_qubits)
.max()
.unwrap_or(0)
match self.physical_qubit_calculation {
PhysicalQubitCalculation::Max => self
.rounds
.iter()
.map(DistillationRound::physical_qubits)
.max()
.unwrap_or(0),
PhysicalQubitCalculation::Sum => self
.rounds
.iter()
.map(DistillationRound::physical_qubits)
.sum::<u64>(),
}
}

fn duration(&self) -> u64 {
Expand All @@ -350,3 +373,12 @@ impl<P: Clone> Factory for RoundBasedFactory<P> {
.map(|f| Cow::Borrowed(f))
}
}

#[derive(Copy, Clone, Debug, Default)]
pub enum PhysicalQubitCalculation {
/// physical qubits can be shared among rounds
#[default]
Max,
/// each round has its own physical qubits
Sum,
}

0 comments on commit b192d38

Please sign in to comment.