a = tensor(destroy(N), qeye(2)) sm = tensor(qeye(N), destroy(2)) H = wc * a.dag() * a + wa * sm.dag() * sm + \ g * (a.dag() * sm + a * sm.dag()) c_ops = [np.sqrt(kappa * (1 + n_th)) * a, np.sqrt(kappa * n_th) * a.dag(), np.sqrt(gamma) * sm] wlist = 2 * pi * np.linspace(0.5, 1.5, 100) spec1 = spectrum(H, wlist, c_ops, a.dag(), a, solver='es') spec2 = spectrum(H, wlist, c_ops, a.dag(), a, solver='pi') assert_(max(abs(spec1 - spec2)) < 1e-3) @unittest.skipIf(_version2int(Cython.__version__) < _version2int('0.14') or Cython_found == 0, 'Cython not found or version too low.') def test_str_list_td_corr(): """ correlation: comparing TLS emission correlations (str-list td format) """ # calculate emission zero-delay second order correlation, g2(0), for TLS # with following parameters: # gamma = 1, omega = 2, tp = 0.5 # Then: g2(0)~0.57 sm = destroy(2) args = {"t_off": 1, "tp": 0.5} H = [[2 * (sm+sm.dag()), "exp(-(t-t_off)**2 / (2*tp**2))"]] tlist = np.linspace(0, 5, 50) corr = correlation_3op_2t(H, fock(2, 0), tlist, tlist, [sm],
# # Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson # ########################################################################### from qutip import * from qutip import _version2int from qutip.sparse import * from numpy import allclose, isreal, iscomplex from numpy.testing import assert_equal, run_module_suite import scipy import unittest @unittest.skipIf(_version2int(scipy.__version__) < _version2int('0.10'), 'Known to fail on SciPy ' + scipy.__version__) def test_SparseHermValsVecs(): """ Sparse eigs Hermitian """ # check using number operator N = num(10) spvals, spvecs = N.eigenstates(sparse=True) for k in range(10): # check that eigvals are in proper order assert_equal(abs(spvals[k] - k) <= 1e-13, True) # check that eigenvectors are right and in right order assert_equal(abs(expect(N, spvecs[k]) - spvals[k]) < 5e-14, True)
import unittest import warnings from qutip import (correlation, destroy, coherent_dm, correlation_2op_2t, fock, correlation_2op_1t, tensor, qeye, spectrum_ss, spectrum_pi, correlation_ss, spectrum_correlation_fft, spectrum, correlation_3op_2t, mesolve, Options, Cubic_Spline) # find Cython if it exists try: import Cython except: Cython_OK = False else: Cython_OK = _version2int(Cython.__version__) >= _version2int('0.14') def test_compare_solvers_coherent_state_legacy(): """ correlation: legacy me and es for oscillator in coherent initial state """ N = 20 a = destroy(N) H = a.dag() * a G1 = 0.75 n_th = 2.00 c_ops = [np.sqrt(G1 * (1 + n_th)) * a, np.sqrt(G1 * n_th) * a.dag()] rho0 = coherent_dm(N, np.sqrt(4.0)) taulist = np.linspace(0, 5.0, 100)
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ############################################################################### import scipy import numpy as np from numpy.testing import assert_equal, run_module_suite import unittest from qutip import num, rand_herm, expect, rand_unitary from qutip import _version2int @unittest.skipIf( _version2int(scipy.__version__) < _version2int('0.10'), 'Known to fail on SciPy ' + scipy.__version__) def test_SparseHermValsVecs(): """ Sparse eigs Hermitian """ # check using number operator N = num(10) spvals, spvecs = N.eigenstates(sparse=True) for k in range(10): # check that eigvals are in proper order assert_equal(abs(spvals[k] - k) <= 1e-13, True) # check that eigenvectors are right and in right order assert_equal(abs(expect(N, spvecs[k]) - spvals[k]) < 5e-14, True)
g * (a.dag() * sm + a * sm.dag()) c_ops = [ sqrt(kappa * (1 + n_th)) * a, sqrt(kappa * n_th) * a.dag(), sqrt(gamma) * sm ] wlist = 2 * pi * np.linspace(0.5, 1.5, 100) spec1 = spectrum(H, wlist, c_ops, a.dag(), a, solver='es') spec2 = spectrum(H, wlist, c_ops, a.dag(), a, solver='pi') assert_(max(abs(spec1 - spec2)) < 1e-3) @unittest.skipIf( _version2int(Cython.__version__) < _version2int('0.14') or Cython_found == 0, 'Cython not found or version too low.') def test_str_list_td_corr(): """ correlation: comparing TLS emission correlations (str-list td format) """ # calculate emission zero-delay second order correlation, g2(0), for TLS # with following parameters: # gamma = 1, omega = 2, tp = 0.5 # Then: g2(0)~0.57 sm = destroy(2) args = {"t_off": 1, "tp": 0.5} H = [[2 * (sm + sm.dag()), "exp(-(t-t_off)**2 / (2*tp**2))"]] tlist = linspace(0, 5, 50) corr = correlation_3op_2t(H,
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ############################################################################### import numpy as np from numpy.testing import assert_, run_module_suite, assert_allclose import unittest from qutip import * from qutip import _version2int try: import Cython except: Cython_OK = False else: Cython_OK = _version2int(Cython.__version__) >= _version2int('0.14') @unittest.skipIf(not Cython_OK, 'Cython not found or version too low.') def test_td_brmesolve_basic(): """ td_brmesolve: passes all brmesolve tests """ # Test #1 delta = 0.0 * 2 * np.pi epsilon = 0.5 * 2 * np.pi gamma = 0.25 times = np.linspace(0, 10, 100) H = delta / 2 * sigmax() + epsilon / 2 * sigmaz() psi0 = (2 * basis(2, 0) + basis(2, 1)).unit()
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ############################################################################### import pytest import numpy as np import qutip try: import Cython except ImportError: Cython_OK = False else: cython_version = qutip._version2int(Cython.__version__) Cython_OK = cython_version >= qutip._version2int('0.14') pytestmark = pytest.mark.skipif(not Cython_OK, reason="Cython not found, or version too low.", allow_module_level=True) def pauli_spin_operators(): return [qutip.sigmax(), qutip.sigmay(), qutip.sigmaz()] _simple_qubit_gamma = 0.25 _m_c_op = np.sqrt(_simple_qubit_gamma) * qutip.sigmam() _z_c_op = np.sqrt(_simple_qubit_gamma) * qutip.sigmaz() _x_a_op = [qutip.sigmax(), '{0} * (w >= 0)'.format(_simple_qubit_gamma)]
N = 10 # number of basis states to consider a = destroy(N) H = a.dag() * a psi0 = basis(N, 9) # initial state kappa = 0.2 # coupling to oscillator c_op_list = [[a, sqrt_kappa]] tlist = np.linspace(0, 10, 100) mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj) expt = mcdata.expect[0] actual_answer = 9.0 * np.exp(-kappa * tlist) avg_diff = np.mean(abs(actual_answer - expt) / actual_answer) assert_equal(avg_diff < mc_error, True) @unittest.skipIf( _version2int(Cython.__version__) < _version2int("0.14") or Cython_found == 0, "Cython not found or version too low." ) def test_MCSimpleConstStr(): "Monte-carlo: Collapse terms constant (str format)" N = 10 # number of basis states to consider a = destroy(N) H = a.dag() * a psi0 = basis(N, 9) # initial state kappa = 0.2 # coupling to oscillator c_op_list = [[a, "sqrt(k)"]] args = {"k": kappa} tlist = np.linspace(0, 10, 100) mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], args=args, ntraj=ntraj) expt = mcdata.expect[0] actual_answer = 9.0 * np.exp(-kappa * tlist) avg_diff = np.mean(abs(actual_answer - expt) / actual_answer)
"Monte-carlo: Collapse terms constant (func format)" N = 10 # number of basis states to consider a = destroy(N) H = a.dag() * a psi0 = basis(N, 9) # initial state kappa = 0.2 # coupling to oscillator c_op_list = [[a, sqrt_kappa]] tlist = linspace(0, 10, 100) mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a]) expt = mcdata.expect[0] actual_answer = 9.0 * exp(-kappa * tlist) avg_diff = mean(abs(actual_answer - expt) / actual_answer) assert_equal(avg_diff < mc_error, True) @unittest.skipIf(_version2int(Cython.__version__) < _version2int('0.14') or Cython_found == 0, 'Cython not found or version too low.') def test_MCSimpleConstStr(): "Monte-carlo: Collapse terms constant (str format)" N = 10 # number of basis states to consider a = destroy(N) H = a.dag() * a psi0 = basis(N, 9) # initial state kappa = 0.2 # coupling to oscillator c_op_list = [[a, 'sqrt(k)']] args = {'k': kappa} tlist = linspace(0, 10, 100) mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], args=args) expt = mcdata.expect[0] actual_answer = 9.0 * exp(-kappa * tlist) avg_diff = mean(abs(actual_answer - expt) / actual_answer)
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ############################################################################### import scipy import numpy as np from numpy.testing import assert_equal, run_module_suite, assert_ import unittest from qutip import num, rand_herm, expect, rand_unitary from qutip import _version2int @unittest.skipIf(_version2int(scipy.__version__) < _version2int('0.10'), 'Known to fail on SciPy ' + scipy.__version__) def test_SparseHermValsVecs(): """ Sparse eigs Hermitian """ # check using number operator N = num(10) spvals, spvecs = N.eigenstates(sparse=True) for k in range(10): # check that eigvals are in proper order assert_equal(abs(spvals[k] - k) <= 1e-13, True) # check that eigenvectors are right and in right order assert_equal(abs(expect(N, spvecs[k]) - spvals[k]) < 5e-14, True)