evolve
API
Quantum Dynamics and Time Evolution Simulation on GPU with NVIDIA CUDA-Q’s In this post, we introduce the time evolution API from CUDA-Q:
In quantum mechanics, the change of a quantum state over time is called time evolution. It’s a fundamental method for understanding the intrinsic behavior of quantum systems.
More specifically, we often want to know how a quantum state
This formula forms the basis for calculating quantum time evolution.
Here, we’ll walk through one of CUDA-Q’s time evolution examples to see how it works in practice.
Example: Modeling a Superconducting Transmon Qubit
A superconducting transmon qubit can be modeled by the following time-dependent Hamiltonian:
Let’s translate this into a form usable with CUDA-Q.
We’ll use ScalarOperator
to handle the time-dependent part. Since parameter values weren’t in the official tutorial, we generated reasonable ones with ChatGPT.
import numpy as np
from cudaq.operator import *
# Define system parameters (units arbitrary, e.g., GHz)
omega_z = 1.0 # Energy scale in Z direction
omega_x = 0.6 # Drive strength
omega_d = 1.0 # Drive frequency
# Define the time-dependent Hamiltonian
hamiltonian = 0.5 * omega_z * spin.z(0)
hamiltonian += omega_x * ScalarOperator(lambda t: np.cos(omega_d * t)) * spin.x(0)
Running the Simulation
There was no predefined schedule, so we created one ourselves:
import cudaq
import cupy as cp
import time
# Define time range and number of steps
t_final = 10.0 # Final simulation time (e.g., 10 seconds)
n_steps = 100 # Number of time steps
# Set backend to dynamics simulator
cudaq.set_target("dynamics")
# Define subsystem dimensions (qubit = 2-level system)
dimensions = {0: 2}
# Initial state (ground state)
rho0 = cudaq.State.from_data(
cp.array([[1.0, 0.0], [0.0, 0.0]], dtype=cp.complex128))
# Time schedule
steps = np.linspace(0, t_final, n_steps)
schedule = Schedule(steps, ["t"])
# Time evolution execution
start_time = time.time()
evolution_result = evolve(
hamiltonian,
dimensions,
schedule,
rho0,
observables=[spin.x(0), spin.y(0), spin.z(0)],
collapse_operators=[],
store_intermediate_results=True
)
end_time = time.time()
print(f"Simulation runtime: {end_time - start_time:.4f} seconds")
Simulation runtime: 2.9713 seconds on NVIDIA H100
Plotting the Results
Now let’s visualize the time evolution of the expectation values:
import matplotlib.pyplot as plt
get_result = lambda idx, res: [
exp_vals[idx].expectation() for exp_vals in res.expectation_values()
]
plt.plot(steps, get_result(0, evolution_result))
plt.plot(steps, get_result(1, evolution_result))
plt.plot(steps, get_result(2, evolution_result))
plt.ylabel("Expectation value")
plt.xlabel("Time")
plt.legend(("Sigma-X", "Sigma-Y", "Sigma-Z"))
As shown above, we were able to analyze the time evolution step-by-step.
This capability could be highly useful in research applications involving quantum dynamics and driven qubit systems.