概要
量子もつれが、分からないので、copilotに聞いてみた。
ベルの不等式の破れを実験したい。
サンプルコード
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit.primitives import StatevectorSampler as Sampler
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
sampler = Sampler()
job = sampler.run([qc], shots = 1024)
result = job.result()
counts = result[0].data.c.get_counts()
print(f" > Counts: {counts}")
def get_probabilities(counts):
total_shots = sum(counts.values())
probabilities = {key: value / total_shots for key, value in counts.items()}
return probabilities
probabilities = get_probabilities(dict(counts))
E_A0_B0 = probabilities.get('00', 0) + probabilities.get('11', 0) - probabilities.get('01', 0) - probabilities.get('10', 0)
E_A0_B1 = probabilities.get('00', 0) + probabilities.get('11', 0) - probabilities.get('01', 0) - probabilities.get('10', 0)
E_A1_B0 = probabilities.get('00', 0) + probabilities.get('11', 0) - probabilities.get('01', 0) - probabilities.get('10', 0)
E_A1_B1 = probabilities.get('00', 0) + probabilities.get('11', 0) - probabilities.get('01', 0) - probabilities.get('10', 0)
S = abs(E_A0_B0 - E_A0_B1 + E_A1_B0 + E_A1_B1)
print(f"CHSH Inequality S: {S}")
if S > 2:
print("Bell Inequality is violated!")
else:
print("Bell Inequality is not violated.")
実行結果
破れていない。
$ python3 test5.py
> Counts: {'00': 511, '11': 513}
CHSH Inequality S: 2.0
Bell Inequality is not violated.
$ python3 test5.py
> Counts: {'11': 530, '00': 494}
CHSH Inequality S: 2.0
Bell Inequality is not violated.
以上。