【发布时间】:2019-07-06 15:21:30
【问题描述】:
假设我们有 3 个Pauli matrices,每个都有尺寸 (2x2)。如下图:
X = np.array([[0, 1], [1, 0]], dtype=complex)
Y = np.array([[0, -1j], [1j, 0]], dtype=complex)
Z = np.array([[1, 0], [0, -1]], dtype=complex)
现在,如果我将这些每个单独的 (2x2) 矩阵作为另一个 (2x2) 矩阵的条目。说:
A = np.array([[X, 0], [0, Y]])
B = np.array([[X, X], [Y, Y]])
奇怪的是,A 的暗度为 (2x2) - 这是我想要的理想值 - 而 B 的暗度为 (2, 2, 2, 2),无论这是什么,如下所示
A = np.array([[X, 0], [0, Y]])
A.shape
Out[131]: (2, 2)
B = np.array([[X, X], [Y, Y]])
B.shape
Out[133]: (2, 2, 2, 2)
另一方面,假设C 为(1x3) 矩阵,D 为(1x2) 矩阵,例如
C = np.array([[X, Y, 0]])
D = np.array([[X, Y]])
如果我们再次查看初始化矩阵的维度
C = np.array([[X, Y, 0]])
C.shape
Out[136]: (1, 3)
D = np.array([[X, Y]])
D.shape
Out[138]: (1, 2, 2, 2)
所以似乎每当我在这样的数组中初始化数组时,如果有混合数据类型作为条目,即矩阵和整数,如A和C,它会给我我想要的合理形状,即维度@ 987654335@,每个条目的“隐藏”维度为(2x2)。但是只要条目只是像BandD 这样的严格矩阵,它就会给我带来诸如(2, 2, 2, 2) 之类的无意义的维度。所以我的问题是:
如何使用严格的 (2, 2) 矩阵作为条目来初始化 (n, n) numpy 数组(矩阵),并且仍然保留其 (n, n) 维度,即,而不是给我一些奇怪的 numpy 维度 (w, x, y, z)?
我想要这个的原因是因为我正在使用量子力学中的运算符进行计算,使用这些泡利矩阵,例如 X、Y 和 Z,作为量子计算中的量子门。所以如果我有一些状态 rho 这也是一个 (2x2) 矩阵。让
rho = np.array([[1, 0],
[0, 0]])
让RHO 成为(2x2) 对角矩阵,其条目是(2x2) rho 矩阵。
RHO = np.array([[rho, 0],
[0, rho]])
我希望计算像np.dot(D, RHO) 这样的东西
np.array([np.dot(X, rho), 0],
[0, np.dot(Y, rho)])
我在 python 上检查了两个 (2x2) 矩阵的点积,其中 (2x2) 矩阵作为条目,它的条目乘法也都将是点积。
我对上面谈到的所有内容的动机是我希望使用这些属性作为矢量化我的算法的手段。目前,我的算法的一个非常粗略的示例如下所示:
for i in (integer_1):
for j in (integer_2):
#do something that involves operations with sums of dot products of many matrices#
并将其矢量化,使其可能成为
for i in (integer_1):
#do something that involves operations with multiples of matrices with dot product of matrices as its entries#
这可能有效,或者无效!但我很想知道我的这种方法是否会加快速度。 我希望我已经很好地解释了我的问题。 提前致谢。
编辑(1)
I've added latex formatted maths so hopefully you can understand what I'm trying to do.
def compute_channel_operation(rho, operators):
"""
Given a quantum state's density function rho, the effect of the
channel on this state is:
rho -> sum_{i=1}^n E_i * rho * E_i^dagger
Args:
rho (2x2 matrix): Density function
operators (list): List of operators(matrices)
Returns:
number: The result of applying the list of operators
"""
operation = [E@rho@E.conj().T for i, E in enumerate(operators)]
return np.sum(operation, axis=0)
So then I was hoping that instead of using loops, this direct multiplication of tensor method might be quicker as I scale up my simulation, say having to do this 1 million times 这里的问题是 K 应该是任何 (1xn) 维度的列表,即 [I] 或 [I, X] 或 [I, X, Y] 或 [I, X, Y, Z]。我知道这里 X = X^{\dagger} 和 Y 和 Z 也是如此,但我的模拟中会出现这种情况。
我希望我现在已经解释清楚了。
【问题讨论】:
-
你希望 A 和 B 是 4x4 矩阵,还是 2x2x2x2 张量?
-
我希望我的 B(with (2, 2, 2, 2)) 具有与 A(with (2, 2)) 相同的暗度。还是它们基本上具有相同的尺寸?
-
但是“将矩阵作为另一个矩阵的条目”是什么意思?你想创建一个块矩阵,还是真正的矩阵矩阵(不管是什么)?在 NumPy 中,
(2, 2)对象矩阵并不是很有用,因为大多数数学运算将停止工作......也许您可以提供一些示例输入数据、您想要执行的一些操作以及所需的输出数据?跨度> -
请看我上面的编辑。谢谢:)
-
我已经为你的函数修改了一个加速解决方案
标签: python python-3.x numpy numpy-ndarray quantum-computing