Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@skiing_LAL10

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

More than 1 year has passed since last update.

結論

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
Help us understand the problem. What is going on with this article?
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
skiing_LAL10
初心者です.

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?