# Source code for flamingpy.noise.iid

# Copyright 2022 Xanadu Quantum Technologies Inc.

# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# Unless required by applicable law or agreed to in writing, software
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
"""An implementation of IID Pauli noise."""

from numpy.random import default_rng

[docs]class IidNoise:
"""Noise sampler for independent and identically distributed Z errors on
the qubits of a cluster state.

Args:
code (SurfaceCode): the code on which to apply the noise.
error_probability (float): the probability of a Z error.
"""

def __init__(self, code, error_probability):
self.egraph = code.graph

if error_probability < 0.0 or error_probability > 1.0:
raise ValueError("Probability is not between 0 and 1.")

self.error_probability = error_probability

[docs]    def apply_noise(self, rng=default_rng()):
"""Apply the noise to the code.

This fixes the "bit_val" attribute of each node in the code egraph.

Args:
rng (numpy.random.Generator, optional): a random number generator
following the NumPy API. It can be seeded for reproducibility.
By default, numpy.random.default_rng is used without a fixed seed.
"""
for _, node_data in self.egraph.nodes.data():
node_data["bit_val"] = int(rng.random() < self.error_probability)


Home

Background

Using FlamingPy

Development

Getting Help

Python API