Skip to content

Commit

Permalink
[surface code] DataBlock refactor (#1141)
Browse files Browse the repository at this point in the history
* DataBlock refactor

* fix notebook

* Spell everything

* Fix notebook
  • Loading branch information
mpharrigan authored Jul 18, 2024
1 parent a8528f0 commit fb6f3e4
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 128 deletions.
1 change: 1 addition & 0 deletions qualtran/surface_code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
BeverlandSuperconductingQubits,
BeverlandTrappedIonQubits,
FowlerSuperconductingQubits,
LogicalErrorModel,
QuantumErrorCorrectionSchemeSummary,
)
from qualtran.surface_code.reference import Reference
Expand Down
15 changes: 7 additions & 8 deletions qualtran/surface_code/azure_cost_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"source": [
"from qualtran.surface_code.data_block import FastDataBlock\n",
"\n",
"logical_qubits = FastDataBlock.grid_size(n_algo_qubits=quantum_dynamics_specs.algorithm_qubits)\n",
"logical_qubits = FastDataBlock.get_n_tiles(n_algo_qubits=quantum_dynamics_specs.algorithm_qubits)\n",
"\n",
"print('Q =', logical_qubits)"
]
Expand Down Expand Up @@ -398,7 +398,7 @@
"metadata": {},
"outputs": [],
"source": [
"logical_qubits = FastDataBlock.grid_size(n_algo_qubits=quantum_chemistry_specs.algorithm_qubits)\n",
"logical_qubits = FastDataBlock.get_n_tiles(n_algo_qubits=quantum_chemistry_specs.algorithm_qubits)\n",
"\n",
"print('Q =', logical_qubits)"
]
Expand Down Expand Up @@ -572,7 +572,7 @@
"metadata": {},
"outputs": [],
"source": [
"logical_qubits = FastDataBlock.grid_size(n_algo_qubits=shor_specs.algorithm_qubits)\n",
"logical_qubits = FastDataBlock.get_n_tiles(n_algo_qubits=shor_specs.algorithm_qubits)\n",
"\n",
"print('Q =', logical_qubits)"
]
Expand Down Expand Up @@ -699,7 +699,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "qualtran",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -713,10 +713,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
},
"orig_nbformat": 4
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion qualtran/surface_code/azure_cost_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def code_distance(
qec: Quantum Error Correction Scheme.
physical_error_rate: The physical error rate of the device.
"""
q = FastDataBlock.grid_size(n_algo_qubits=int(alg.algorithm_qubits))
q = FastDataBlock.get_n_tiles(n_algo_qubits=int(alg.algorithm_qubits))
return qec.code_distance_from_budget(physical_error_rate, error_budget / (3 * q * time_steps))


Expand Down
5 changes: 5 additions & 0 deletions qualtran/surface_code/azure_cost_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pytest
from attrs import frozen

import qualtran.testing as qlt_testing
from qualtran.surface_code import azure_cost_model
from qualtran.surface_code.algorithm_summary import AlgorithmSummary
from qualtran.surface_code.quantum_error_correction_scheme_summary import (
Expand Down Expand Up @@ -109,3 +110,7 @@ def test_t_states(test: Test):
test.error_budget, 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')
19 changes: 9 additions & 10 deletions qualtran/surface_code/ccz2t_cost_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,20 @@ def get_ccz2t_costs(
factory: magic state factory configuration. Used to evaluate distillation error and cost.
data_block: data block configuration. Used to evaluate data error and footprint.
"""
err_model = qec.LogicalErrorModel(
qec_scheme=qec.FowlerSuperconductingQubits, physical_error=phys_err
)
distillation_error = factory.distillation_error(n_magic=n_magic, phys_err=phys_err)
n_generation_cycles = factory.n_cycles(n_magic=n_magic, phys_err=phys_err)
n_consumption_cycles = (
n_magic.n_t / 4 + n_magic.n_ccz
) * data_block.n_cycles_to_consume_a_magic_state()
n_consumption_cycles = data_block.n_cycles(
n_logical_gates=n_magic, logical_error_model=err_model
)
n_cycles = max(n_generation_cycles, n_consumption_cycles)
data_error = data_block.data_error(
n_algo_qubits=n_algo_qubits, n_cycles=int(n_cycles), phys_err=phys_err
n_algo_qubits=n_algo_qubits, n_cycles=int(n_cycles), logical_error_model=err_model
)
failure_prob = distillation_error + data_error
footprint = factory.footprint() + data_block.footprint(n_algo_qubits=n_algo_qubits)
footprint = factory.footprint() + data_block.n_physical_qubits(n_algo_qubits=n_algo_qubits)
duration_hr = (cycle_time_us * n_cycles) / (1_000_000 * 60 * 60)

return PhysicalCost(failure_prob=failure_prob, footprint=footprint, duration_hr=duration_hr)
Expand Down Expand Up @@ -255,11 +258,7 @@ def get_ccz2t_costs_from_error_budget(
data_d = qec.FowlerSuperconductingQubits.code_distance_from_budget(
physical_error_rate=phys_err, budget=target_err_per_round
)
data_block = SimpleDataBlock(
data_d=data_d,
routing_overhead=routing_overhead,
qec_scheme=qec.FowlerSuperconductingQubits,
)
data_block = SimpleDataBlock(data_d=data_d, routing_overhead=routing_overhead)

return get_ccz2t_costs(
n_magic=n_magic,
Expand Down
Loading

0 comments on commit fb6f3e4

Please sign in to comment.