2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

概要

量子もつれが、分からないので、copilotに聞いてみた。
qiskitで実験してみた。

環境

windows11
wsl1
ubuntu22
qiskit 1.3.1
qiskit-aer 0.15.1
qiskit-ibm-runtime 0.34.0

巷のqiskitコード

シミュレータを準備する際に、シミュレータオブジェクト(Aer)からバックエンドオブジェクトを得る。構築回路の実行時、実行関数(execute)にバックエンドオブジェクトを伝える。

from qiskit import QuantumCircuit, Aer, execute <- これは、動かん。
	backend = Aer.get_backend('qasm_simulator')
	job = execute(qc, backend, shots = 1024)
	result = job.result()

新qiskitでは、こうする。

providerオブジェクトからシミュレータを指定してproviderオブジェクトを得て、このproviderオブジェクトからバックエンド情報を得る。バックエンドオブジェクトを使ってシミュレータを動かす。

from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
	backend = AerSimulator()
	job = backend.run([qc], shots = 1024)
	result = job.result()

サンプルコード

量子もつれ

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit_aer import AerSimulator
from qiskit.circuit.library import UnitaryGate

qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
#qc.draw('mpl')

#simulator = AerSimulator()
#result = execute(qc, simulator, shots=1024).result()
#counts = result.get_counts(qc)
#print(counts)
#plot_histogram(counts)

from qiskit.primitives import StatevectorSampler as Sampler
sampler = Sampler()
job = sampler.run([qc], shots=100)
result = job.result()
#pub_result = result[0]
#print(f" > Counts: {pub_result.data.meas.get_counts()}")

counts = result[0].data.c.get_counts()
print(f" > Counts: {counts}")



実行結果

$ python3 test0.py
 > Counts: {'11': 58, '00': 42}
$ python3 test0.py
 > Counts: {'11': 56, '00': 44}

以上。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?