らんだむな記憶

blogというものを体験してみようか!的なー

Blueqat (2)

Introduction の回路をまず Qiskit で書いてみる。

from qiskit import QuantumCircuit, execute, Aer

qc = QuantumCircuit(4)

qc.x(0)
qc.x(1)
qc.barrier()
qc.cx(1, 2)
qc.cx(0, 2)
qc.ccx(0, 1, 3)

qc.measure_all()

backend = Aer.get_backend('aer_simulator')
results = execute(qc, backend=backend, shots=1024).result()
answer = results.get_counts()

print(answer)

{'1011': 1024}

となる。イントロダクションだと qc.measure_all() でなくても良いのだが、blueqat 0.6 がシミュレータでの部分的な測定がうまくできない?ようだったのでそれに合わせた。

次に blueqat で書いてみよう:

from blueqat import Circuit

c = Circuit()
c = c.x[0].x[1].cx[1,2].cx[0,2].ccx[0,1,3]

results = c.m[:].run(shots=1024)
print(results)

Counter({'1101': 1024})

ということで、本質的には同じ結果が得られた。注意すべきこととしては、Qiskit では q_0 の観測結果が右に出てくるが、blueqat では左に出てくることである。

The Atoms of Computation にも

Qiskit numbers the bits in a string from right to left.

とある。