sign python_Python sympy.sign方法代码示例

# 需要导入模块: import sympy [as 别名]

# 或者: from sympy import sign [as 别名]

def cphase_to_sqrt_iswap(a, b, turns):

"""Implement a C-Phase gate using two sqrt ISWAP gates and single-qubit

operations. The circuit is equivalent to cirq.CZPowGate(exponent=turns).

Output unitary:

[1 0 0 0],

[0 1 0 0],

[0 0 1 0],

[0 0 0 e^{i turns pi}].

Args:

a: the first qubit

b: the second qubit

turns: Exponent specifying the evolution time in number of rotations.

"""

theta = (turns % 2) * np.pi

if 0 <= theta <= np.pi:

sign = 1.

theta_prime = theta

elif np.pi < theta < 2 * np.pi:

sign = -1.

theta_prime = 2 * np.pi - theta

if np.isclose(theta, np.pi):

# If we are close to pi, just set values manually to avoid possible

# numerical errors with arcsin of greater than 1.0 (Ahem, Windows).

phi = np.pi / 2

xi = np.pi / 2

else:

phi = np.arcsin(np.sqrt(2) * np.sin(theta_prime / 4))

xi = np.arctan(np.tan(phi) / np.sqrt(2))

yield ops.rz(sign * 0.5 * theta_prime).on(a)

yield ops.rz(sign * 0.5 * theta_prime).on(b)

yield ops.rx(xi).on(a)

yield ops.X(b)**(-sign * 0.5)

yield SQRT_ISWAP_INV(a, b)

yield ops.rx(-2 * phi).on(a)

yield SQRT_ISWAP(a, b)

yield ops.rx(xi).on(a)

yield ops.X(b)**(sign * 0.5)

# Corrects global phase

yield ops.GlobalPhaseOperation(np.exp(sign * theta_prime * 0.25j))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值