概要
量子もつれが、分からないので、copilotに聞いてみた。
chshの不等式の破れを実験したい。
参考にしたページ
サンプルコード
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
import numpy as np
def make_bell_state(qubits, n = 16):
qc = QuantumCircuit(n, 2)
qc.x(qubits[0])
qc.h(qubits[0])
qc.x(qubits[1])
qc.cx(qubits[0], qubits[1])
qc.z(qubits[1])
return qc
def E(shots, count):
cs = [count[i + j] if i + j in count else 0 for i in ["0", "1"] for j in ["0", "1"]]
return (cs[0] + cs[3] - cs[1] - cs[2]) / shots
def real_chsh(theta, qubits, shots = 1024, n = 20):
qcs = [make_bell_state(qubits, n) for _ in range(4)]
counts = []
for i in range(4):
if i >= 2:
qcs[i].h(qubits[0])
qcs[i].ry(-theta, qubits[1]) if i % 2 else qcs[i].ry(-theta - np.pi / 2, qubits[1])
qcs[i].measure(qubits, [0, 1])
backend = AerSimulator()
job = backend.run([qcs[i]], shots = shots)
counts.append(job.result().get_counts())
return E(shots, counts[2]) + E(shots, counts[3]) + E(shots, counts[0]) - E(shots, counts[1])
theta = np.pi / 4
shots = 1024
n = 20
print("correlation of [0, 1] by simulation:", real_chsh(theta, [0, 1], shots, n))
print("correlation of [0,12] by simulation:", real_chsh(theta, [0, 12], shots, n))
print("correlation of [0,19] by simulation:", real_chsh(theta, [0, 19], shots, n))
実行結果
$ python3 test8.py
correlation of [0, 1] by simulation: 2.865234375
correlation of [0,12] by simulation: 2.841796875
correlation of [0,19] by simulation: 2.76953125
$ python3 test8.py
correlation of [0, 1] by simulation: 2.857421875
correlation of [0,12] by simulation: 2.833984375
correlation of [0,19] by simulation: 2.82421875
以上。