Enhance variational quantum algorithms with Qiskit Pulse and Qiskit Dynamics

Qiskit
Qiskit
Published in
8 min readNov 1, 2023

By Zhiding Liang, Jinglei Cheng, and Hanrui Wang

The world of quantum computing is always evolving. Researchers and scientists are constantly pushing the boundaries, looking for ways to improve the methods they use to harness the power of quantum mechanics. Variational quantum algorithms (VQAs), for example, have gained significant traction in recent years as useful tools for exploring optimization and quantum chemistry problems. But how can we make them even better?

Traditionally, researchers approach VQAs at the gate-level. More specifically, they focus on the design of a type of quantum circuit structure known as the “ansatz,” which serves as a kind of template for the quantum state that we believe is close to the solution of the problem at hand. The challenge with this approach is that gate-level quantum circuits have a lot of redundancies and inefficiencies that limit the execution of intricate quantum algorithms on the noisy quantum computing hardware we have today. Fortunately, there’s a new kid on the block who could very well open up a world of possibilities for running VQA algorithms on near-term quantum hardware. It’s called the Parameterized Quantum Pulse Circuit.

In this blog post, we will showcase how to use a tool from the Qiskit Ecosystem called Qiskit Dynamics to simulate the parameterized quantum pulse circuits, with a focus on the variational quantum eigensolver (VQE) algorithm. More specifically, we will demonstrate the Pulse ansatz on near-term superconducting hardware by using part of the PAN [1] algorithm, implementing a pulse-based ansatz for estimating the H2 molecule’s ground state energy.

Pulse programming in Qiskit

One of the useful features of Qiskit is that it gives us a lot of flexibility. Most Qiskit users focus on gate-level operations. However, when we’re working with transmon qubits in superconducting hardware, we know the quantum system executes qubit operations by firing microwave pulses at the qubits. Qiskit provides both gate-level and pulse-level programming capabilities, allowing us to get much more creative with how we approach algorithms like VQE.

Within Qiskit’s Pulse programming, users can customize pulse shapes for transmon qubits, adjusting parameters like amplitude, phase, shape, and frequency. (Check the Qiskit Pulse module for more details.) Users can also use the Qiskit Ecosystem project Qiskit Dynamics to quickly and efficiently simulate the generated pulse schedules.

Pulse circuits offer much more versatility than gate-level programming, but they come at the cost of precision, leading to potential uncertainties in the resulting unitary matrix. This precision is crucial for non-variational algorithms that demand exact rotations and operations. However, in variational quantum algorithms, the primary goal is to approximate a specific quantum state, not to achieve perfect accuracy. Experiments in previous research — VQP [2] and Pan [1] by Liang, Zhiding, et al., and [3] by Egger, Daniel J, et al. — confirm that shorter circuit latency pulses can effectively achieve these outcomes on IBM hardware via pulse access with both quantum machine learning (QML) and quantum chemistry tasks, such as running the VQE algorithm.

Variational Quantum Eigensolver

The Variational Quantum Eigensolver (VQE) is a prominent example of variational quantum algorithms. A comprehensive review of its methods and best practices can be found in the VQE documentation provided in Qiskit. Distinct from conventional quantum algorithms that require fault-tolerant quantum computers for proper execution, VQE can be tailored for efficient operations on our current generation of noisy quantum devices.

When using the typical gate-level approach, we begin the process of using a VQE algorithm by expressing a system’s Hamiltonian with weighted Pauli matrices, which we can translate into quantum circuits. Next, we deploy an ansatz, essentially a quantum circuit with tunable parameters, to prepare the ground eigenstate of the Hamiltonian. Further measurement of this eigenstate gives us the Hamiltonian’s ground state energy. The power of VQE lies in its iterative nature. It employs classical optimization techniques to adjust the ansatz parameters, minimizing the Hamiltonian’s expectation value and thereby approximating the system’s lowest energy state.

Different ansatz structures have been proposed, from hardware-efficient models to the UCCSD, and each possesses its own advantages and challenges. Some researchers have even proposed a search-based algorithm, the QuantumNAS [4], to simplify the process of finding the best ansatz. As quantum computing continues to advance, VQE remains a popular area of focus, with ongoing studies exploring innovative ansatz structures and optimization strategies to enhance its precision and applicability.

Before diving into pulse-level VQE, let’s quickly recap the traditional gate-level approach:

  • In gate-level VQE, the parameters we deal with are the angles of rotation gates.
  • The ansatz, or the quantum circuit that approximates the desired quantum state, is composed of these parameterized gates (e.g. rotation gates) and fixed gates.
  • The primary objective is to tweak these parameters such that the quantum state closely approximates the lowest energy state.

Now, let’s look at how pulse-level VQE differs from the usual approach:

  • Instead of focusing on gate-level parameters, pulse-level VQE shifts attention to the parameters of quantum pulses.
  • These quantum pulses are essentially microwave pulses that act directly on superconducting quantum qubits.
  • By directly controlling the quantum pulses, we can significantly reduce circuit latency.

Why Pulse-Level VQE?

You might be wondering, “why should I bother with pulse-level VQE when the gate-level approach already exists?” Here are some compelling reasons:

  1. Expands the Design Space. Working with pulses allows us to potentially access areas of the Hilbert space that are inaccessible with a CNOT-based circuit decomposition. For example, leakage outside of the computational sub-space may allow the variational algorithm to take short-cuts.
  2. Lowers calibration cost. One of the challenges with quantum gates is calibration. With pulse-level VQE, the lack of calibration is automatically addressed as the parameters are updated to mitigate these errors. For example, quantum pulses can sometimes suffer from issues like overrotation and underrotation. Pulse-level VQE inherently corrects these errors by adjusting the parameters to find the optimal quantum state.
  3. Reduces Latency. By directly controlling the quantum pulses, the need for intermediate gate operations is reduced, leading to faster quantum computations.

How to build parameterized pulse circuits in Qiskit

To construct a pulse schedule, we can use the built-in functionality offered by Qiskit Pulse. This allows us to exercise control over the parameters in the quantum pulses, and extract the corresponding pulses from gates.

For instance, let’s generate a bell state pulse schedule by directly obtaining the corresponding pulses from the gate-level circuit.

from qiskit import QuantumCircuit, pulse
from qiskit_dynamics.backend import DynamicsBackend

qc_test = QuantumCircuit(2)
qc_test.h(0)
qc_test.cx(0,1)
qc_test.measure_all()
with pulse.build(backend) as pulse_test:
pulse.call(qc_test)

pulse_test.draw()

We can visualize the pulse schedule as follows:

Furthermore, we can build parameterized quantum pulse circuits (see example code below). Here, we use the drag pulse shape from a single qubit gate, since drag pulse is the native pulse in IBM’s superconducting quantum machines. By using drag pulses, we can avoid population leaking outside of the computational subspace. However, we can also build a parameterized pulse from scratch depending on our needs.

from qiskit.pulse import Schedule, GaussianSquare, Drag, Delay, Play, ControlChannel, DriveChannel

def drag_pulse(backend, amp, angle):
backend_defaults = backend.defaults()
inst_sched_map = backend_defaults.instruction_schedule_map
x_pulse = inst_sched_map.get(‘x’, (0)).filter(channels = [DriveChannel(0)], instruction_types=[Play]).instructions[0][1].pulse
duration_parameter = x_pulse.parameters[‘duration’]
sigma_parameter = x_pulse.parameters[‘sigma’]
beta_parameter = x_pulse.parameters[‘beta’]
pulse1 = Drag(duration=duration_parameter, sigma=sigma_parameter, beta=beta_parameter, amp=amp, angle=angle)
return pulse1

How to simulate the pulse circuit with Qiskit Dynamics

To run the pulse circuit using Qiskit Dynamics, first we need to initialize Qiskit Dynamics itself.

from qiskit_dynamics import Solver, DynamicsBackend
from qiskit_dynamics.backend import default_experiment_result_function
from qiskit_dynamics.array import Array
import jax
from qiskit.providers.fake_provider import *

gate_backend = FakeManila()
gate_backend.configuration().hamiltonian[‘qub’] = {‘0’: 2,’1': 2,’2': 2,’3': 2,’4': 2}
jax.config.update(“jax_enable_x64”, True)
jax.config.update(“jax_platform_name”, “cpu”)
Array.set_default_backend(“jax”)
pulse_backend = DynamicsBackend.from_backend(gate_backend, evaluation_mode=”sparse”)
solver_options = {“method”: “jax_odeint”, “atol”: 1e-6, “rtol”: 1e-8}
pulse_backend.set_options(solver_options=solver_options)
pulse_backend.configuration = lambda: gate_backend.configuration()

After the initialization, let’s try to run the pulse_test (the Bell state circuit we showed in the last section) on Qiskit Dynamics.

results = pulse_backend.run(pulse_test).result()
counts = results.get_counts()

Pulse based VQE for Ground State Energy of H2

We will now perform ground state energy estimation for the H2 molecule using our Pulse-based VQE. We’ll need to start with the following preprocessing steps:

  1. Use ‘sto-3g’ Gaussian equations to fit the spin orbital of the H2 molecule with bond length equals 0.735.
  2. Through the Fermionic mapping, we get the Pauli strings and corresponding coefficients that describe the problem. Based on these Pauli strings, we can generate the observable layer for the VQE algorithm.
from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.drivers import PySCFDriver
from qiskit_nature.second_q.mappers import JordanWignerMapper,ParityMapper,QubitConverter
import numpy as np
simplified_h2_molecule = """
H 0.0 0.0 0.0
H 0.0 0.0 0.735
"""

driver = PySCFDriver(
atom=ultra_simplified_ala_string.strip(),basis='sto3g',
charge=0,
spin=0,
unit=DistanceUnit.ANGSTROM
)
qmolecule = driver.run()

We define the VQE and build our own custom pulse ansatz. Then we can use the Qiskit Dynamics module to obtain the results of the estimated energy of H2. (For more details regarding implementation based on the PAN [1] algorithm, please refer to this pulse-level VQE tool based on Qiskit-Pulse and Qiskit-Dynamics.)

def vqe(params,pauli_dict,pulse_backend, backend,n_qubit,n_shot):
print(“params in def chemistry in vqe.py: “, params)
# assert(len(params)%2==0)
width_len = int(len(params)-1*(n_qubit-1))
split_ind = int(width_len/2)
amp = np.array(params[:split_ind])
angle = np.array(params[split_ind:width_len])*np.pi*2
width_1 = (np.array(params[width_len:]))
num_items = (1024–256) // 16 + 1
width_norm = (width_1–256) / (1024–256)
width_norm = np.clip(width_norm, 0, 1)
width = (np.round(width_norm * (num_items — 1)) * 16 + 256).astype(int)
amp = amp.tolist()
angle = angle.tolist()
width = width.tolist()
keys = [key for key in pauli_dict]
values = [pauli_dict[key] for key in pauli_dict]
expect_values = []
for key, value in zip(keys, values):
prepulse = HE_pulse(backend, amp, angle, width)
expect = vqe_one(prepulse, n_qubit, n_shot, pulse_backend, backend, key, value)
expect_values.append(expect)
print(“E for cur_iter: “,sum(expect_values))
return sum(expect_values)

Here is a plot showing the convergence of estimated energy while training pulse-based VQE for the H2 molecule.

Conclusion

Pulse-level VQE offers a promising avenue for quantum optimization. By shifting the focus from gate-level parameters to quantum pulse parameters, we can address several challenges inherent in quantum computing, such as calibration and rotation errors.

We hope this blog post provides you with a deeper understanding of pulse-level VQE and its advantages. Stay tuned for more insights into the fascinating world of quantum computing!

References

[1] Liang, Zhiding, et al. “Pan: Pulse ansatz on nisq machines.” arXiv preprint arXiv:2208.01215 (2022).

[2] Liang, Zhiding, et al. “Variational quantum pulse learning.” 2022 IEEE International Conference on Quantum Computing and Engineering (QCE). IEEE, 2022.

[3] Egger, Daniel J, et al. “Pulse variational quantum eigensolver on cross-resonance-based hardware.” PhysRevResearch.5.033159. American Physical Society (2023).

[4] Wang, Hanrui, et al. “Quantumnas: Noise-adaptive search for robust quantum circuits.” 2022 IEEE International Symposium on High-Performance Computer Architecture (HPCA). IEEE, 2022.

--

--

Qiskit
Qiskit

An open source quantum computing framework for writing quantum experiments and applications