Path: blob/main/dynamics101/Solutions/Lab 1 - Solutions.ipynb
1139 views
Lab 1 - Solutions
Why dynamics simulations vs. circuit simulations?
CUDA-Q Dynamics is a powerful library enabling GPU-accelerated simulations of the time evolution of open and closed quantum systems. In contrast to quantum circuit simulation, which simulates the algorithmic output of the application of discrete logical quantum gates (eg X, Y, Z, CNOT, H, etc), dynamics simulations represent how quantum systems evolve in time, revealing important insights about the non-idealities of a quantum system, including how they interact with the environment and other quantum systems.
To make a classical analogy, the logic of a classical computer can be modeled using binary logic gates applied to transistor states, analogous to simulating the application of quantum logic gates to qubits. Dynamics simulations are an abstraction layer below this. Classically, to design better and higher-performing transistors, it's useful to fully model the device physics of the transistor itself, including fluctuations in voltage, capacitance, and current. Analogously, quantum dyanmics simulations can fully capture the physics of components beyond just the qubits, including drive pulses, resonators, couplers, and noise.

Figure 1. Classical computing can be a helpful analogy for understanding the difference between algorithm and dynamics simulations. Image credits: Fredrik Brange (top right) and qutip-qip (bottom right)
Functionality
CUDA-Q dynamics provides an easy API, evolve, to solve the Schrodinger and Lindblad Master equation, as well as number of commonly used operators to construct Hamiltonians. The basic order of operations is similar to other quantum dynamics frameworks.
Define:
The dimensions of the system
The Hamiltonian
The initial state of the system
Any dissipation terms
The timesteps desired
Evolve!
Conveniently, this is the same programming model and API used to submit CUDA-Q jobs to analog quantum computers like QuEra and Pasqal. For simulation workloads, we also provide several commonly used numerical integrators.
In addition to this higher level functionality, we also provide a lower level library called cuDensityMat which provide the building blocks for accelerating custom solvers and other dynamics frameworks.
Performance
CUDA-Q Dynamics shines for large system sizes, as is the case for most GPU workloads. We will see maximal speed-ups over CPU implementations with Hilbert spaces larger than levels. For systems of this size and larger, it is common to see speed-ups of >1000x. A benchmark modeling 100 timesteps of a system consisting of a 32-level transmon, 256-level resonator, and 4-level Purcell filter yielded a 1,140x speed-up in execution from single CPU (dual-socket Intel Xeon 8480CL) to single GPU (H100), or 1.5 days to 2 minutes.
CUDA-Q Dynamics also provides multi-GPU and multi-node capabilities to both increase the performance and scale of simulations. Additional GPUs can be pooled for additional memory to simulate larger systems (weak-scaling). Alternatively, with a fixed system size, additional GPUs can be pooled for increase performance (strong-scaling).
Full details of the benchmarks can be found in the blog here.
Section 1 - Simulating the Jaynes-Cummings Hamiltonian
The Jaynes-Cummings (JC) Hamiltonian is a important theoretical model describing a two-level system interacting with a resonator. It describes how an atom or qubit fundamentally interacts with light. It is a powerful building block for modeling and designing many superconducting qubit systems and can be extended to describe many of the interactions in a superconducting qubit system. In practice, it describes the physics by which qubits can be controlled by external control pulses and the readout process used to determine their state.

Figure 2. A two-level quantum system such as a qubit or an atom interacting with a light field confined by a resonator. The JC model describes this interaction. Image credit: Wikipedia.
The Hamiltonian can be simplified into the following three principal terms, by taking the rotating wave approximation, and dropping constant terms.
with
In this section, we will simulate JC Hamiltonian. You will learn to:
Define the dimensions of the system
Construct the Hamiltonian with CUDA-Q
operatorsDefine the initial state of the system
Execute the simulation with
cudaq.evolve()
We start by setting the backend target to dynamics. Then, we define the degrees of freedom, specifying the number of levels associated with each one. We can then construct the Hamiltonian by applying the correct operators to the relevant degrees of freedom.
Initialize the states of the system in cupy arrays and define the time chedule
Evolve! Various observables can be collected at each time step. For this, we will track the population of both the qubit and the cavity in the absence of noise.
We see the qubit and cavity coherently exchanging population with a Rabi period of 2. Intuitively, a photon is being absorbed by the qubit and then re-emitted to the cavity.
Recall that we set the coupling rate in the interation Hamiltonian to . From performing some analysis on the JC Hamiltonian, one can derive that this oscillation rate is , where the effective subspace is spanned by . Is this consistent with what we observe?
Exercise 1 - Simulating a many-photon Jaynes-Cummings Hamiltonian:
Adjust the code below to now simulate 20 photons in the cavity, a much larger system. Answer the questions below to analyze the results.
What do you observe about the new Rabi frequency? Is this consistent with what you expect?
The Rabi frequency is proportional to , so times faster than the 1 photon case
Section 2 - Simulating open quantum systems with the collapse_operators
In the previous section we simulated an idealized quantum system, isolated from the environment, with no noise. This is equivalent to solving the Schrodinger equation. Let us now add the effects of the environment, by adding noise to the system via the collapse_operators. We will now solve the Lindbladian:
where we can assign the dissipation terms and rates .
In this section we will learn to use the collapse_operators to model noise in the system.
We can add a list of dissipation terms to the collapse_operators argument in cudaq.evolve. Let's add a photon loss mechanism with rate 0.1 with the a annihilation operator and observe what happens.
Exercise 2a - Adding additional jump operators :
Now instead of considering a photon loss mechanism, consider a photon excitation mechanism with rate 0.1. Initialize the cavity with one photon.
Exercise 2b - Adding additional jump operators :
2b. Now add a dephasing term to qubit with rate `dephasing=0.4`.
Section 3 - Many qubits coupled to the resonator
Let us now construct a model of several qubits coupled to a resonator. This is known as the Tavis-Cummings model. We define the dimensions of the system, construct the Hamiltonian assuming a distribution of qubit-resonator couplings near , qubit energies near , and photon energies of . Initialize all qubits in the ground state and with the resonator with 10 photons.
We now see the effect of multiple qubits exchanging excitations at different rates with the photons in the resonator