Skip to content

Commit

Permalink
[surface code] Organize
Browse files Browse the repository at this point in the history
  • Loading branch information
mpharrigan committed Jul 24, 2024
1 parent 149fe23 commit abd8323
Show file tree
Hide file tree
Showing 20 changed files with 435 additions and 400 deletions.
43 changes: 20 additions & 23 deletions qualtran/surface_code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,35 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from qualtran.surface_code.algorithm_summary import AlgorithmSummary
from qualtran.surface_code.ccz2t_cost_model import (
CCZ2TFactory,
get_ccz2t_costs,
get_ccz2t_costs_from_error_budget,
get_ccz2t_costs_from_grid_search,
)
from qualtran.surface_code.data_block import (
# isort:skip_file

from .algorithm_summary import AlgorithmSummary
from .physical_cost_summary import PhysicalCostsSummary
from .physical_parameters import PhysicalParameters
from .qec_scheme import LogicalErrorModel, QECScheme
from .magic_state_factory import MagicStateFactory
from .ccz2t_factory import CCZ2TFactory
from .fifteen_to_one_factory import FifteenToOne
from .data_block import (
CompactDataBlock,
DataBlock,
FastDataBlock,
IntermediateDataBlock,
SimpleDataBlock,
)
from qualtran.surface_code.magic_count import MagicCount
from qualtran.surface_code.magic_state_factory import MagicStateFactory
from qualtran.surface_code.multi_factory import MultiFactory
from qualtran.surface_code.physical_cost import PhysicalCost
from qualtran.surface_code.physical_parameters import PhysicalParameters
from qualtran.surface_code.quantum_error_correction_scheme_summary import (
BeverlandMajoranaQubits,
BeverlandSuperconductingQubits,
BeverlandTrappedIonQubits,
FowlerSuperconductingQubits,
LogicalErrorModel,
QuantumErrorCorrectionSchemeSummary,
)
from qualtran.surface_code.reference import Reference
from qualtran.surface_code.rotation_cost_model import (
from .multi_factory import MultiFactory
from .rotation_cost_model import (
BeverlandEtAlRotationCost,
ConstantWithOverheadRotationCost,
RotationCostModel,
RotationLogarithmicModel,
SevenDigitsOfPrecisionConstantCost,
)
from .gidney_fowler_model import (
get_ccz2t_costs,
get_ccz2t_costs_from_error_budget,
get_ccz2t_costs_from_grid_search,
iter_ccz2t_factories,
iter_simple_data_blocks,
)
from .reference import Reference
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Azure Cost Model\n",
"# Beverland et. al. Model\n",
"In this notebook, we reproduce the physical resource estimates in \"Assessing requirements to scale to practical quantum advantage\" by [Beverland et al](https://arxiv.org/abs/2211.07629), Appendix F.\n",
"\n",
"The paper describes the formulas used for estimating cost in the various appendices. The final estimation procedure is put together in Appendix E and we reproduce the values found in Appendix F."
Expand Down Expand Up @@ -49,10 +49,20 @@
"source": [
"from qualtran.surface_code import PhysicalParameters\n",
"\n",
"beverland_phys_params = PhysicalParameters.from_beverland('superconducting', optimistic_err_rate=True)\n",
"beverland_phys_params = PhysicalParameters.make_beverland_et_al('superconducting', optimistic_err_rate=True)\n",
"beverland_phys_params"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Compare and contrast with the Gidney and Fowler assumptions\n",
"PhysicalParameters.make_gidney_fowler()"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down Expand Up @@ -159,11 +169,9 @@
"metadata": {},
"outputs": [],
"source": [
"from qualtran.surface_code.quantum_error_correction_scheme_summary import (\n",
" BeverlandSuperconductingQubits,\n",
")\n",
"from qualtran.surface_code import QECScheme\n",
"\n",
"qec = BeverlandSuperconductingQubits\n",
"qec = QECScheme.make_beverland_et_al()\n",
"qec"
]
},
Expand Down Expand Up @@ -235,11 +243,11 @@
"metadata": {},
"outputs": [],
"source": [
"from qualtran.surface_code import azure_cost_model\n",
"from qualtran.surface_code import beverland_et_al_model\n",
"\n",
"# Calculate the minimum number of logical time steps (Eq D3)\n",
"error_budget = 0.001\n",
"c_min = azure_cost_model.minimum_time_steps(\n",
"c_min = beverland_et_al_model.minimum_time_steps(\n",
" error_budget=error_budget,\n",
" alg=qd_alg,\n",
" rotation_model=BeverlandEtAlRotationCost,\n",
Expand All @@ -254,7 +262,7 @@
"outputs": [],
"source": [
"# And the number of needed T operations (Eq D4)\n",
"t_operations = azure_cost_model.t_states(\n",
"t_operations = beverland_et_al_model.t_states(\n",
" error_budget=error_budget,\n",
" alg=qd_alg,\n",
" rotation_model=BeverlandEtAlRotationCost\n",
Expand Down Expand Up @@ -293,11 +301,11 @@
"metadata": {},
"outputs": [],
"source": [
"d = azure_cost_model.code_distance(\n",
"d = beverland_et_al_model.code_distance(\n",
" error_budget=error_budget,\n",
" time_steps=c_min,\n",
" alg=qd_alg,\n",
" qec_scheme=BeverlandSuperconductingQubits,\n",
" qec_scheme=qec,\n",
" physical_error=beverland_phys_params.physical_error,\n",
")\n",
"print(f'{d=}')"
Expand Down Expand Up @@ -415,7 +423,7 @@
"source": [
"# Calculate the minimum number of logical time steps (Eq D3)\n",
"error_budget = 0.01\n",
"c_min = azure_cost_model.minimum_time_steps(\n",
"c_min = beverland_et_al_model.minimum_time_steps(\n",
" error_budget=error_budget, alg=chem_alg, rotation_model=BeverlandEtAlRotationCost\n",
")\n",
"print('C_min = %g' % c_min)"
Expand All @@ -428,7 +436,7 @@
"outputs": [],
"source": [
"# And the number of needed T operations (Eq D4)\n",
"t_operations = azure_cost_model.t_states(\n",
"t_operations = beverland_et_al_model.t_states(\n",
" error_budget=error_budget, alg=chem_alg, rotation_model=BeverlandEtAlRotationCost\n",
")\n",
"print('M = %g' % t_operations)"
Expand Down Expand Up @@ -459,7 +467,7 @@
"metadata": {},
"outputs": [],
"source": [
"d = azure_cost_model.code_distance(\n",
"d = beverland_et_al_model.code_distance(\n",
" error_budget=error_budget,\n",
" time_steps=c_min,\n",
" alg=chem_alg,\n",
Expand Down Expand Up @@ -591,7 +599,7 @@
"source": [
"# Calculate the minimum number of logical time steps (Eq D3)\n",
"error_budget = 1 / 3\n",
"c_min = azure_cost_model.minimum_time_steps(\n",
"c_min = beverland_et_al_model.minimum_time_steps(\n",
" error_budget=error_budget, alg=shor_alg, rotation_model=BeverlandEtAlRotationCost\n",
")\n",
"print('C_min = %e' % c_min)"
Expand All @@ -604,7 +612,7 @@
"outputs": [],
"source": [
"# And the number of needed T operations (Eq D4)\n",
"t_operations = azure_cost_model.t_states(\n",
"t_operations = beverland_et_al_model.t_states(\n",
" error_budget=error_budget, alg=shor_alg, rotation_model=BeverlandEtAlRotationCost\n",
")\n",
"print('M = %e' % t_operations)"
Expand All @@ -624,7 +632,7 @@
"metadata": {},
"outputs": [],
"source": [
"d = azure_cost_model.code_distance(\n",
"d = beverland_et_al_model.code_distance(\n",
" error_budget=error_budget,\n",
" time_steps=c_min,\n",
" alg=shor_alg,\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
from qualtran.resource_counting import GateCounts

if TYPE_CHECKING:
from qualtran.surface_code import (
AlgorithmSummary,
QuantumErrorCorrectionSchemeSummary,
RotationCostModel,
)
from qualtran.surface_code import AlgorithmSummary, QECScheme, RotationCostModel


def minimum_time_steps(
Expand Down Expand Up @@ -85,7 +81,7 @@ def code_distance(
error_budget: float,
time_steps: float,
alg: 'AlgorithmSummary',
qec_scheme: 'QuantumErrorCorrectionSchemeSummary',
qec_scheme: 'QECScheme',
physical_error: float,
) -> int:
r"""Minimum code distance needed to run the algorithm within the error budget.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

import qualtran.testing as qlt_testing
from qualtran.resource_counting import GateCounts
from qualtran.surface_code import AlgorithmSummary, azure_cost_model
from qualtran.surface_code.quantum_error_correction_scheme_summary import (
BeverlandSuperconductingQubits,
)
from qualtran.surface_code import AlgorithmSummary, beverland_et_al_model, QECScheme
from qualtran.surface_code.rotation_cost_model import BeverlandEtAlRotationCost


Expand Down Expand Up @@ -83,31 +80,31 @@ class Test:

@pytest.mark.parametrize('test', _TESTS)
def test_minimum_time_step(test: Test):
got = azure_cost_model.minimum_time_steps(
got = beverland_et_al_model.minimum_time_steps(
error_budget=test.error_budget, alg=test.alg, rotation_model=BeverlandEtAlRotationCost
)
assert got == pytest.approx(test.c_min, rel=0.1)


@pytest.mark.parametrize('test', _TESTS)
def test_code_distance(test: Test):
got = azure_cost_model.code_distance(
got = beverland_et_al_model.code_distance(
error_budget=test.error_budget,
time_steps=test.time_steps,
alg=test.alg,
qec_scheme=BeverlandSuperconductingQubits,
qec_scheme=QECScheme.make_beverland_et_al(),
physical_error=1e-4,
)
assert got == test.code_distance


@pytest.mark.parametrize('test', _TESTS)
def test_t_states(test: Test):
got = azure_cost_model.t_states(
got = beverland_et_al_model.t_states(
error_budget=test.error_budget, alg=test.alg, rotation_model=BeverlandEtAlRotationCost
)
assert got == pytest.approx(test.t_states, rel=0.1)


def test_notebook():
qlt_testing.execute_notebook('azure_cost_model')
qlt_testing.execute_notebook('beverland_et_al_model')
Loading

0 comments on commit abd8323

Please sign in to comment.