Path: blob/main/dynamics101/02_Time_Dependent.ipynb
1127 views
Introduction to CUDA-Q Dynamics (Time Dependent Hamiltonians)
In this lab we will learn how to implement time dependent Hamiltonian terms and custom operators. This is important functionality for modeling the application of control pulses to qubits or other interactions that maybe changing in time.
In the first section we will use the example of a Landau-Zener transition to demonstrate two ways of implementing time dependent terms, and in the second section we will demonstrate how to create custom oeprators.
Prerequisites: This notebook assumes familiarity with quantum states, wavefunctions, and operators, including the concept of a Hamiltonian. Additional prerequisisite knowledge includes understanding the fundamental equations governing the evolution of closed (Schrödinger) and open (Lindblad) quantum systems and the basics of the Landau-Zener model.
Before we dive into the details, let's start by setting up the necessary packages and libraries, and ensure our environment is ready for GPU-based simulations.
💻 Just a heads-up: This notebook is designed to be run on an environment with a GPU. If you don't have access to a GPU, feel free to read through the cells and explore the content without executing them. Enjoy learning! ⭐
🎥 Prefer a guided walkthrough? You can watch a video presentation from the Quantum Device Workshop at UCLA in May 2025.
The Landau-Zener model
The Landau-Zener model describes the transition probability of a quantum system with two energy levels that cross each other as a function of an external parameter. For example, one can consider two spins weakly coupled to each other () while an external magnetic field is swept. If the two spins have an energy spectrum that cross each other as a function of the magnetic field, an avoided crossing is created due to the interaction of the spins with each other.
If the magnetic field is swept slowly (adiabatically), no transitions across the splitting occurs. However, if it is swept quickly (diabatically), the transition hops over the splitting, effectively ignoring the splitting. If swept at an intermediate rate, the transition probability is given by a well defined probability.

Figure 1. Sketch of two crossing energy levels with an avoided crossing along a parameter z. Image credit: Wikipedia
Section 1 - Implementing time dependent terms
In this lab we will learn to implement time dependent Hamiltonian terms with:
a time dependent scalar coefficient via
ScalarOperatora
tensor callbackfunction for custom operators
We consider the following simple Hamiltonian representing the lowest two levels of the system. Note we consider first a small system as an instructional example to demonstrate the above features. A system this small won't experience a good acceleration run on GPU, but the features here can easily be scaled towards much larger systems which will experience a significant GPU speed-up.
Here the coupling between levels is denoted by and the time dependent parameter is denoted by . The above Hamiltonian can be of course decomposed into the following Pauli operators:
We can implement the Pauli decomposition easily by constructing our Hamiltonian in CUDA-Q Dynamics with our typical spin operators and by leveraging a ScalarOperator with a time dependence and multiplying that by the term. The transition probability is known to be but we will observe this by performing the following simulation.
Let's set a target transition probability of 0.75 to inform our value of . We will see that computing the simulation will yield a transition result predicted by the theory.
We define our Hamiltonian below and use the ScalarOperator to multiply the term by in a lambda function. This functionality also enables the easy implementation of time dependent drive terms and envelop functions by simply replacing the function in the ScalarOperator argument.
We see the transition probability of the ground state converges to the predicted probability of 0.75.
Section 2 - Implementing custom operators
In the previous section we decomposed the Hamiltonian into spin operators to apply the time dependence to the terms. Alternatively, we can directly represent the Hamiltonian with a tensor callback and by defining an ElementaryOperator.
Let's define the above Hamiltonian in a matrix in the function callback_tensor(t) which accepts time as an argument.
We can now define an operator with this callback tensor, labeled lz_op.
We can define our hamiltonian now with this single lz_op ElementaryOperator, applied to the 0th degree of freedom.
We can run the rest of the simulation as before.
Section 3 - Heisenberg Model with a time-varying magnetic field
In this section we will now look at a much larger quantum system, considering a 1-D chain of 10 spins according to the Heisenberg Hamiltonian, adding a time-dependent transverse magnetic field after a delay. We can use this system to model quantum quench dynamics.
For this example, we consider the case where the coupling is dominant, and prepare the system in an alternating spin up and down state, the approximate ground state.

image credit: Wikipedia
Exercise 1 - Define a time-varying magnetic field:
Now, construct the Hamiltonian with a step function B-field that turns on with magnitude 2.0 after a time delay=2.5. Modify the `B_field` function below to reflect this.
Now add the magnetic field term to the Hamiltonian. Assume the B-field lies in the x direction. The spin-spin Hamiltonian terms are given already.
We can now execute the simulation, measuring the expectation. Other common observables for this system are spin correlators and the magnetization
We can see that the prior to the addition of the magnetic field, the system stays relatively stationary. With the transverse field, the system quickly mixes.
Exercise 2:
a. Adjust the time dependent magnetic field to now be a sine function with amplitude 2.0, and frequency .
b. Consider now a disordered spin chain with varying couplings
c. Observe the behavior of the following observables: spin correlators and the magnetization