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 17 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
87 changes: 87 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,87 @@
# 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 in human readable format.
"""

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 detection circuit."""
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved

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


@frozen
class SimpliedSurfaceCode(QuantumErrorCorrectionSchemeSummary):
"""A Surface Code Quantum Error Correction Scheme.

Attributes:
single_stabilizer_time_us: Max time of a single X or Z stabilizer measurement.
"""

single_stabilizer_time_us: float

def physical_qubits(self, code_distance: int) -> int:
return 2 * code_distance**2
mpharrigan marked this conversation as resolved.
Show resolved Hide resolved

def error_detection_circuit_time_us(self, code_distance: int) -> float:
"""Equals the time to measure a stabilizer times the depth of the circuit."""
return self.single_stabilizer_time_us * code_distance


BeverlandSuperConductingQubits = SimpliedSurfaceCode(
error_rate_scaler=0.03,
error_rate_threshold=0.01,
single_stabilizer_time_us=0.4, # Equals 4*t_gate+2*t_meas where t_gate=50ns and t_meas=100ns.
reference='https://arxiv.org/abs/2211.07629',
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.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]])
def test_physical_qubits(qec: qecs.QuantumErrorCorrectionSchemeSummary, want: int):
assert qec.physical_qubits(11) == want


@pytest.mark.parametrize('qec,want', [[qecs.BeverlandSuperConductingQubits, 4.8]])
def test_error_detection_cycle_time(qec: qecs.QuantumErrorCorrectionSchemeSummary, want: float):
assert qec.error_detection_circuit_time_us(12) == pytest.approx(want)
Loading