0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

qiskitで量子もつれ その3

Posted at

概要

量子もつれが、分からないので、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

以上。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?