Source code for mrmustard.lab.transformations.attenuator

# Copyright 2023 Xanadu Quantum Technologies Inc.

# 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

#     http://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.

"""The class representing a noisy attenuator channel."""

from __future__ import annotations

from collections.abc import Sequence

from mrmustard.parameters import Parameter
from mrmustard.physics.ansatz_factory import AnsatzFactory
from mrmustard.physics.wires import ReprEnum, Wires

from .base import Channel
from .builtins import attenuator_channel

__all__ = ["Attenuator"]


[docs] class Attenuator(Channel): r"""The noisy attenuator channel. >>> from mrmustard import math >>> from mrmustard.lab import Attenuator >>> channel = Attenuator(mode=1, transmissivity=0.1) >>> assert channel.modes == (1,) >>> assert channel.parameters.transmissivity.value == 0.1 Args: mode: The mode this gate is applied to. transmissivity: The transmissivity. name: A name for the channel. If not provided, the class name will be used. .. details:: The :math:`N`-mode attenuator is defined as .. math:: X = \text{cos}(\theta)I_{2N} \text{ , } Y = \text{sin}^2(\theta)I_{2N} \text{ , and } d = O_{4N}\:, where the :math:`\theta=\text{arcos}(\sqrt{\bar{\eta}})`, :math:`\eta` is the transmissivity, and :math:`\text{diag}_N(\bar{\eta})` is the :math:`N\text{x}N` matrix with diagonal :math:`\bar{\eta}`. Its ``(A,b,c)`` triple is given by .. math:: A &= \begin{bmatrix} O_N & \text{diag}_N(\sqrt{\bar{\eta}}) & O_N & O_N \\ \text{diag}_N(\sqrt{\bar{\eta}}) & O_N & O_N & \text{diag}_N(1-\sqrt{\bar{\eta}})\\ O_N & O_N & O_N & \text{diag}_N(\sqrt{\bar{\eta}})\\ O_N & \text{diag}_N(1-\sqrt{\bar{\eta}}) & \text{diag}_N(\sqrt{\bar{\eta}}) & O_N \end{bmatrix} \\ \\ b &= O_{4N} \\ \\ c &= 1\:. """ short_name = "Att~" def __init__( self, mode: int | tuple[int], transmissivity: float | Sequence[float] | Parameter = 1.0, name: str | None = None, ): mode = (mode,) if not isinstance(mode, tuple) else mode name = name if name is not None else self.__class__.__name__ super().__init__( ansatz_factory=AnsatzFactory( ansatz_dict={ReprEnum.BARGMANN: (attenuator_channel, ("transmissivity", "lin_sup"))} ), wires=Wires( modes_in_bra=set(mode), modes_out_bra=set(mode), modes_in_ket=set(mode), modes_out_ket=set(mode), ), name=name, ) self.parameters["transmissivity"] = Parameter.from_cc_init( transmissivity, "float64", f"{self.name}/transmissivity" )