-
Notifications
You must be signed in to change notification settings - Fork 66
Add amplitude damping noise model (#497) #540
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
Open
NandanPatel24
wants to merge
14
commits into
TeamGraphix:master
Choose a base branch
from
NandanPatel24:amplitude-damping-noise
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c33e65b
Add amplitude damping noise model (#497)
2deb23a
Merge branch 'master' into amplitude-damping-noise
NandanPatel24 cf1e21d
Merge branch 'master' into amplitude-damping-noise
NandanPatel24 bec57de
Apply ruff format
096f00a
Merge branch 'amplitude-damping-noise' of https://github.com/NandanPa…
2dc824d
Add per-step analytic tests and fix docstring raw-string lint
af09971
Fix lint and type errors in amplitude damping tests
dda1110
Add tests for amplitude damping noise model coverage
54cfebe
Add measure_error_prob, RZ analytic tests, and branch coverage for am…
c3f8c7c
Used the Ops functionality, ensured all function calls are standardized
ebad847
Made reviewer changes
6bd72e5
Merge branch 'master' into amplitude-damping-noise
NandanPatel24 ff8a83b
Updated CHANGELOG.md
d22d508
Merge branch 'amplitude-damping-noise' of https://github.com/NandanPa…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| """Amplitude damping noise model.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import typing_extensions | ||
|
|
||
| from graphix.channels import ( | ||
| KrausChannel, | ||
| amplitude_damping_channel, | ||
| two_qubit_amplitude_damping_channel, | ||
| ) | ||
| from graphix.command import BaseM, CommandKind | ||
| from graphix.measurements import toggle_outcome | ||
| from graphix.noise_models.noise_model import ApplyNoise, Noise, NoiseModel | ||
| from graphix.rng import ensure_rng | ||
| from graphix.utils import Probability | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Iterable | ||
|
|
||
| from numpy.random import Generator | ||
|
|
||
| from graphix.measurements import Outcome | ||
| from graphix.noise_models.noise_model import CommandOrNoise | ||
|
|
||
|
|
||
| class AmplitudeDampingNoise(Noise): | ||
| """One-qubit amplitude damping noise with damping parameter ``prob``.""" | ||
|
|
||
| prob = Probability() | ||
|
|
||
| def __init__(self, prob: float) -> None: | ||
| r"""Initialize one-qubit amplitude damping noise. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| prob : float | ||
| Damping parameter :math:`\\gamma` of the noise, between 0 and 1. | ||
| """ | ||
| self.prob = prob | ||
|
|
||
| @property | ||
| @typing_extensions.override | ||
| def nqubits(self) -> int: | ||
| """Return the number of qubits targetted by the noise element.""" | ||
| return 1 | ||
|
|
||
| @typing_extensions.override | ||
| def to_kraus_channel(self) -> KrausChannel: | ||
| """Return the Kraus channel describing the noise element.""" | ||
| return amplitude_damping_channel(self.prob) | ||
|
|
||
|
|
||
| class TwoQubitAmplitudeDampingNoise(Noise): | ||
| """Two-qubit amplitude damping noise with damping parameter ``prob``.""" | ||
|
|
||
| prob = Probability() | ||
|
|
||
| def __init__(self, prob: float) -> None: | ||
| r"""Initialize two-qubit amplitude damping noise. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| prob : float | ||
| Damping parameter :math:`\\gamma` of the noise, between 0 and 1. | ||
| """ | ||
| self.prob = prob | ||
|
|
||
| @property | ||
| @typing_extensions.override | ||
| def nqubits(self) -> int: | ||
| """Return the number of qubits targetted by the noise element.""" | ||
| return 2 | ||
|
|
||
| @typing_extensions.override | ||
| def to_kraus_channel(self) -> KrausChannel: | ||
| """Return the Kraus channel describing the noise element.""" | ||
| return two_qubit_amplitude_damping_channel(self.prob) | ||
|
|
||
|
|
||
| class AmplitudeDampingNoiseModel(NoiseModel): | ||
| r"""Amplitude damping noise model. | ||
|
|
||
| :param NoiseModel: Parent abstract class class:`NoiseModel` | ||
| :type NoiseModel: class | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| prepare_error_prob: float = 0.0, | ||
| x_error_prob: float = 0.0, | ||
| z_error_prob: float = 0.0, | ||
| entanglement_error_prob: float = 0.0, | ||
| measure_channel_prob: float = 0.0, | ||
| measure_error_prob: float = 0.0, | ||
| ) -> None: | ||
| self.prepare_error_prob = prepare_error_prob | ||
| self.x_error_prob = x_error_prob | ||
| self.z_error_prob = z_error_prob | ||
| self.entanglement_error_prob = entanglement_error_prob | ||
| self.measure_channel_prob = measure_channel_prob | ||
| self.measure_error_prob = measure_error_prob | ||
|
|
||
| @typing_extensions.override | ||
| def input_nodes( | ||
| self, nodes: Iterable[int], rng: Generator | None = None, *, stacklevel: int = 1 | ||
| ) -> list[CommandOrNoise]: | ||
| """Return the noise to apply to input nodes.""" | ||
| return [ApplyNoise(noise=AmplitudeDampingNoise(self.prepare_error_prob), nodes=[node]) for node in nodes] | ||
|
|
||
| @typing_extensions.override | ||
| def command( | ||
| self, cmd: CommandOrNoise, rng: Generator | None = None, *, stacklevel: int = 1 | ||
| ) -> list[CommandOrNoise]: | ||
| """Return the noise to apply to the command ``cmd``.""" | ||
| match cmd.kind: | ||
| case CommandKind.N: | ||
| return [cmd, ApplyNoise(noise=AmplitudeDampingNoise(self.prepare_error_prob), nodes=[cmd.node])] | ||
| case CommandKind.E: | ||
| return [ | ||
| cmd, | ||
| ApplyNoise( | ||
| noise=TwoQubitAmplitudeDampingNoise(self.entanglement_error_prob), nodes=list(cmd.nodes) | ||
| ), | ||
| ] | ||
| case CommandKind.M: | ||
| return [ApplyNoise(noise=AmplitudeDampingNoise(self.measure_channel_prob), nodes=[cmd.node]), cmd] | ||
| case CommandKind.X: | ||
| return [ | ||
| cmd, | ||
| ApplyNoise(noise=AmplitudeDampingNoise(self.x_error_prob), nodes=[cmd.node], domain=cmd.domain), | ||
| ] | ||
| case CommandKind.Z: | ||
| return [ | ||
| cmd, | ||
| ApplyNoise(noise=AmplitudeDampingNoise(self.z_error_prob), nodes=[cmd.node], domain=cmd.domain), | ||
| ] | ||
| case CommandKind.C | CommandKind.T | CommandKind.ApplyNoise: | ||
| return [cmd] | ||
| case CommandKind.S: | ||
| raise ValueError("Unexpected signal!") | ||
| case _: # pragma: no cover | ||
| typing_extensions.assert_never(cmd.kind) | ||
|
|
||
| @typing_extensions.override | ||
| def confuse_result( | ||
| self, cmd: BaseM, result: Outcome, rng: Generator | None = None, *, stacklevel: int = 1 | ||
| ) -> Outcome: | ||
| """Assign wrong measurement result with probability ``measure_error_prob``.""" | ||
| rng = ensure_rng(rng, stacklevel=stacklevel + 1) | ||
| if rng.uniform() < self.measure_error_prob: | ||
| return toggle_outcome(result) | ||
| return result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.