Help us understand the problem. What is going on with this article?

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

結論

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした