Skip to content

Commit

Permalink
Fix: Change litinsky factory to return based on error rate, not archi…
Browse files Browse the repository at this point in the history
…tecture type (#149)

* change litinsky factory to return based on error rate, not type

* Fix tests

* fix factory dict
  • Loading branch information
SebastianMorawiec authored Mar 5, 2024
1 parent 9574364 commit d383ecc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 64 deletions.
93 changes: 30 additions & 63 deletions src/benchq/magic_state_distillation/litinski_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,15 @@
from typing import Iterable

from benchq.quantum_hardware_modeling.hardware_architecture_models import (
DetailedIonTrapModel,
IONTrapModel,
SCModel,
BasicArchitectureModel,
)

from .magic_state_factory import MagicStateFactory

_ALLOWED_PHYSICAL_ERROR_RATES = (1e-3, 1e-4)

@singledispatch
def iter_litinski_factories(architecture_model) -> Iterable[MagicStateFactory]:
raise NotImplementedError(
f"No MagicStateFactorys known for type model {architecture_model}"
)


@iter_litinski_factories.register
def iter_litinski_factories_for_ion_traps(
_architecture_model: IONTrapModel,
) -> Iterable[MagicStateFactory]:
return [
MagicStateFactory("(15-to-1)_7,3,3", 4.4e-8, (30, 27), 810, 18.1),
MagicStateFactory("(15-to-1)_9,3,3", 9.3e-10, (38, 30), 1150, 18.1),
MagicStateFactory("(15-to-1)_11,5,5", 1.9e-11, (47, 44), 2070, 30),
MagicStateFactory(
"(15-to-1)^4_9,3,3 x (20-to-4)_15,7,9",
2.4e-15,
(221, 96),
16400,
90.3,
n_t_gates_produced_per_distillation=4,
),
MagicStateFactory(
"(15-to-1)^4_9,3,3 x (15-to-1)_25,9,9", 6.3e-25, (193, 96), 18600, 67.8
),
]


# this can be combined with the above function, when we upgrade to python 3.11
# and union types are supported by singledispatch.
# https://github.com/python/cpython/issues/90172
@iter_litinski_factories.register
def iter_litinski_factories_for_detailed_ion_traps(
_architecture_model: DetailedIonTrapModel,
) -> Iterable[MagicStateFactory]:
return [
MagicStateFactory("(15-to-1)_7,3,3", 4.4e-8, (30, 27), 810, 18.1),
MagicStateFactory("(15-to-1)_9,3,3", 9.3e-10, (38, 30), 1150, 18.1),
MagicStateFactory("(15-to-1)_11,5,5", 1.9e-11, (47, 44), 2070, 30),
MagicStateFactory(
"(15-to-1)^4_9,3,3 x (20-to-4)_15,7,9",
2.4e-15,
(221, 96),
16400,
90.3,
n_t_gates_produced_per_distillation=4,
),
MagicStateFactory(
"(15-to-1)^4_9,3,3 x (15-to-1)_25,9,9", 6.3e-25, (193, 96), 18600, 67.8
),
]


@iter_litinski_factories.register
def iter_litinski_factories_for_sc(
_architecture_model: SCModel,
) -> Iterable[MagicStateFactory]:
return [
_ERROR_RATE_FACTORY_MAPPING = {
1e-3: (
MagicStateFactory("(15-to-1)_17,7,7", 4.5e-8, (72, 64), 4620, 42.6),
MagicStateFactory(
"(15-to-1)^6_15,5,5 x (20-to-4)_23,11,13",
Expand Down Expand Up @@ -106,4 +48,29 @@ def iter_litinski_factories_for_sc(
73400,
128,
),
]
),
1e-4: (
MagicStateFactory("(15-to-1)_7,3,3", 4.4e-8, (30, 27), 810, 18.1),
MagicStateFactory("(15-to-1)_9,3,3", 9.3e-10, (38, 30), 1150, 18.1),
MagicStateFactory("(15-to-1)_11,5,5", 1.9e-11, (47, 44), 2070, 30),
MagicStateFactory(
"(15-to-1)^4_9,3,3 x (20-to-4)_15,7,9",
2.4e-15,
(221, 96),
16400,
90.3,
n_t_gates_produced_per_distillation=4,
),
MagicStateFactory(
"(15-to-1)^4_9,3,3 x (15-to-1)_25,9,9", 6.3e-25, (193, 96), 18600, 67.8
),
),
}


def iter_litinski_factories(
architecture_model: BasicArchitectureModel,
) -> Iterable[MagicStateFactory]:
assert architecture_model.physical_qubit_error_rate in _ALLOWED_PHYSICAL_ERROR_RATES

return _ERROR_RATE_FACTORY_MAPPING[architecture_model.physical_qubit_error_rate]
12 changes: 12 additions & 0 deletions tests/benchq/magic_state_distillation/test_litinski_factories.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import dataclasses
from dataclasses import replace

import pytest

from benchq.magic_state_distillation.litinski_factories import iter_litinski_factories
Expand All @@ -13,6 +16,7 @@
[
BASIC_ION_TRAP_ARCHITECTURE_MODEL,
BASIC_SC_ARCHITECTURE_MODEL,
DetailedIonTrapModel(),
],
)
def test_factory_properties_are_correct(architecture_model):
Expand All @@ -24,3 +28,11 @@ def test_factory_properties_are_correct(architecture_model):
assert factory.qubits > 0
assert factory.distillation_time_in_cycles > 0
assert factory.n_t_gates_produced_per_distillation >= 1


def test_factory_based_on_err_rate():
ion = BASIC_ION_TRAP_ARCHITECTURE_MODEL
cs = BASIC_SC_ARCHITECTURE_MODEL
cs = replace(cs, physical_qubit_error_rate=1e-4)

assert iter_litinski_factories(cs) == iter_litinski_factories(ion)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from benchq.algorithms.data_structures import AlgorithmImplementation, ErrorBudget
from benchq.compilation import get_ruby_slippers_compiler
from benchq.decoder_modeling import DecoderModel
from benchq.magic_state_distillation.litinski_factories import (
_ERROR_RATE_FACTORY_MAPPING,
)
from benchq.problem_embeddings.quantum_program import (
QuantumProgram,
get_program_from_circuit,
Expand Down Expand Up @@ -185,7 +188,9 @@ def test_better_architecture_does_not_require_more_resources(
high_noise_resource_estimates = get_custom_resource_estimation(
algorithm_implementation,
estimator=GraphResourceEstimator(
high_noise_architecture_model, optimization=optimization
high_noise_architecture_model,
optimization=optimization,
magic_state_factory_iterator=_ERROR_RATE_FACTORY_MAPPING[1e-4],
),
transformers=transformers,
)
Expand Down

0 comments on commit d383ecc

Please sign in to comment.