Skip to content

Commit

Permalink
remove MagicStateCount
Browse files Browse the repository at this point in the history
  • Loading branch information
NoureldinYosri committed Sep 27, 2023
1 parent 0611f06 commit 4e16013
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 52 deletions.
20 changes: 10 additions & 10 deletions qualtran/surface_code/algorithm_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

from attrs import field, frozen

_PRETTY_FLOAT = field(default=0.0, repr=lambda x: f'{x:g}')
_PRETTY_FLOAT = field(default=0.0, converter=float, repr=lambda x: f'{x:g}')


@frozen
class AlgorithmSummary:
"""Properties of a quantum algorithm that impact its physical cost
Counts of different properities that affect the physical cost of
running an algorithm (e.g. number of T gates).
All counts default to zero.
Counts of different properities that affect the physical cost of
running an algorithm (e.g. number of T gates).
All counts default to zero.
Attributes:
algorithm_qubits: Number of qubits used by the algorithm $Q_{alg}$.
Expand All @@ -35,9 +35,9 @@ class AlgorithmSummary:
rotation_circuit_depth: Depth of rotation circuit $D_R$.
"""

algorithm_qubits = _PRETTY_FLOAT
measurements = _PRETTY_FLOAT
t_gates = _PRETTY_FLOAT
toffoli_gates = _PRETTY_FLOAT
rotation_gates = _PRETTY_FLOAT
rotation_circuit_depth = _PRETTY_FLOAT
algorithm_qubits: float = _PRETTY_FLOAT
measurements: float = _PRETTY_FLOAT
t_gates: float = _PRETTY_FLOAT
toffoli_gates: float = _PRETTY_FLOAT
rotation_gates: float = _PRETTY_FLOAT
rotation_circuit_depth: float = _PRETTY_FLOAT
15 changes: 8 additions & 7 deletions qualtran/surface_code/ccz2t_cost_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

from attrs import frozen

from qualtran.surface_code.algorithm_summary import AlgorithmSummary
from qualtran.surface_code.data_block import DataBlock, SimpleDataBlock
from qualtran.surface_code.formulae import code_distance_from_budget, error_at
from qualtran.surface_code.magic_state_factory import MagicStateCount, MagicStateFactory
from qualtran.surface_code.magic_state_factory import MagicStateFactory
from qualtran.surface_code.physical_cost import PhysicalCost


Expand Down Expand Up @@ -132,16 +133,16 @@ def footprint(self) -> int:
l2 = 4 * 8 * 2 * self.distillation_l2_d**2
return 6 * l1 + l2

def distillation_error(self, n_magic: MagicStateCount, phys_err: float) -> float:
def distillation_error(self, n_magic: AlgorithmSummary, phys_err: float) -> float:
"""Error resulting from the magic state distillation part of the computation."""
n_ccz_states = n_magic.ccz_count + math.ceil(n_magic.t_count / 2)
n_ccz_states = n_magic.toffoli_gates + math.ceil(n_magic.t_gates / 2)
return self.l2_error(phys_err) * n_ccz_states

def n_cycles(self, n_magic: MagicStateCount) -> int:
def n_cycles(self, n_magic: AlgorithmSummary) -> int:
"""The number of error-correction cycles to distill enough magic states."""
distillation_d = max(2 * self.distillation_l1_d + 1, self.distillation_l2_d)
n_ccz_states = n_magic.ccz_count + math.ceil(n_magic.t_count / 2)
catalyzations = math.ceil(n_magic.t_count / 2)
n_ccz_states = n_magic.toffoli_gates + math.ceil(n_magic.t_gates / 2)
catalyzations = math.ceil(n_magic.t_gates / 2)

# Naive depth of 8.5, but can be overlapped to effective depth of 5.5
# See section 2, paragraph 2 of the reference.
Expand All @@ -152,7 +153,7 @@ def n_cycles(self, n_magic: MagicStateCount) -> int:

def get_ccz2t_costs(
*,
n_magic: MagicStateCount,
n_magic: AlgorithmSummary,
n_algo_qubits: int,
phys_err: float = 1e-3,
error_budget: Optional[float] = 1e-2,
Expand Down
4 changes: 2 additions & 2 deletions qualtran/surface_code/ccz2t_cost_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

import numpy as np

from qualtran.surface_code.algorithm_summary import AlgorithmSummary
from qualtran.surface_code.ccz2t_cost_model import get_ccz2t_costs
from qualtran.surface_code.magic_state_factory import MagicStateCount


def test_vs_spreadsheet():
re = get_ccz2t_costs(
n_magic=MagicStateCount(t_count=10**8, ccz_count=10**8),
n_magic=AlgorithmSummary(t_gates=10**8, toffoli_gates=10**8),
n_algo_qubits=100,
error_budget=0.01,
phys_err=1e-3,
Expand Down
24 changes: 3 additions & 21 deletions qualtran/surface_code/magic_state_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,7 @@

from attrs import frozen


@frozen
class MagicStateCount:
"""The number of magic states needed for a computation.
Each `count` excludes the resources needed to perform operations captured in other
magic state counts.
Args:
t_count: The number of T operations that need to be performed.
ccz_count: The number of Toffoli or CCZ operations that need to be performed.
"""

t_count: int
ccz_count: int

def all_t_count(self) -> int:
"""The T count needed to do all magic operations with T only."""
return self.t_count + 4 * self.ccz_count
from qualtran.surface_code.algorithm_summary import AlgorithmSummary


class MagicStateFactory(metaclass=abc.ABCMeta):
Expand All @@ -50,9 +32,9 @@ def footprint(self) -> int:
"""The number of physical qubits used by the magic state factory."""

@abc.abstractmethod
def n_cycles(self, n_magic: MagicStateCount) -> int:
def n_cycles(self, n_magic: AlgorithmSummary) -> int:
"""The number of cycles (time) required to produce the requested number of magic states."""

@abc.abstractmethod
def distillation_error(self, n_magic: MagicStateCount, phys_err: float) -> float:
def distillation_error(self, n_magic: AlgorithmSummary, phys_err: float) -> float:
"""The total error expected from distilling magic states with a given physical error rate."""
16 changes: 4 additions & 12 deletions qualtran/surface_code/physical_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,12 @@ class PhysicalParameters:
reference: Source of these estimates.
"""

t_gate_ns = field(default=1, repr=lambda x: f'{x:g}')
t_meas_ns = field(default=1, repr=lambda x: f'{x:g}')
t_gate_ns: float = field(repr=lambda x: f'{x:g}')
t_meas_ns: float = field(repr=lambda x: f'{x:g}')

physical_error_rate = field(default=1e-3, repr=lambda x: f'{x:g}')
physical_error_rate: float = field(default=1e-3, repr=lambda x: f'{x:g}')

reference = field(default='')


FowlerGidney = PhysicalParameters(
t_gate_ns=100,
t_meas_ns=100,
physical_error_rate=1e-3,
reference='https://arxiv.org/abs/1808.06709',
)
reference: str | None = None


BeverlandEtAl = PhysicalParameters(
Expand Down

0 comments on commit 4e16013

Please sign in to comment.