Superposition is defined as 正交基的线性组合.

huangapple go评论53阅读模式
英文:

Quantum: Define superposition as linear combination of orthonormal basis

问题

以下是您要翻译的代码部分:

# Standard basis |0>, |1> (Z axis)
zero_qubit = np.matrix([[1.+0.j], [0.+0.j]])
one_qubit = np.matrix([[0.+0.j], [1.+0.j]])
standard_basis: Tuple[np.matrix] = (zero_qubit, one_qubit)


def superposition(
        percentage: float = 100.0,
        basis: Tuple[np.matrix] = (zero_qubit, one_qubit)):
    
    p=sqrt(percentage/100)
    q=sqrt(1-p*p)

    q1 = p*basis[0]+q*basis[1]
    q2 = p*basis[0]-q*basis[1]
    q3 = -p*basis[0]+q*basis[1]
    q4 = -p*basis[0]-q*basis[1]
    return q1, q2, q3, q4

# This works
q1,q2,q3,q4 = superposition(50,standard_basis)

print(q1)
print(q2)
print(q3)
print(q4)

# This generate weird values
q1,q2,q3,q4 = superposition(50j,standard_basis)

print(q1)
print(q2)
print(q3)
print(q4)

请注意,这是您提供的代码的翻译部分。如果您需要任何其他帮助,请随时告诉我。

英文:

I'm testing a code for define a superposition state using a percentage of both basis.

All seems to run well, when the linear percentage is real. But it fails when the percentage is complex parameter.

from cmath import sqrt
from typing import List, Tuple

# Standard basis |0>, |1> (Z axis)
zero_qubit = np.matrix([[1.+0.j], [0.+0.j]])
one_qubit = np.matrix([[0.+0.j], [1.+0.j]])
standard_basis: Tuple[np.matrix] = (zero_qubit, one_qubit)


def superposition(
        percentage: float = 100.0,
        basis: Tuple[np.matrix] = (zero_qubit, one_qubit)):
    
    p=sqrt(percentage/100)
    q=sqrt(1-p*p)

    q1 = p*basis[0]+q*basis[1]
    q2 = p*basis[0]-q*basis[1]
    q3 = -p*basis[0]+q*basis[1]
    q4 = -p*basis[0]-q*basis[1]
    return q1, q2, q3, q4

# This works
q1,q2,q3,q4 = superposition(50,standard_basis)

print(q1)
print(q2)
print(q3)
print(q4)

# This generate weird values
q1,q2,q3,q4 = superposition(50j,standard_basis)

print(q1)
print(q2)
print(q3)
print(q4)

答案1

得分: 0

回答我的问题。

叠加态必须考虑系数的模(而不是系数本身)。

因此,我的当前代码如下:

from math import sqrt
from typing import List, Tuple

# https://en.wikipedia.org/wiki/Quantum_superposition
def superposition(
        alfa: complex = sqrt(.5)+0.j,
        basis: Tuple[np.matrix] = (zero_qubit, one_qubit)):
    
    assert abs(alfa) <= 1.0, "断言系数的模必须小于或等于1"

    if abs(alfa) >= 0.9999999:
        beta: complex = 0.+0.j
    elif abs(alfa) <= 0.0000001:
        beta: complex = 1.+0.j
    else:
        alfa_module=abs(alfa)
        beta_module=sqrt(1-alfa_module**2)
        beta: complex=(beta_module/alfa_module)*(alfa.conjugate())
        assert abs(abs(beta)-beta_module) < 0.0000001, "计算模块时出现内部错误"

    q1 = alfa*basis[0]+beta*basis[1]
    q2 = alfa*basis[0]+(-beta)*basis[1]
    q3 = (-alfa)*basis[0]+beta*basis[1]
    q4 = (-alfa)*basis[0]+(-beta)*basis[1]
    print(get_bloch_coordinates(q1))
    print(get_bloch_coordinates(q2))
    print(get_bloch_coordinates(q3))
    print(get_bloch_coordinates(q4))
    return q1, q2, q3, q4
英文:

Answering my own question.

The superposition has to consider modules of coeficients (not the coeficient themselves).

So, my current code looks like

from math import sqrt
from typing import List, Tuple

# https://en.wikipedia.org/wiki/Quantum_superposition
def superposition(
        alfa: complex = sqrt(.5)+0.j,
        basis: Tuple[np.matrix] = (zero_qubit, one_qubit)):
    
    assert abs(alfa)&lt;=1.0,&quot;Module of assertion coef has to be lower or equal 1&quot;

    if abs(alfa) &gt;= 0.9999999:
        beta: complex = 0.+0.j
    elif abs(alfa) &lt;=0.0000001:
        beta: complex = 1.+0.j
    else:
        alfa_module=abs(alfa)
        beta_module=sqrt(1-alfa_module**2)
        beta: complex=(beta_module/alfa_module)*(alfa.conjugate())
        assert abs(abs(beta)-beta_module)&lt;0.0000001,&quot;Internal error calculating modules&quot;

    q1 = alfa*basis[0]+beta*basis[1]
    q2 = alfa*basis[0]+(-beta)*basis[1]
    q3 = (-alfa)*basis[0]+beta*basis[1]
    q4 = (-alfa)*basis[0]+(-beta)*basis[1]
    print(get_bloch_coordinates(q1))
    print(get_bloch_coordinates(q2))
    print(get_bloch_coordinates(q3))
    print(get_bloch_coordinates(q4))
    return q1, q2, q3, q4

huangapple
  • 本文由 发表于 2023年6月13日 02:46:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76459472.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定