|
22 | 22 | import numpy as np |
23 | 23 |
|
24 | 24 | from mrmustard import math, settings |
25 | | -from mrmustard.utils.typing import Matrix, Vector, Scalar, RealMatrix |
| 25 | +from mrmustard.utils.typing import Matrix, Vector, Scalar, RealMatrix, ComplexMatrix |
26 | 26 | from mrmustard.physics.gaussian_integrals import complex_gaussian_integral_2 |
27 | 27 |
|
28 | 28 |
|
@@ -778,3 +778,64 @@ def attenuator_kraus_Abc(eta: float) -> Union[Matrix, Vector, Scalar]: |
778 | 778 | b = _vacuum_B_vector(3) |
779 | 779 | c = 1.0 + 0j |
780 | 780 | return A, b, c |
| 781 | + |
| 782 | + |
| 783 | +def XY_to_channel_Abc(X: RealMatrix, Y: RealMatrix, d: Vector | None = None) -> ComplexMatrix: |
| 784 | + r""" |
| 785 | + The method to compute the A matrix of a channel based on its X, Y, and d. |
| 786 | + Args: |
| 787 | + X: The X matrix of the channel |
| 788 | + Y: The Y matrix of the channel |
| 789 | + d: The d (displacement) vector of the channel -- if None, we consider it as 0 |
| 790 | + """ |
| 791 | + |
| 792 | + m = Y.shape[-1] // 2 |
| 793 | + # considering no displacement if d is None |
| 794 | + d = d if d else math.zeros(2 * m) |
| 795 | + |
| 796 | + if X.shape != Y.shape: |
| 797 | + raise ValueError( |
| 798 | + "The dimension of X and Y matrices are not the same." |
| 799 | + f"X.shape = {X.shape}, Y.shape = {Y.shape}" |
| 800 | + ) |
| 801 | + |
| 802 | + xi = 1 / 2 * math.eye(2 * m, dtype=math.complex128) + 1 / 2 * X @ X.T + Y / settings.HBAR |
| 803 | + xi_inv = math.inv(xi) |
| 804 | + xi_inv_in_blocks = math.block( |
| 805 | + [[math.eye(2 * m) - xi_inv, xi_inv @ X], [X.T @ xi_inv, math.eye(2 * m) - X.T @ xi_inv @ X]] |
| 806 | + ) |
| 807 | + R = ( |
| 808 | + 1 |
| 809 | + / math.sqrt(complex(2)) |
| 810 | + * math.block( |
| 811 | + [ |
| 812 | + [ |
| 813 | + math.eye(m, dtype=math.complex128), |
| 814 | + 1j * math.eye(m, dtype=math.complex128), |
| 815 | + math.zeros((m, 2 * m), dtype=math.complex128), |
| 816 | + ], |
| 817 | + [ |
| 818 | + math.zeros((m, 2 * m), dtype=math.complex128), |
| 819 | + math.eye(m, dtype=math.complex128), |
| 820 | + -1j * math.eye(m, dtype=math.complex128), |
| 821 | + ], |
| 822 | + [ |
| 823 | + math.eye(m, dtype=math.complex128), |
| 824 | + -1j * math.eye(m, dtype=math.complex128), |
| 825 | + math.zeros((m, 2 * m), dtype=math.complex128), |
| 826 | + ], |
| 827 | + [ |
| 828 | + math.zeros((m, 2 * m), dtype=math.complex128), |
| 829 | + math.eye(m, dtype=math.complex128), |
| 830 | + 1j * math.eye(m, dtype=math.complex128), |
| 831 | + ], |
| 832 | + ] |
| 833 | + ) |
| 834 | + ) |
| 835 | + |
| 836 | + A = math.Xmat(2 * m) @ R @ xi_inv_in_blocks @ math.conj(R).T |
| 837 | + temp = math.block([[(xi_inv @ d).reshape(2 * m, 1)], [(-X.T @ xi_inv @ d).reshape((2 * m, 1))]]) |
| 838 | + b = 1 / math.sqrt(settings.HBAR) * math.conj(R) @ temp |
| 839 | + c = math.exp(-0.5 / settings.HBAR * d @ xi_inv @ d) / math.sqrt(math.det(xi)) |
| 840 | + |
| 841 | + return A, b, c |
0 commit comments