English
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

Note

# Pulse gates¶

Most quantum algorithms can be described with circuit operations alone. When we need more control over the low-level implementation of our program, we can use pulse gates. Pulse gates remove the constraint of executing circuits with basis gates only, and also allow you to override the default implementation of any basis gate.

Pulse gates allow you to map a logical circuit gate (e.g., X) to a Qiskit Pulse program, called a Schedule. This mapping is referred to as a calibration. A high fidelity calibration is one which faithfully implements the logical operation it is mapped from (e.g., whether the X gate calibration drives $$|0\rangle$$ to $$|1\rangle$$, etc.).

A schedule specifies the exact time dynamics of the input signals across all input channels to the device. There are usually multiple channels per qubit, such as drive and measure. This interface is more powerful, and requires a deeper understanding of the underlying device physics.

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: To execute a program with pulse gates, the backend has to be enabled with OpenPulse. You can check via backend.configuration().open_pulse, which is True when OpenPulse is enabled. If it is enabled and the pulse gates feature is not enabled, you can schedule your input 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.

In practice, the pulse shape and its parameters would be optimized through a series of Rabi experiments (see the Qiskit Textbook for a walk through). For this demonstration, our Hadamard will be a Gaussian pulse. We will play our pulse on the drive channel of qubit 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()

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]:


## Custom gates¶

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))



If we use the Gate instance variable custom_gate to add the calibration, the parameters are derived from that instance. Remember that the order of parameters is meaningful.

[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


### Version Information

Qiskit SoftwareVersion
qiskit-terra0.23.0
qiskit-aer0.11.2
qiskit-ibmq-provider0.19.2
qiskit0.40.0
qiskit-nature0.5.2
qiskit-finance0.3.4
qiskit-optimization0.4.0
qiskit-machine-learning0.5.0
System information
Python version3.8.16
Python compilerGCC 11.3.0
Python builddefault, Jan 11 2023 00:28:51
OSLinux
CPUs2
Memory (Gb)6.781219482421875
Thu Jan 26 23:20:43 2023 UTC