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: Not all providers support pulse gates.

## Build your circuit#

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


## Build your calibrations#

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

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


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

circ.add_calibration('my_custom_gate', [0], my_schedule, [3.14, 1])
# Alternatively: circ.add_calibration(custom_gate, [0], my_schedule)


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

SoftwareVersion
qiskitNone
qiskit-terra0.25.2
qiskit_aer0.12.2
System information
Python version3.9.18
Python compilerGCC 11.4.0
Python buildmain, Aug 28 2023 08:38:32
OSLinux
CPUs2
Memory (Gb)6.759754180908203
Mon Oct 02 19:18:51 2023 UTC