-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Description This pull request suggests to introduce new noise model for qudits. It consists of two ideas: "Mathematical Noise" & "Physical Noise". There are some limitations as follows now. * The data structure of Noise is defined. * It is supported by only `tnsim`, not `misim`. * To clear the tests, some code changes are made in `misim`. * However, `misim` cannot simulate neither correctly. ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are related to it. - [x] I have added appropriate tests and documentation. - [x] I have made sure that all CI jobs on GitHub pass. - [x] The pull request introduces no new warnings and follows the project's style guidelines. Co-authored-by: Yusuke Kimura <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b12cbb1
commit 980f666
Showing
16 changed files
with
887 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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 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 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,88 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
|
||
from ..components.extensions.gate_types import GateTypes | ||
from ..gate import Gate | ||
|
||
if TYPE_CHECKING: | ||
from numpy.typing import NDArray | ||
|
||
from ..circuit import QuantumCircuit | ||
from ..components.extensions.controls import ControlData | ||
from ..gate import Parameter | ||
|
||
|
||
class NoiseX(Gate): | ||
def __init__( | ||
self, | ||
circuit: QuantumCircuit, | ||
name: str, | ||
target_qudits: int, | ||
parameters: list[int], | ||
dimensions: int, | ||
controls: ControlData | None = None, | ||
) -> None: | ||
super().__init__( | ||
circuit=circuit, | ||
name=name, | ||
gate_type=GateTypes.SINGLE, | ||
target_qudits=target_qudits, | ||
dimensions=dimensions, | ||
control_set=controls, | ||
qasm_tag="noisex", | ||
) | ||
|
||
if self.validate_parameter(parameters): | ||
self.original_lev_a: int = parameters[0] | ||
self.original_lev_b: int = parameters[1] | ||
self.lev_a, self.lev_b = self.levels_setter(self.original_lev_a, self.original_lev_b) | ||
self._params = parameters | ||
|
||
def __array__(self) -> NDArray: # noqa: PLW3201 | ||
dimension = self.dimensions | ||
matrix = np.identity(dimension, dtype="complex") | ||
|
||
matrix[self.lev_a, self.lev_a] = 0.0 | ||
matrix[self.lev_b, self.lev_b] = 0.0 | ||
matrix[self.lev_a, self.lev_b] = 1.0 | ||
matrix[self.lev_b, self.lev_a] = 1.0 | ||
|
||
return matrix | ||
|
||
@staticmethod | ||
def levels_setter(la: int, lb: int) -> tuple[int, int]: | ||
if la < lb: | ||
return la, lb | ||
return lb, la | ||
|
||
def validate_parameter(self, parameter: Parameter) -> bool: | ||
if parameter is None: | ||
return False | ||
|
||
if isinstance(parameter, list): | ||
assert isinstance(parameter[0], int) | ||
assert isinstance(parameter[1], int) | ||
assert parameter[0] >= 0 | ||
assert parameter[0] < self.dimensions | ||
assert parameter[1] >= 0 | ||
assert parameter[1] < self.dimensions | ||
assert parameter[0] != parameter[1] | ||
# Useful to remember direction of the rotation | ||
self.original_lev_a = parameter[0] | ||
self.original_lev_b = parameter[1] | ||
|
||
return True | ||
|
||
if isinstance(parameter, np.ndarray): | ||
# Add validation for numpy array if needed | ||
return False | ||
|
||
return False | ||
|
||
@property | ||
def dimensions(self) -> int: | ||
assert isinstance(self._dimensions, int), "Dimensions must be an integer" | ||
return self._dimensions |
This file contains 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,88 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
|
||
from ..components.extensions.gate_types import GateTypes | ||
from ..gate import Gate | ||
|
||
if TYPE_CHECKING: | ||
from numpy.typing import NDArray | ||
|
||
from ..circuit import QuantumCircuit | ||
from ..components.extensions.controls import ControlData | ||
from ..gate import Parameter | ||
|
||
|
||
class NoiseY(Gate): | ||
def __init__( | ||
self, | ||
circuit: QuantumCircuit, | ||
name: str, | ||
target_qudits: int, | ||
parameters: list[int], | ||
dimensions: int, | ||
controls: ControlData | None = None, | ||
) -> None: | ||
super().__init__( | ||
circuit=circuit, | ||
name=name, | ||
gate_type=GateTypes.SINGLE, | ||
target_qudits=target_qudits, | ||
dimensions=dimensions, | ||
control_set=controls, | ||
qasm_tag="noisey", | ||
) | ||
|
||
if self.validate_parameter(parameters): | ||
self.original_lev_a: int = parameters[0] | ||
self.original_lev_b: int = parameters[1] | ||
self.lev_a, self.lev_b = self.levels_setter(self.original_lev_a, self.original_lev_b) | ||
self._params = parameters | ||
|
||
def __array__(self) -> NDArray: # noqa: PLW3201 | ||
dimension = self.dimensions | ||
matrix = np.identity(dimension, dtype="complex") | ||
|
||
matrix[self.lev_a, self.lev_a] = 0.0 | ||
matrix[self.lev_b, self.lev_b] = 0.0 | ||
matrix[self.lev_a, self.lev_b] = -1j | ||
matrix[self.lev_b, self.lev_a] = 1j | ||
|
||
return matrix | ||
|
||
@staticmethod | ||
def levels_setter(la: int, lb: int) -> tuple[int, int]: | ||
if la < lb: | ||
return la, lb | ||
return lb, la | ||
|
||
def validate_parameter(self, parameter: Parameter) -> bool: | ||
if parameter is None: | ||
return False | ||
|
||
if isinstance(parameter, list): | ||
assert isinstance(parameter[0], int) | ||
assert isinstance(parameter[1], int) | ||
assert parameter[0] >= 0 | ||
assert parameter[0] < self.dimensions | ||
assert parameter[1] >= 0 | ||
assert parameter[1] < self.dimensions | ||
assert parameter[0] != parameter[1] | ||
# Useful to remember direction of the rotation | ||
self.original_lev_a = parameter[0] | ||
self.original_lev_b = parameter[1] | ||
|
||
return True | ||
|
||
if isinstance(parameter, np.ndarray): | ||
# Add validation for numpy array if needed | ||
return False | ||
|
||
return False | ||
|
||
@property | ||
def dimensions(self) -> int: | ||
assert isinstance(self._dimensions, int), "Dimensions must be an integer" | ||
return self._dimensions |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
from .noise import Noise, NoiseModel | ||
from .noise import Noise, NoiseModel, SubspaceNoise | ||
from .noisy_circuit_factory import NoisyCircuitFactory | ||
|
||
__all__ = ["Noise", "NoiseModel", "NoisyCircuitFactory"] | ||
__all__ = ["Noise", "NoiseModel", "NoisyCircuitFactory", "SubspaceNoise"] |
Oops, something went wrong.