Source code for mrmustard.lab.transformations.identity
# 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 classes representing an identity gate."""
from __future__ import annotations
from mrmustard.physics.ansatz_factory import AnsatzFactory
from mrmustard.physics.wires import ReprEnum, Wires
from .base import Unitary
from .builtins import identity_gate
__all__ = ["Identity"]
[docs]
class Identity(Unitary):
r"""The identity gate.
>>> from mrmustard.lab import Identity
>>> unitary = Identity(modes=(1, 2))
>>> assert unitary.modes == (1, 2)
Args:
modes: The modes this gate is applied to.
name: A name for the gate. If not provided, the class name will be used.
.. details::
The Abc parametrization of the identity gate is given by (c.f. https://www.scipost.org/10.21468/SciPostPhys.17.3.082)
.. math::
A = \begin{pmatrix}
0 & 1 \\
1 & 0
\end{pmatrix},
\quad
b = \begin{pmatrix}
0 \\
0
\end{pmatrix},
\quad
c = 1
"""
short_name = "I"
def __init__(
self,
modes: int | tuple[int, ...],
name: str | None = None,
):
modes = (modes,) if isinstance(modes, int) else modes
name = name if name is not None else self.__class__.__name__
super().__init__(
ansatz_factory=AnsatzFactory(
ansatz_dict={ReprEnum.BARGMANN: (identity_gate, ("n_modes", "lin_sup"))},
n_modes=len(modes),
),
wires=Wires(
modes_in_bra=set(),
modes_out_bra=set(),
modes_in_ket=set(modes),
modes_out_ket=set(modes),
),
name=name,
)
_modules/mrmustard/lab/transformations/identity
Download Python script
Download Notebook
View on GitHub