【问题标题】:Returning chance of qubit state as a decimal以小数形式返回量子位状态的机会
【发布时间】:2020-05-04 23:03:37
【问题描述】:

我正在尝试在 2 个量子位上运行 X 门,然后将任一状态下的量子位的机会返回为小数。我一直在寻找答案,但我没有得到任何答案。

##THE CODE##
import math
import numpy as np
from qiskit import *
from qiskit.providers.aer.extensions.snapshot_probabilities import *


#call for qubits
q = QuantumRegister(2)
c = ClassicalRegister(2)

#creates qubits and classical bits
qc = QuantumCircuit(q, c)

#applys a half not ad 
for i in range(2):
    qc.u3(0.5 * math.pi,0,0, q[i])

# Map the quantum measurement to the classical bits
for i in range(2):
    qc.measure(q[i], c[i])

# Execute the circuit on the qasm simulator
simulator = Aer.get_backend('qasm_simulator')
job = execute(qc, simulator, shots=1000)

result = job.result()
counts = result.get_counts(qc)
## END OF CODE##

【问题讨论】:

  • 程序现在的输出是什么?你还期待什么?

标签: python qiskit


【解决方案1】:

好的,所以result.get_counts() 返回以可能答案命名的可能字典列表。所以遍历可能的答案

##THE CODE##
counts = result.get_counts(qc)
ls = []
for i, key in enumerate(counts.keys()):
    v = counts.get(key)
    ls.append(v)
    
print(ls) 
##END OF CODE##

例子

如果我在将半个 x 门应用到两个量子位之前运行代码

for i in range(2):
    qc.u3(0.5 * math.pi,0,0, q[i]) 

我的输出将是 1000 个量子比特处于状态 1 的机会。

输出

[241, 238, 262, 259]

【讨论】:

    猜你喜欢
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多