Qutip Functions for Quantum Dynamics

Mihirsinh Chauhan
5 min readSep 9, 2023

--

Welcome to Day 9 of our quantum computing journey. Today, we’re going to dive deeper into simulating quantum dynamics using Qutip. We’ll explore essential Qutip functions that enable us to simulate the time evolution of quantum systems, a fundamental concept in quantum computing and quantum physics.

Key Qutip Functions for Quantum Dynamics:

Qutip provides a range of powerful functions to simulate quantum dynamics. Here are some of the key functions and concepts you’ll need to understand:

Hamiltonians:

The Hamiltonian operator (H) describes the total energy of a quantum system. It plays a central role in quantum dynamics simulations. You can define custom Hamiltonians based on your system’s properties.
Example:
In this example, we’ll define a custom Hamiltonian and visualize its effect on a quantum state’s evolution.

import qutip as qt
import numpy as np
import matplotlib.pyplot as plt

# Define parameters
omega = 1.0 # Angular frequency

# Create the Hamiltonian
H = 0.5*np.pi * omega * qt.sigmax()

# Initial state |0⟩
psi_0 = qt.basis(2, 0)

# Time points for simulation
times = np.linspace(0, 10, 100)

# Perform unitary evolution
result = qt.mesolve(H, psi_0, times, [], [])

# Access the results
states = result.states

# Visualize the results
expect_z = qt.expect(qt.sigmaz(), states)
plt.plot(times, expect_x)
plt.xlabel('Time')
plt.ylabel('<σx>')
plt.title('Quantum State Evolution')
plt.show()

you will get this output

In this example, we create a Hamiltonian for a qubit, simulate its time evolution, and visualize the expectation value of the Pauli-X operator (<σx>) over time, i.e oscillate between -1 and 1.

Time Evolution Operator:

The time evolution operator (U) describes how a quantum state changes over time under the influence of a Hamiltonian. Qutip provides functions to compute U for different types of Hamiltonians.

import qutip as qt
import numpy as np
import matplotlib.pyplot as plt

# Define parameters
omega = 1.0 # Angular frequency

# Create the Hamiltonian
H = 0.5*np.pi * omega * qt.sigmax()

# Initial state |0⟩
psi_0 = qt.basis(2, 0)

# Time points for simulation
times = np.linspace(0, 10, 100)

# Calculate the time evolution operator
U = qt.propagator(H, times, c_ops=[])

# Apply the time evolution operator to the initial state
psi_evolved = U * psi_0

# Visualize the quantum state on the Bloch sphere
b = qt.Bloch()
b.make_sphere()
b.add_states([psi_evolved])

b.render()
b.show()

the output of above code is

In this example, we calculate the time evolution operator (U) and apply it to the initial state (∣0⟩). We then visualize the quantum state on a Bloch sphere.

Unitary Evolution:

The function qt.mesolve() allows you to perform unitary evolution of a quantum state over time. It takes the Hamiltonian and the initial state as input and computes the state at a given time.

Lindblad Master Equation:

For open quantum systems that interact with their environment, you can use the Lindblad master equation to describe the dynamics. Qutip’s qt.mesolve() can also handle Lindblad-type evolution.

import qutip as qt
import numpy as np
import matplotlib.pyplot as plt

# Define parameters
omega = 1.0 # Angular frequency
gamma = 0.1 # Decay rate

# Create the Hamiltonian
H = 0.5 *np.pi* omega * qt.sigmax()

# Initial state |0⟩
psi_0 = qt.basis(2, 0)

# Time points for simulation
times = np.linspace(0, 10, 100)

# Define the Lindblad operators for relaxation
c_ops = [np.sqrt(gamma) * qt.sigmam()]

# Simulate using the Lindblad master equation
result = qt.mesolve(H, psi_0, times, c_ops, [])

# Access the results
states = result.states

# Visualize the results
expect_z = qt.expect(qt.sigmaz(), states)
plt.plot(times, expect_z)
plt.xlabel('Time')
plt.ylabel('<σx>')
plt.title('Quantum State Evolution (Lindblad)')
plt.show()

this code produce

In this example, you should see a plot displaying the quantum state’s evolution over time, considering relaxation due to the Lindblad operators. The expectation value of the Pauli-Z operator (<σz>) will decay over time.

Monte Carlo Wave Function Simulations:

For stochastic quantum dynamics, where you want to simulate the statistical behavior of a quantum system, Qutip offers Monte Carlo wave function simulations using the qt.mcsolve() function.

import qutip as qt
import numpy as np
import matplotlib.pyplot as plt

# Define parameters
omega = 1.0 # Angular frequency

# Create the Hamiltonian
H = 0.5*np.pi * omega * qt.sigmax()

# Initial state |0⟩
psi_0 = qt.basis(2, 0)

# Time points for simulation
times = np.linspace(0, 10, 100)

# Perform Monte Carlo wave function simulation
result = qt.mcsolve(H, psi_0, times, [])

# Access the results
states = result.states

# Visualize the results
expect_z = qt.expect(qt.sigmaz(), states)
plt.plot(times, expect_z)
plt.xlabel('Time')
plt.ylabel('<σx>')
plt.title('Quantum State Evolution (Monte Carlo)')
plt.show()

output:

No c_ops, using sesolve
10.0%. Run time: 0.00s. Est. time left: 00:00:00:00
20.0%. Run time: 0.00s. Est. time left: 00:00:00:00
30.0%. Run time: 0.01s. Est. time left: 00:00:00:00
40.0%. Run time: 0.01s. Est. time left: 00:00:00:00
50.0%. Run time: 0.01s. Est. time left: 00:00:00:00
60.0%. Run time: 0.01s. Est. time left: 00:00:00:00
70.0%. Run time: 0.01s. Est. time left: 00:00:00:00
80.0%. Run time: 0.02s. Est. time left: 00:00:00:00
90.0%. Run time: 0.02s. Est. time left: 00:00:00:00
Total run time: 0.02s

When you run this code, you should see a plot showing the quantum state’s evolution over time using a Monte Carlo wave function simulation. The expectation value of the Pauli-x operator (<σx>) will exhibit stochastic behavior over time.

Conclusion:

In Day 9, we’ve explored essential Qutip functions for simulating quantum dynamics. Understanding how to define Hamiltonians, compute time evolution operators, and perform quantum simulations is crucial for quantum programming and research. As you continue your quantum journey, you’ll use these tools to tackle more complex quantum systems and explore quantum algorithms and applications. Stay tuned for more quantum adventures!

#Day9 of #Quantum30 day challenge

--

--

Mihirsinh Chauhan

《Quantum computing Enthusiast |Future Innovator》《Under grad at SVNIT | ML| Buisness Amateur》