首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从量子位运算到轴角Bloch球面旋转

从量子位运算到轴角Bloch球面旋转
EN

Stack Overflow用户
提问于 2016-10-02 21:29:25
回答 1查看 662关注 0票数 1

给定应用于单个量子位的运算的2x2酉矩阵表示,如何计算它对应于布洛赫球上的旋转。

例如,Hadamard矩阵是围绕X+Z轴的180度旋转。从[[1,1],[1,-1]]*sqrt(0.5)(X+Z, 180 deg)怎么走

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-02 21:29:25

单量子位运算基本上只是单位四元数,但是有一个额外的相位因子.相似性是因为Pauli矩阵,乘以sqrt(-1),满足定义四元数的i^2=j^2=k^2=ijk=-1关系。

因此,转换方法的硬部分已经被任何“四元数到轴角”代码处理了。只需提取相位角四元数分量,计算相位因子,然后应用四元数对角轴法。

代码语言:javascript
复制
import math
import cmath

def toBlochAngleAxis(matrix):
    """
    Breaksdown a matrix U into axis, angle, and phase_angle components satisfying
    U = exp(i phase_angle) (I cos(angle/2) - axis sigma i sin(angle/2))

    :param matrix: The 2x2 unitary matrix U
    :return: The breakdown (axis(x, y, z), angle, phase_angle)
    """
    [[a, b], [c, d]] = matrix

    # --- Part 1: convert to a quaternion ---

    # Phased components of quaternion.
    wp = (a + d) / 2.0
    xp = (b + c) / 2.0j
    yp = (b - c) / 2.0
    zp = (a - d) / 2.0j

    # Arbitrarily use largest value to determine the global phase factor.
    phase = max([wp, xp, yp, zp], key=abs)
    phase /= abs(phase)

    # Cancel global phase factor, recovering quaternion components.
    w = complex(wp / phase).real
    x = complex(xp / phase).real
    y = complex(yp / phase).real
    z = complex(zp / phase).real

    # --- Part 2: convert from quaternion to angle-axis ---

    # Floating point error may have pushed w outside of [-1, +1]. Fix that.
    w = min(max(w, -1), +1)

    # Recover angle.
    angle = -2*math.acos(w)

    # Normalize axis.
    n = math.sqrt(x*x + y*y + z*z);
    if n < 0.000001:
        # There's an axis singularity near angle=0.
        # Just default to no rotation around the Z axis in this case.
        angle = 0
        x = 0
        y = 0
        z = 1
        n = 1
    x /= n
    y /= n
    z /= n

    # --- Part 3: (optional) canonicalize ---

    # Prefer angle in [-pi, pi]
    if angle <= -math.pi:
        angle += 2*math.pi
        phase *= -1

    # Prefer axes that point positive-ward.
    if x + y + z < 0:
        x *= -1
        y *= -1
        z *= -1
        angle *= -1

    phase_angle = cmath.polar(phase)[1]

    return (x, y, z), angle, phase_angle

测试一下:

代码语言:javascript
复制
print(toBlochAngleAxis([[1, 0], [0, 1]])) # Identity
# ([0, 0, 1], 0, 0.0)

print(toBlochAngleAxis([[0, 1], [1, 0]])) # Pauli X, 180 deg around X
# ([1.0, -0.0, -0.0], 3.141592653589793, 1.5707963267948966)

print(toBlochAngleAxis([[0, -1j], [1j, 0]])) # Pauli Y, 180 deg around Y
# ([-0.0, 1.0, -0.0], 3.141592653589793, 1.5707963267948966)

print(toBlochAngleAxis([[1, 0], [0, -1]])) # Pauli Z, 180 deg around Z
# ([-0.0, -0.0, 1.0], 3.141592653589793, 1.5707963267948966)

s = math.sqrt(0.5)
print(toBlochAngleAxis([[s, s], [s, -s]])) # Hadamard, 180 deg around X+Z
# ([0.7071067811865476, -0.0, 0.7071067811865476], 3.141592653589793, 1.5707963267948966)

print(toBlochAngleAxis([[s, s*1j], [s*1j, s]])) # -90 deg X axis, no phase
# ((1.0, 0.0, 0.0), -1.5707963267948966, 0.0)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39821888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档