graphix.noise_models.noise_model module

Abstract interface for noise models.

This module defines NoiseModel, the base class used by graphix.simulator.PatternSimulator when running noisy simulations. Child classes implement concrete noise processes by overriding the abstract methods defined here.

class Noise[source]

Bases: ABC

Abstract base class for noise.

abstract property nqubits: int

Return the number of qubits targetted by the noise.

abstractmethod to_krauschannel() → KrausChannel[source]

Return the Kraus channel describing the noise.

class ApplyNoise(noise: Noise, nodes: list[int], domain: set[int] | None = None)[source]

Bases: _KindChecker

Apply noise command.

Parameters:
  • noise (Noise) – noise to be applied

  • nodes (list[Node]) – list of node indices on which to apply noise

  • domain (set[Node] | None = None) – Optional domain for conditional noise. If None, the noise is applied unconditionally. Otherwise, the noise is applied if there is an odd number of nodes among domain that have been measured with outcome 1 (as for X and Z commands). Note that the noise is never applied if domain is the empty set.

kind: ClassVar[Literal[CommandKind.ApplyNoise]] = 9
noise: Noise
nodes: list[int]
domain: set[int] | None = None
__init__(noise: Noise, nodes: list[int], domain: set[int] | None = None) → None
CommandOrNoise: TypeAlias
class NoiseModel[source]

Bases: ABC

Abstract base class for all noise models.

abstractmethod input_nodes(nodes: Iterable[int], rng: Generator | None = None, *, stacklevel: int = 1) → list[CommandOrNoise][source]

Return the noise to apply to input nodes.

abstractmethod command(cmd: CommandOrNoise, rng: Generator | None = None, *, stacklevel: int = 1) → list[CommandOrNoise][source]

Return the noise to apply to the command cmd.

abstractmethod confuse_result(cmd: BaseM, result: Outcome, rng: Generator | None = None, *, stacklevel: int = 1) → Outcome[source]

Return a possibly flipped measurement outcome.

Parameters:
  • result (Outcome) – Ideal measurement result.

  • cmd (BaseM) – The measurement command that produced the given outcome.

Returns:

Possibly corrupted result.

Return type:

Outcome

transpile(sequence: Iterable[CommandOrNoise], rng: Generator | None = None, *, stacklevel: int = 1) → list[CommandOrNoise][source]

Apply the noise to a sequence of commands and return the resulting sequence.

class NoiselessNoiseModel[source]

Bases: NoiseModel

Noise model that performs no operation.

input_nodes(nodes: Iterable[int], rng: Generator | None = None, *, stacklevel: int = 1) → list[CommandOrNoise][source]

Return the noise to apply to input nodes.

command(cmd: CommandOrNoise, rng: Generator | None = None, *, stacklevel: int = 1) → list[CommandOrNoise][source]

Return the noise to apply to the command cmd.

confuse_result(cmd: BaseM, result: Outcome, rng: Generator | None = None, *, stacklevel: int = 1) → Outcome[source]

Assign wrong measurement result.

class ComposeNoiseModel(models: list[NoiseModel])[source]

Bases: NoiseModel

Compose noise models.

models: list[NoiseModel]
input_nodes(nodes: Iterable[int], rng: Generator | None = None, *, stacklevel: int = 1) → list[CommandOrNoise][source]

Return the noise to apply to input nodes.

command(cmd: CommandOrNoise, rng: Generator | None = None, *, stacklevel: int = 1) → list[CommandOrNoise][source]

Return the noise to apply to the command cmd.

confuse_result(cmd: BaseM, result: Outcome, rng: Generator | None = None, *, stacklevel: int = 1) → Outcome[source]

Assign wrong measurement result.

__init__(models: list[NoiseModel]) → None