1# This file is part of QuTiP: Quantum Toolbox in Python. 2# 3# Copyright (c) 2011 and later, Paul D. Nation and Robert J. Johansson. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: 9# 10# 1. Redistributions of source code must retain the above copyright notice, 11# this list of conditions and the following disclaimer. 12# 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# 3. Neither the name of the QuTiP: Quantum Toolbox in Python nor the names 18# of its contributors may be used to endorse or promote products derived 19# from this software without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 24# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32############################################################################### 33 34import numpy as np 35import qutip 36 37 38def test_unitary_evolution_two_level_system(): 39 delta = 1.0 * 2 * np.pi 40 eps0 = 1.0 * 2 * np.pi 41 A = 0.5 * 2 * np.pi 42 omega = np.sqrt(delta**2 + eps0**2) 43 T = 2*np.pi / omega 44 tlist = np.linspace(0, 2*T, 101) 45 psi0 = qutip.rand_ket(2) 46 H0 = -0.5*eps0*qutip.sigmaz() - 0.5*delta*qutip.sigmax() 47 H1 = 0.5 * A * qutip.sigmax() 48 args = {'w': omega} 49 H = [H0, [H1, lambda t, args: np.sin(args['w'] * t)]] 50 e_ops = [qutip.num(2)] 51 52 trial = qutip.fsesolve(H, psi0, tlist, e_ops, T, args).expect[0] 53 expected = qutip.mesolve(H, psi0, tlist, [], e_ops, args).expect[0] 54 55 np.testing.assert_allclose(trial, expected, atol=1e-4) 56