Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _default_kwargs():
settings = {'num_cpus': qset.num_cpus}
return settings
out.isherm = True
for n, q in enumerate(qlist):
if n == 0:
out.data = q.data
out.dims = q.dims
else:
out.data = zcsr_kron(out.data, q.data)
out.dims = [out.dims[0] + q.dims[0], out.dims[1] + q.dims[1]]
out.isherm = out.isherm and q.isherm
if not out.isherm:
out._isherm = None
return out.tidyup() if qutip.settings.auto_tidyup else out
def calculate_openmp_thresh():
if qset.num_cpus == 1:
return qset.openmp_thresh
jc_dims = np.unique(np.logspace(0.45, 1.78, 20,dtype=int))
jc_result = system_bench(_jc_liouvillian, jc_dims)
opto_dims = np.unique(np.logspace(0.4, 1.33, 12, dtype=int))
opto_result = system_bench(_opto_liouvillian, opto_dims)
spin_dims = np.unique(np.logspace(0.45, 1.17, 10, dtype=int))
spin_result = system_bench(_spin_hamiltonian, spin_dims)
# Double result to be conservative
thresh = 2*int(max([jc_result,opto_result,spin_result]))
if thresh < 0:
thresh = np.iinfo(np.int32).max
return thresh
"""
Loads the configuration data from the
qutiprc file
"""
config = configparser.ConfigParser()
_valid_keys ={'auto_tidyup' : config.getboolean, 'auto_herm' : config.getboolean,
'atol': config.getfloat, 'auto_tidyup_atol' : config.getfloat,
'num_cpus' : config.getint, 'debug' : config.getboolean,
'log_handler' : config.getboolean, 'colorblind_safe' : config.getboolean,
'openmp_thresh': config.getint}
config.read(rc_file)
if config.has_section('qutip'):
opts = config.options('qutip')
for op in opts:
if op in _valid_keys.keys():
setattr(qset, op, _valid_keys[op]('qutip',op))
else:
raise Exception('Invalid config variable in qutiprc.')
else:
raise configparser.NoSectionError('qutip')
if config.has_section('compiler'):
_valid_keys = ['CC', 'CXX']
opts = config.options('compiler')
for op in opts:
up_op = op.upper()
if up_op in _valid_keys:
os.environ[up_op] = config.get('compiler', op)
else:
raise Exception('Invalid config variable in qutiprc.')
def _td_brmesolve(H, psi0, tlist, a_ops=[], e_ops=[], c_ops=[], args={},
use_secular=True, sec_cutoff=0.1,
tol=qset.atol, options=None,
progress_bar=None,_safe_mode=True,
verbose=False,
_prep_time=0):
if isket(psi0):
rho0 = ket2dm(psi0)
else:
rho0 = psi0
nrows = rho0.shape[0]
H_terms = []
H_td_terms = []
H_obj = []
A_terms = []
A_td_terms = []
C_terms = []
v = v / la.norm(v, np.inf)
data = v / sum(tr_vec.dot(v))
data = reshape(data, (rhoss.shape[0], rhoss.shape[1])).T
rhoss.data = sp.csr_matrix(data)
it += 1
if la.norm(L * v, np.inf) <= tol:
break
if it >= maxiter:
raise ValueError('Failed to find steady state after ' +
str(maxiter) + ' iterations')
return rhoss.tidyup() if qset.auto_tidyup else rhoss
def __div__(self, other):
"""
DIVISION (by numbers only)
"""
if isinstance(other, Qobj): # if both are quantum objects
raise TypeError("Incompatible Qobj shapes " +
"[division with Qobj not implemented]")
if isinstance(other, (int, float, complex,
np.integer, np.floating, np.complexfloating)):
out = Qobj()
out.data = self.data / other
out.dims = self.dims
if settings.auto_tidyup: out.tidyup()
if isinstance(other, complex):
out._isherm = out.isherm
else:
out._isherm = self._isherm
out.superrep = self.superrep
return out
else:
raise TypeError("Incompatible object for division")
# tidyup Hamiltonian before calculation (default = True)
self.tidy = tidy
# include the state in the function callback signature
self.rhs_with_state = rhs_with_state
# Use preexisting RHS function for time-dependent solvers
self.rhs_reuse = rhs_reuse
# Use filename for preexisting RHS function (will default to last
# compiled function if None & rhs_exists=True)
self.rhs_filename = rhs_filename
# small value in mc solver for computing correlations
self.mc_corr_eps = 1e-10
# Number of processors to use (mcsolve only)
if num_cpus:
self.num_cpus = num_cpus
else:
self.num_cpus = qset.num_cpus
# Tolerance for wavefunction norm (mcsolve only)
self.norm_tol = norm_tol
# Tolerance for collapse time precision (mcsolve only)
self.norm_t_tol = norm_t_tol
# Max. number of steps taken to find wavefunction norm to within
# norm_tol (mcsolve only)
self.norm_steps = norm_steps
# Number of threads for openmp
if openmp_threads is None:
self.openmp_threads = qset.num_cpus
else:
self.openmp_threads = openmp_threads
# store final state?
self.store_final_state = store_final_state
# store states even if expectation operators are given?
self.store_states = store_states
def check_use_openmp(options):
"""
Check to see if OPENMP should be used in dynamic solvers.
"""
force_omp = False
if qset.has_openmp and options.use_openmp is None:
options.use_openmp = True
force_omp = False
elif qset.has_openmp and options.use_openmp == True:
force_omp = True
elif qset.has_openmp and options.use_openmp == False:
force_omp = False
elif qset.has_openmp == False and options.use_openmp == True:
raise Exception('OPENMP not available.')
else:
options.use_openmp = False
force_omp = False
#Disable OPENMP in parallel mode unless explicitly set.
if not force_omp and os.environ['QUTIP_IN_PARALLEL'] == 'TRUE':
options.use_openmp = False
_st = time.time()
cgen = BR_Codegen(h_terms=len(H_terms),
h_td_terms=H_td_terms, h_obj=H_obj,
c_terms=len(C_terms),
c_td_terms=C_td_terms, c_obj=CA_obj,
a_terms=len(A_terms), a_td_terms=A_td_terms,
spline_count=spline_count,
coupled_ops = coupled_ops,
coupled_lengths = coupled_lengths,
coupled_spectra = coupled_spectra,
config=config, sparse=False,
use_secular = use_secular,
sec_cutoff = sec_cutoff,
args=args,
use_openmp=options.use_openmp,
omp_thresh=qset.openmp_thresh if qset.has_openmp else None,
omp_threads=options.num_cpus,
atol=tol)
cgen.generate(config.tdname + ".pyx")
code = compile('from ' + config.tdname + ' import cy_td_ode_rhs',
'', 'exec')
exec(code, globals())
config.tdfunc = cy_td_ode_rhs
if verbose:
print('BR compile time:', time.time()-_st)
initial_vector = mat2vec(rho0.full()).ravel()
_ode = scipy.integrate.ode(config.tdfunc)
code = compile('_ode.set_f_params(' + parameter_string + ')',
'', 'exec')
_ode.set_integrator('zvode', method=options.method,