Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a summary of QEC algorithms class #378

Merged
merged 25 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions qualtran/surface_code/quantum_error_correction_scheme_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import abc

import numpy as np
from attrs import field, frozen


@frozen
class QuantumErrorCorrectionSchemeSummary(abc.ABC):
r"""QuantumErrorCorrectionSchemeSummary represents a high level view of a QEC scheme.

QuantumErrorCorrectionSchemeSummary provides estimates for the logical error rate,
number of physical qubits and the time of an error detection cycle.

The logical error rate as a function of code distance $d$ and physical error rate $p$
is given by
$$
a \left ( \frac{p}{p^*} \right )^\frac{d + 1}{2}
$$
Where $a$ is the error_rate_scaler and $p^*$ is the error_rate_threshold.

Note: The logical error-suppression factor $\Lambda = \frac{p^*}{p}$

Attributes:
error_rate_scaler: Logical error rate coefficient.
error_rate_threshold: Logical error rate threshold.
reference: source of the estimates.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you be more specific about what this is supposed to be. Comma separated list of urls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now I see it as just a human readable string

"""

error_rate_scaler: float = field(repr=lambda x: f'{x:g}')
error_rate_threshold: float = field(repr=lambda x: f'{x:g}')
reference: str | None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have default value of None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I do then any attribute in any class that inherets this class must have a default value

qualtran/surface_code/quantum_error_correction_scheme_summary_test.py:17: in <module>
    from qualtran.surface_code import quantum_error_correction_scheme_summary as qecs
qualtran/surface_code/quantum_error_correction_scheme_summary.py:72: in <module>
    class SimpliedSurfaceCode(SurfaceCode):
../../../anaconda3/envs/qualtran-env/lib/python3.10/site-packages/attr/_next_gen.py:147: in define
    return wrap(maybe_cls)
../../../anaconda3/envs/qualtran-env/lib/python3.10/site-packages/attr/_next_gen.py:138: in wrap
    return do_it(cls, True)
../../../anaconda3/envs/qualtran-env/lib/python3.10/site-packages/attr/_next_gen.py:83: in do_it
    return attrs(
../../../anaconda3/envs/qualtran-env/lib/python3.10/site-packages/attr/_make.py:1629: in attrs
    return wrap(maybe_cls)
../../../anaconda3/envs/qualtran-env/lib/python3.10/site-packages/attr/_make.py:1525: in wrap
    builder = _ClassBuilder(
../../../anaconda3/envs/qualtran-env/lib/python3.10/site-packages/attr/_make.py:694: in __init__
    attrs, base_attrs, base_map = _transform_attrs(
../../../anaconda3/envs/qualtran-env/lib/python3.10/site-packages/attr/_make.py:602: in _transform_attrs
    raise ValueError(
E   ValueError: No mandatory attributes allowed after an attribute with a default value or factory.  Attribute in question: Attribute(name='error_detection_cycle_time_slope_us',

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


def logical_error_rate(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a general form of formulae.error_at. Please refactor to remove the duplicate code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the formulae.py file. the two methods there correspond to calling the appropiate methods of a SimpeSurfaceCode with the correct parameters

self, code_distance: int, physical_error_rate: float | np.ndarray
) -> float | np.ndarray:
"""The logical error rate given the physical error rate."""
return self.error_rate_scaler * np.power(
physical_error_rate / self.error_rate_threshold, (code_distance + 1) / 2
)

@abc.abstractmethod
def physical_qubits(self, code_distance: int) -> int:
"""The number of physical qubits used by the error correction circuit."""

@abc.abstractmethod
def error_detection_cycle_time(self, code_distance: int) -> float:
"""The time of a quantum error correction cycle in seconds."""
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved


class SurfaceCode(QuantumErrorCorrectionSchemeSummary):
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved
"""A Surface Code Quantum Error Correction Scheme."""

def physical_qubits(self, code_distance: int) -> int:
return 2 * code_distance**2


@frozen
class SimpliedSurfaceCode(SurfaceCode):
r"""SimpliedSurfaceCode assumes the error detection time is a linear function in code distance.
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved

The error detection time $\tau(d)$ is assumed to be given by a linear function
$$
\tau(d) = a*d + b
$$
Where $a$ is the `error_detection_cycle_time_slope_us` and $b$ is `error_detection_cycle_time_intercept_us`
both of which depend only on the hardware.

Attributes:
error_detection_cycle_time_slope_us:
error_detection_cycle_time_intercept_us: float
"""

error_detection_cycle_time_slope_us: float
error_detection_cycle_time_intercept_us: float

def error_detection_cycle_time(self, code_distance: int) -> float:
return (
self.error_detection_cycle_time_slope_us * code_distance
+ self.error_detection_cycle_time_intercept_us
) * 1e-6
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved


Fowler = SimpliedSurfaceCode(
error_rate_scaler=0.1,
error_rate_threshold=0.01,
# The Fowler model assumes an error detection time of 1us regardless of the code distance.
error_detection_cycle_time_slope_us=0,
error_detection_cycle_time_intercept_us=1,
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved
reference='https://arxiv.org/pdf/1808.06709.pdf,https://arxiv.org/pdf/1208.0928.pdf',
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved
)

# The Beverland model assumes an error detection time equal to a*d, where slope a depends only on the hardware.
BeverlandTrappedIonQubits = SimpliedSurfaceCode(
error_rate_scaler=0.03,
error_rate_threshold=0.01,
error_detection_cycle_time_slope_us=600,
error_detection_cycle_time_intercept_us=0,
reference='https://arxiv.org/pdf/2211.07629.pdf',
)
BeverlandSuperConductingQubits = SimpliedSurfaceCode(
error_rate_scaler=0.03,
error_rate_threshold=0.01,
error_detection_cycle_time_slope_us=0.4,
error_detection_cycle_time_intercept_us=0,
reference='https://arxiv.org/pdf/2211.07629.pdf',
)
BeverlandMajoranaQubits = SimpliedSurfaceCode(
error_rate_scaler=0.03,
error_rate_threshold=0.01,
error_detection_cycle_time_slope_us=0.6,
error_detection_cycle_time_intercept_us=0,
reference='https://arxiv.org/pdf/2211.07629.pdf',
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from qualtran.surface_code import quantum_error_correction_scheme_summary as qecs


@pytest.mark.parametrize(
'qec,want', [(qecs.Fowler, 1e-3), (qecs.BeverlandSuperConductingQubits, 3e-4)]
)
def test_logical_error_rate(qec: qecs.QuantumErrorCorrectionSchemeSummary, want: float):
assert qec.logical_error_rate(3, 1e-3) == pytest.approx(want)


@pytest.mark.parametrize(
'qec,want', [[qecs.BeverlandSuperConductingQubits, 242], [qecs.Fowler, 242]]
)
def test_physical_qubits(qec: qecs.QuantumErrorCorrectionSchemeSummary, want: int):
assert qec.physical_qubits(11) == want


@pytest.mark.parametrize(
'qec,want', [[qecs.BeverlandSuperConductingQubits, 4.8e-6], [qecs.Fowler, 1e-6]]
)
def test_error_detection_cycle_time(qec: qecs.QuantumErrorCorrectionSchemeSummary, want: float):
assert qec.error_detection_cycle_time(12) == pytest.approx(want)
Loading