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

More than 5 years have passed since last update.

Qiskit 任意個のqubitがある回路をappendしたいとき

Last updated at Posted at 2020-02-20

結論

Qiskitで作成した回路を別の回路に組み込みたいとき, qc.append( sub_qc, [q[m], q[m+1], ..., q[n]] )と書くことで追加できる.
[q[m], ... ,q[n]]q[m:n+1]と書いても実行される.
sliceなのでn+1になる.

IBM Q Epxrerience上で実行した.

まずimport

%matplotlib inline
# Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
# Loading your IBM Q account(s)
provider = IBMQ.load_account()

from qiskit import *

sub_qcを定義, あとでappendされる.


q = QuantumRegister(3)
c = ClassicalRegister(3)
qc = QuantumCircuit(q, c)
qc.draw()
ScreenShot 2020-02-20 13.40.32.png `sub_qc`が完成

parent_qcを定義

q = QuantumRegister(4)
c = ClassicalRegister(1)
parent_qc = QuantumCircuit(q, c)
parent_qc.append( sub_qc, [q[1], q[2], q[3]] )
parent_qc.draw()

ScreenShot 2020-02-20 13.44.25.png

sliceの書き方version

q = QuantumRegister(4)
c = ClassicalRegister(1)
parent_qc = QuantumCircuit(q, c)
parent_qc.append( sub_qc, q[1:4] )
parent_qc.draw()

同じ結果が得られる.
ScreenShot 2020-02-20 13.44.25.png

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