Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _init_ptrace_stuff(sel):
psi0 = Qobj(config.psi0,
dims=config.psi0_dims,
shape=config.psi0_shape)
qtf90.qutraj_run.init_ptrace_stuff(config.psi0_dims[0],
np.array(sel) + 1,
psi0.ptrace(sel).shape[0])
def _get_onto_evo_target(self):
"""
Get the inverse of the target.
Used for calculating the 'onto target' evolution
This is actually only relevant for unitary dynamics where
the target.dag() is what is required
However, for completeness, in general the inverse of the target
operator is is required
For state-to-state, the bra corresponding to the is required ket
"""
if self.target.shape[0] == self.target.shape[1]:
#Target is operator
targ = la.inv(self.target.full())
if self.oper_dtype == Qobj:
self._onto_evo_target = Qobj(targ)
elif self.oper_dtype == np.ndarray:
self._onto_evo_target = targ
elif self.oper_dtype == sp.csr_matrix:
self._onto_evo_target = sp.csr_matrix(targ)
else:
targ_cls = self._target.__class__
self._onto_evo_target = targ_cls(targ)
else:
if self.oper_dtype == Qobj:
self._onto_evo_target = self.target.dag()
elif self.oper_dtype == np.ndarray:
self._onto_evo_target = self.target.dag().full()
elif self.oper_dtype == sp.csr_matrix:
self._onto_evo_target = self.target.dag().data
else:
targ_cls = self._target.__class__
# only reset the solver if state changed
r.set_initial_value(cdata, r.t)
else:
r._y = cdata
if opt.store_states:
if oper_evo:
fdata = dense2D_to_fastcsr_fmode(cdata, size, size)
output.states.append(Qobj(fdata, dims=dims))
else:
fdata = dense1D_to_fastcsr_ket(cdata)
output.states.append(Qobj(fdata, dims=dims, fast='mc'))
if expt_callback:
# use callback method
output.expect.append(e_ops(t, Qobj(cdata, dims=dims)))
if oper_evo:
for m in range(n_expt_op):
output.expect[m][t_idx] = (e_ops_data[m] * cdata).trace()
else:
for m in range(n_expt_op):
output.expect[m][t_idx] = cy_expect_psi(e_ops_data[m], cdata,
e_ops[m].isherm)
if t_idx < n_tsteps - 1:
r.integrate(r.t + dt[t_idx])
progress_bar.finished()
if opt.store_final_state:
cdata = get_curr_state_data(r)
if self.args[key] is None:
self.args[key] = Qobj(dims=statedims)
if key == "state_mat":
self.dynamics_args += [("state_mat", "mat", None)]
if isinstance(self.args[key], Qobj):
self.args[key] = self.args[key].full()
if self.args[key] is None:
self.args[key] = Qobj(dims=statedims).full()
if key == "state_vec":
self.dynamics_args += [("state_vec", "vec", None)]
if isinstance(self.args[key], Qobj):
self.args[key] = self.args[key].full().ravel("F")
if self.args[key] is None:
self.args[key] = Qobj(dims=statedims).full().ravel("F")
if key.startswith("expect_op_"):
e_op_num = int(key[10:])
self.dynamics_args += [(key, "expect", e_op_num)]
if isinstance(self.args[key], StateArgs):
self.dynamics_args += [(key, *self.args[key]())]
self.args[key] = 0.
dt, eps, alpha_val, beta_val, phase_sensitive,
use_u_limits, u_min, u_max)
if use_interp:
ip_funcs = [interp1d(times, u[R - 1, j, :], kind=interp_kind,
bounds_error=False, fill_value=u[R - 1, j, -1])
for j in range(J)]
H_td_func = [H0] + [[H_ops[j], lambda t, args, j=j: ip_funcs[j](t)]
for j in range(J)]
else:
H_td_func = [H0] + [[H_ops[j], u[-1, j, :]] for j in range(J)]
progress_bar.finished()
return GRAPEResult(u=u, U_f=Qobj(U_f_list[-1], dims=U.dims),
H_t=H_td_func)
Position for the annotaion.
Qobj of a qubit or a vector of 3 elements.
text : str/unicode
Annotation text.
You can use LaTeX, but remember to use raw string
e.g. r"$\\langle x \\rangle$"
or escape backslashes
e.g. "$\\\\langle x \\\\rangle$".
**kwargs :
Options as for mplot3d.axes3d.text, including:
fontsize, color, horizontalalignment, verticalalignment.
"""
if isinstance(state_or_vector, Qobj):
vec = [expect(sigmax(), state_or_vector),
expect(sigmay(), state_or_vector),
expect(sigmaz(), state_or_vector)]
elif isinstance(state_or_vector, (list, ndarray, tuple)) \
and len(state_or_vector) == 3:
vec = state_or_vector
else:
raise Exception("Position needs to be specified by a qubit " +
"state or a 3D vector.")
self.annotations.append({'position': vec,
'text': text,
'opts': kwargs})
------
ValueError
Input argument is not a quantum object.
"""
# Apply default colormaps.
# TODO: abstract this away into something that makes default
# colormaps.
cmap = (
(cm.Greys_r if settings.colorblind_safe else cm.RdBu)
if cmap is None else cmap
)
# Extract plotting data W from the input.
if isinstance(rho, Qobj):
if rho.isoper:
W = rho.full()
# Create default labels if none are given.
if xlabels is None or ylabels is None:
labels = _cb_labels(rho.dims[0])
xlabels = xlabels if xlabels is not None else list(labels[0])
ylabels = ylabels if ylabels is not None else list(labels[1])
elif rho.isoperket:
W = vector_to_operator(rho).full()
elif rho.isoperbra:
W = vector_to_operator(rho.dag()).full()
elif rho.issuper:
if not _isqubitdims(rho.dims):
raise ValueError("Hinton plots of superoperators are "
choi_matrix = super_to_choi(channel)
vals, vecs = eig(choi_matrix.full())
vecs = list(map(array, zip(*vecs)))
kraus_list = [sqrt(vals[j]) * vec2mat(vecs[j])
for j in range(len(vals))]
# Kraus operators to be padded with identities:
k_qubit_kraus_list = product(kraus_list, repeat=sum(mask))
rho_out = Qobj(inpt=zeros(state.shape), dims=state.dims)
for operator_iter in k_qubit_kraus_list:
operator_iter = iter(operator_iter)
op_iter_list = [next(operator_iter) if mask[j]
else qeye(state.dims[0][j])
for j in range(len(state.dims[0]))]
full_oper = tensor(list(map(Qobj, op_iter_list)))
rho_out = rho_out + full_oper * state * full_oper.dag()
return Qobj(rho_out)
def sqrtswap(N=None, targets=[0, 1]):
"""Quantum object representing the square root SWAP gate.
Returns
-------
sqrtswap_gate : qobj
Quantum object representation of square root SWAP gate
"""
if targets != [0, 1] and N is None:
N = 2
if N is not None:
return gate_expand_2toN(sqrtswap(), N, targets=targets)
else:
return Qobj(np.array([[1, 0, 0, 0],
[0, 0.5 + 0.5j, 0.5 - 0.5j, 0],
[0, 0.5 - 0.5j, 0.5 + 0.5j, 0],
[0, 0, 0, 1]]),
dims=[[2, 2], [2, 2]])
def cy_gate(N=None, control=0, target=1):
"""Controlled Y gate.
Returns
-------
result : :class:`qutip.Qobj`
Quantum object for operator describing the rotation.
"""
if (control == 1 and target == 0) and N is None:
N = 2
if N is not None:
return gate_expand_2toN(cy_gate(), N, control, target)
return Qobj([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, -1j],
[0, 0, 1j, 0]],
dims=[[2, 2], [2, 2]])