Skip to content

Commit c9ce551

Browse files
committed
update algorithms and examples
1 parent d95ae5f commit c9ce551

File tree

1,201 files changed

+1436125
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,201 files changed

+1436125
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

LICENSE.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2011 and later, Paul D. Nation and Robert J. Johansson.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
3. Neither the name of the QuTiP: Quantum Toolbox in Python nor the names of
15+
its contributors may be used to endorse or promote products derived from this
16+
software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

MANIFEST.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include README.md
2+
include LICENSE.txt
3+
include VERSION
4+
include requirements.txt
5+
include qutip.bib
6+
include pyproject.toml
7+
recursive-include qutip *.pyx
8+
recursive-include qutip *.pxd
9+
recursive-include qutip *.pxi
10+
recursive-include qutip *.hpp
11+
recursive-include qutip *.cpp
12+
recursive-include qutip *.ini
13+
recursive-include qutip/tests/qasm_files *.qasm

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.7.0.dev
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
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+
import os
34+
import warnings
35+
36+
import qutip.settings
37+
import qutip.version
38+
from qutip.version import version as __version__
39+
40+
# -----------------------------------------------------------------------------
41+
# Check if we're in IPython.
42+
try:
43+
__IPYTHON__
44+
qutip.settings.ipython = True
45+
except NameError:
46+
qutip.settings.ipython = False
47+
48+
49+
# -----------------------------------------------------------------------------
50+
# Look to see if we are running with OPENMP
51+
#
52+
# Set environ variable to determin if running in parallel mode
53+
# (i.e. in parfor or parallel_map)
54+
os.environ['QUTIP_IN_PARALLEL'] = 'FALSE'
55+
56+
try:
57+
from qutip.cy.openmp.parfuncs import spmv_csr_openmp
58+
except ImportError:
59+
qutip.settings.has_openmp = False
60+
else:
61+
qutip.settings.has_openmp = True
62+
# See Pull #652 for why this is here.
63+
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
64+
65+
import platform
66+
import scipy
67+
from packaging import version as pac_version
68+
from qutip.utilities import _blas_info
69+
70+
is_old_scipy = pac_version.parse(scipy.__version__) < pac_version.parse("1.5")
71+
qutip.settings.eigh_unsafe = (
72+
# macOS OpenBLAS eigh is unstable, see #1288
73+
(_blas_info() == "OPENBLAS" and platform.system() == 'Darwin')
74+
# The combination of scipy<1.5 and MKL causes wrong results when calling
75+
# eigh for big matrices. See #1495, #1491 and #1498.
76+
or (is_old_scipy and (_blas_info() == 'INTEL MKL'))
77+
)
78+
79+
del platform, _blas_info, scipy, pac_version, is_old_scipy
80+
# -----------------------------------------------------------------------------
81+
# setup the cython environment
82+
#
83+
try:
84+
import Cython as _Cython
85+
except ImportError:
86+
pass
87+
else:
88+
from qutip.utilities import _version2int
89+
_cy_require = "0.29.20"
90+
if _version2int(_Cython.__version__) < _version2int(_cy_require):
91+
warnings.warn(
92+
"Old version of Cython detected: needed {}, got {}."
93+
.format(_cy_require, _Cython.__version__)
94+
)
95+
# Setup pyximport
96+
import qutip.cy.pyxbuilder as _pyxbuilder
97+
_pyxbuilder.install()
98+
del _pyxbuilder, _Cython, _version2int
99+
100+
101+
# -----------------------------------------------------------------------------
102+
# cpu/process configuration
103+
#
104+
import multiprocessing
105+
106+
# Check if environ flag for qutip processes is set
107+
if 'QUTIP_NUM_PROCESSES' in os.environ:
108+
qutip.settings.num_cpus = int(os.environ['QUTIP_NUM_PROCESSES'])
109+
else:
110+
os.environ['QUTIP_NUM_PROCESSES'] = str(qutip.settings.num_cpus)
111+
112+
if qutip.settings.num_cpus == 0:
113+
# if num_cpu is 0 set it to the available number of cores
114+
import qutip.hardware_info
115+
info = qutip.hardware_info.hardware_info()
116+
if 'cpus' in info:
117+
qutip.settings.num_cpus = info['cpus']
118+
else:
119+
try:
120+
qutip.settings.num_cpus = multiprocessing.cpu_count()
121+
except NotImplementedError:
122+
qutip.settings.num_cpus = 1
123+
124+
del multiprocessing
125+
126+
127+
# Find MKL library if it exists
128+
import qutip._mkl
129+
130+
131+
# -----------------------------------------------------------------------------
132+
# Check that import modules are compatible with requested configuration
133+
#
134+
135+
# Check for Matplotlib
136+
try:
137+
import matplotlib
138+
except ImportError:
139+
warnings.warn("matplotlib not found: Graphics will not work.")
140+
else:
141+
del matplotlib
142+
143+
144+
# -----------------------------------------------------------------------------
145+
# Load modules
146+
#
147+
148+
# core
149+
from qutip.qobj import *
150+
from qutip.qobjevo import *
151+
from qutip.states import *
152+
from qutip.operators import *
153+
from qutip.expect import *
154+
from qutip.tensor import *
155+
from qutip.superoperator import *
156+
from qutip.superop_reps import *
157+
from qutip.subsystem_apply import *
158+
from qutip.graph import *
159+
160+
# graphics
161+
from qutip.bloch import *
162+
from qutip.visualization import *
163+
from qutip.orbital import *
164+
from qutip.bloch3d import *
165+
from qutip.matplotlib_utilities import *
166+
167+
# library functions
168+
from qutip.tomography import *
169+
from qutip.wigner import *
170+
from qutip.random_objects import *
171+
from qutip.simdiag import *
172+
from qutip.entropy import *
173+
from qutip.metrics import *
174+
from qutip.partial_transpose import *
175+
from qutip.permute import *
176+
from qutip.continuous_variables import *
177+
from qutip.distributions import *
178+
from qutip.three_level_atom import *
179+
180+
# evolution
181+
from qutip.solver import *
182+
from qutip.rhs_generate import *
183+
from qutip.mesolve import *
184+
from qutip.sesolve import *
185+
from qutip.mcsolve import *
186+
from qutip.stochastic import *
187+
from qutip.essolve import *
188+
from qutip.eseries import *
189+
from qutip.propagator import *
190+
from qutip.floquet import *
191+
from qutip.bloch_redfield import *
192+
from qutip.cy.br_tensor import bloch_redfield_tensor
193+
from qutip.steadystate import *
194+
from qutip.correlation import *
195+
from qutip.countstat import *
196+
from qutip.rcsolve import *
197+
from qutip.nonmarkov import *
198+
from qutip.interpolate import *
199+
from qutip.scattering import *
200+
201+
# lattice models
202+
from qutip.lattice import *
203+
from qutip.topology import *
204+
205+
########################################################################
206+
# This section exists only for the deprecation warning of qip importation.
207+
# It can be deleted for a major release.
208+
209+
# quantum information
210+
from qutip.qip import *
211+
########################################################################
212+
213+
# utilities
214+
from qutip.parallel import *
215+
from qutip.utilities import *
216+
from qutip.fileio import *
217+
from qutip.about import *
218+
from qutip.cite import *
219+
220+
# -----------------------------------------------------------------------------
221+
# Load user configuration if present: override defaults.
222+
#
223+
import qutip.configrc
224+
has_rc, rc_file = qutip.configrc.has_qutip_rc()
225+
226+
# Read the OpenMP threshold out if it already exists, or calibrate and save it
227+
# if it doesn't.
228+
if qutip.settings.has_openmp:
229+
_calibrate_openmp = qutip.settings.num_cpus > 1
230+
if has_rc:
231+
_calibrate_openmp = (
232+
_calibrate_openmp
233+
and not qutip.configrc.has_rc_key('openmp_thresh', rc_file=rc_file)
234+
)
235+
else:
236+
qutip.configrc.generate_qutiprc()
237+
has_rc, rc_file = qutip.configrc.has_qutip_rc()
238+
if _calibrate_openmp:
239+
print('Calibrating OpenMP threshold...')
240+
from qutip.cy.openmp.bench_openmp import calculate_openmp_thresh
241+
thresh = calculate_openmp_thresh()
242+
qutip.configrc.write_rc_key('openmp_thresh', thresh, rc_file=rc_file)
243+
del calculate_openmp_thresh
244+
245+
# Load the config file
246+
if has_rc:
247+
qutip.configrc.load_rc_config(rc_file)
248+
249+
# -----------------------------------------------------------------------------
250+
# Clean name space
251+
#
252+
del os, warnings
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import qutip.settings as qset
2+
from qutip._mkl.utilities import _set_mkl
3+
_set_mkl()
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# This file is part of QuTiP: Quantum Toolbox in Python.
2+
#
3+
# Copyright (c) 2011 and later, Paul D. Nation.
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+
import numpy as np
34+
from ctypes import POINTER, c_int, c_char, byref
35+
from numpy import ctypeslib
36+
import qutip.settings as qset
37+
zcsrgemv = qset.mkl_lib.mkl_cspblas_zcsrgemv
38+
39+
def mkl_spmv(A, x):
40+
"""
41+
sparse csr_spmv using MKL
42+
"""
43+
(m,n) = A.shape
44+
45+
# Pointers to data of the matrix
46+
data = A.data.ctypes.data_as(ctypeslib.ndpointer(np.complex128, ndim=1, flags='C'))
47+
indptr = A.indptr.ctypes.data_as(POINTER(c_int))
48+
indices = A.indices.ctypes.data_as(POINTER(c_int))
49+
50+
# Allocate output, using same conventions as input
51+
if x.ndim == 1:
52+
y = np.empty(m,dtype=np.complex128,order='C')
53+
elif x.ndim==2 and x.shape[1]==1:
54+
y = np.empty((m,1),dtype=np.complex128,order='C')
55+
else:
56+
raise Exception('Input vector must be 1D row or 2D column vector')
57+
58+
np_x = x.ctypes.data_as(ctypeslib.ndpointer(np.complex128, ndim=1, flags='C'))
59+
np_y = y.ctypes.data_as(ctypeslib.ndpointer(np.complex128, ndim=1, flags='C'))
60+
# now call MKL. This returns the answer in np_y, which points to y
61+
zcsrgemv(byref(c_char(bytes(b'N'))), byref(c_int(m)), data ,indptr, indices, np_x, np_y )
62+
return y

0 commit comments

Comments
 (0)