참고
이 페이지는 tutorials/circuits_advanced/05_pulse_gates.ipynb 에서 생성되었다.
펄스 게이트들¶
대부분의 양자 알고리즘은 회로 작동만으로 설명할 수 있다. 프로그램의 저수준 구현에 대한 제어가 필요할 때 펄스 게이트 를 사용할 수 있다. 펄스 게이트는 기본 게이트 만을 사용해 회로를 실행하는 제약을 뛰어넘어 어떤 기본 게이트라도 기본 구현된 것을 재정의할 수 있다
펄스 게이트를 사용하면 논리 회로 게이트(예: X
)를 Schedule
이라고 하는 Qiskit 펄스 프로그램에 mapping 할 수 있다. 이 사상 작업을 교정 이라고 한다. 높은 정확도의 교정은 mapping 된 논리 연산(예: X
게이트 교정은 \(|0\rangle\) 을 \(|1\rangle\) 로 바꾼다, 등등)을 충실히 구현하는 교정이다.
스케줄은 장치에 대한 모든 입력 채널들 에 걸쳐 입력 신호의 정확한 시간 역학을 지정한다. 일반적으로 큐비트 마다 구동 및 측정과 같은 여러 채널이 있다. 이 인터페이스는 더 강력하며 기본적인 장치의 물리학적 원리를 더 깊이 이해해야 한다.
It’s important to note that Pulse programs operate on physical qubits. A drive pulse on qubit \(a\) will not enact the same logical operation on the state of qubit \(b\) – in other words, gate calibrations are not interchangeable across qubits. This is in contrast to the circuit level, where an X
gate is defined independent of its qubit operand.
이 페이지는 회로에 교정을 추가하는 법을 보여준다.
Note: Not all providers support pulse gates.
회로 구성하기¶
Let’s start with a very simple example, a Bell state circuit.
[1]:
from qiskit import QuantumCircuit
circ = QuantumCircuit(2, 2)
circ.h(0)
circ.cx(0, 1)
circ.measure(0, 0)
circ.measure(1, 1)
circ.draw('mpl')
[1]:

교정 구성하기¶
Now that we have our circuit, let’s define a calibration for the Hadamard gate on qubit 0.
실제로, 펄스의 모양과 매개변수들은 Rabi 실험(Rabi experiments)의 반복을 통해 최적화된다 (Qiskit 교과서 를 따라가라). 이를 시연하고자 Hadamard는 가우시안(Gaussian)펄스가 될 것이다. 큐비트 0의 구동 채널에 펄스를 발생 시킬 것이다.
Don’t worry too much about the details of building the calibration itself; you can learn all about this on the following page: building pulse schedules.
[2]:
from qiskit import pulse
from qiskit.pulse.library import Gaussian
from qiskit.providers.fake_provider import FakeValencia
backend = FakeValencia()
with pulse.build(backend, name='hadamard') as h_q0:
pulse.play(Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0))
Let’s draw the new schedule to see what we’ve built.
[3]:
h_q0.draw()
[3]:

회로에 교정을 링크하기¶
등록을 마무리하는 것만이 남았다. 회로 메서드 add_calibration
은 사상을 완료하고자 게이트 정보와 스케줄에 대한 참조를 필요로 한다:
QuantumCircuit.add_calibration(gate, qubits, schedule, parameters)
The gate
can either be a circuit.Gate
object or the name of the gate. Usually, you’ll need a different schedule for each unique set of qubits
and parameters
. Since the Hadamard gate doesn’t have any parameters, we don’t have to supply any.
[4]:
circ.add_calibration('h', [0], h_q0)
마지막으로 트랜스파일러는 당신의 교정을 준수하다는 걸 주의하자. 그럴 거라고 생각하고 사용하자 (우리의 예는 트랜스파일러가 최적화하기에는 너무 간단하므로 출력이 같다).
[5]:
from qiskit import transpile
from qiskit.providers.fake_provider import FakeHanoi
backend = FakeHanoi()
circ = transpile(circ, backend)
print(backend.configuration().basis_gates)
circ.draw('mpl', idle_wires=False)
['id', 'rz', 'sx', 'x', 'cx', 'reset']
[5]:

h
가 모조 백엔드 FakeHanoi
의 기저 게이트가 아닌 것에 주목하자. 보정이 추가되었기 때문에 트랜스파일러는 해당 게이트를 기저 게이트로 취급할 것이다; 하지만 오직 정의되었던 큐비트들에 대해서만 취급할 것이다. 다른 큐비트에 적용된 Hadamard는 기저 게이트들로 전개될 것이다.
That’s it!
사용자 설정 게이트¶
We’ll briefly show the same process for nonstandard, completely custom gates. This demonstration includes a gate with parameters.
[6]:
from qiskit import QuantumCircuit
from qiskit.circuit import Gate
circ = QuantumCircuit(1, 1)
custom_gate = Gate('my_custom_gate', 1, [3.14, 1])
# 3.14 is an arbitrary parameter for demonstration
circ.append(custom_gate, [0])
circ.measure(0, 0)
circ.draw('mpl')
[6]:

[7]:
with pulse.build(backend, name='custom') as my_schedule:
pulse.play(Gaussian(duration=64, amp=0.2, sigma=8), pulse.drive_channel(0))
circ.add_calibration('my_custom_gate', [0], my_schedule, [3.14, 1])
# Alternatively: circ.add_calibration(custom_gate, [0], my_schedule)
만약 교정을 추가하고자 Gate
인스턴스 변수 custom_gate
를 사용한다면, 그 매개변수들은 인스턴스로부터 도출된다. 매개변수 순서가 의미가 있음을 유념하라.
[8]:
circ = transpile(circ, backend)
circ.draw('mpl', idle_wires=False)
[8]:

Normally, if we tried to transpile our circ
, we would get an error. There was no functional definition provided for "my_custom_gate"
, so the transpiler can’t unroll it to the basis gate set of the target device. We can show this by trying to add "my_custom_gate"
to another qubit which hasn’t been calibrated.
[9]:
circ = QuantumCircuit(2, 2)
circ.append(custom_gate, [1])
from qiskit import QiskitError
try:
circ = transpile(circ, backend)
except QiskitError as e:
print(e)
"Cannot unroll the circuit to the given basis, ['id', 'rz', 'sx', 'x', 'cx', 'reset']. Instruction my_custom_gate not found in equivalence library and no rule found to expand."
[10]:
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright
Version Information
Qiskit Software | Version |
---|---|
qiskit-terra | 0.21.2 |
qiskit-aer | 0.10.4 |
qiskit-ibmq-provider | 0.19.2 |
qiskit | 0.37.2 |
System information | |
Python version | 3.10.7 |
Python compiler | GCC 12.2.0 |
Python build | main, Sep 6 2022 21:22:27 |
OS | Linux |
CPUs | 32 |
Memory (Gb) | 125.64828109741211 |
Mon Sep 12 15:28:25 2022 EDT |
This code is a part of Qiskit
© Copyright IBM 2017, 2022.
This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.