本文整理汇总了Python中qutip.superop_reps.to_choi函数的典型用法代码示例。如果您正苦于以下问题:Python to_choi函数的具体用法?Python to_choi怎么用?Python to_choi使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_choi函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_ChoiPreservesSelf
def test_ChoiPreservesSelf(self):
"""
Superoperator: to_choi(q) returns q if q is already Choi.
"""
superop = rand_super()
choi = to_choi(superop)
assert_(choi is to_choi(choi))
开发者ID:PhilipVinc,项目名称:qutip,代码行数:7,代码来源:test_superop_reps.py
示例2: case
def case(qobj):
qobj = to_chi(qobj)
rt_qobj = to_chi(to_choi(qobj))
assert_almost_equal(rt_qobj.data.toarray(), qobj.data.toarray())
assert_equal(rt_qobj.type, qobj.type)
assert_equal(rt_qobj.dims, qobj.dims)
开发者ID:PhilipVinc,项目名称:qutip,代码行数:7,代码来源:test_superop_reps.py
示例3: test_choi_tr
def test_choi_tr(self):
"""
Superoperator: Checks that the trace of matrices returned by to_choi
matches that asserted by the docstring for that function.
"""
for dims in range(2, 5):
assert_(abs(to_choi(identity(dims)).tr() - dims) <= tol)
开发者ID:fekad,项目名称:qutip,代码行数:7,代码来源:test_superop_reps.py
示例4: test_tensor_swap_other
def test_tensor_swap_other():
dims = (2, 3, 4, 5, 7)
for dim in dims:
S = to_super(rand_super_bcsz(dim))
# Swapping the inner indices on a superoperator should give a Choi matrix.
J = to_choi(S)
case_tensor_swap(S, [(1, 2)], [[[dim], [dim]], [[dim], [dim]]], J)
开发者ID:kafischer,项目名称:qutip,代码行数:9,代码来源:test_tensor.py
示例5: test_ChoiKrausChoi
def test_ChoiKrausChoi(self):
"""
Superoperator: Convert superoperator to Choi matrix and back.
"""
superoperator = rand_super()
choi_matrix = to_choi(superoperator)
kraus_ops = to_kraus(choi_matrix)
test_choi = kraus_to_choi(kraus_ops)
# Assert both that the result is close to expected, and has the right
# type.
assert_((test_choi - choi_matrix).norm() < tol)
assert_(choi_matrix.type == "super" and choi_matrix.superrep == "choi")
assert_(test_choi.type == "super" and test_choi.superrep == "choi")
开发者ID:PhilipVinc,项目名称:qutip,代码行数:14,代码来源:test_superop_reps.py
示例6: test_SuperChoiSuper
def test_SuperChoiSuper(self):
"""
Superoperator: Converting superoperator to Choi matrix and back.
"""
superoperator = rand_super()
choi_matrix = to_choi(superoperator)
test_supe = to_super(choi_matrix)
# Assert both that the result is close to expected, and has the right
# type.
assert_((test_supe - superoperator).norm() < tol)
assert_(choi_matrix.type == "super" and choi_matrix.superrep == "choi")
assert_(test_supe.type == "super" and test_supe.superrep == "super")
开发者ID:PhilipVinc,项目名称:qutip,代码行数:14,代码来源:test_superop_reps.py
示例7: test_dag_preserves_superrep
def test_dag_preserves_superrep():
"""
Checks that dag() preserves superrep.
"""
def case(qobj):
orig_superrep = qobj.superrep
assert_equal(qobj.dag().superrep, orig_superrep)
for dim in (2, 4, 8):
qobj = rand_super_bcsz(dim)
yield case, to_super(qobj)
# These two shouldn't even do anything, since qobj
# is Hermicity-preserving.
yield case, to_choi(qobj)
yield case, to_chi(qobj)
开发者ID:arnelg,项目名称:qutip,代码行数:16,代码来源:test_qobj.py
示例8: test_SuperChoiChiSuper
def test_SuperChoiChiSuper(self):
"""
Superoperator: Converting two-qubit superoperator through
Choi and chi representations goes back to right superoperator.
"""
superoperator = super_tensor(rand_super(2), rand_super(2))
choi_matrix = to_choi(superoperator)
chi_matrix = to_chi(choi_matrix)
test_supe = to_super(chi_matrix)
# Assert both that the result is close to expected, and has the right
# type.
assert_((test_supe - superoperator).norm() < tol)
assert_(choi_matrix.type == "super" and choi_matrix.superrep == "choi")
assert_(chi_matrix.type == "super" and chi_matrix.superrep == "chi")
assert_(test_supe.type == "super" and test_supe.superrep == "super")
开发者ID:PhilipVinc,项目名称:qutip,代码行数:17,代码来源:test_superop_reps.py
示例9: test_choi_tr
def test_choi_tr(self):
"""
Superoperator: Trace returned by to_choi matches docstring.
"""
for dims in range(2, 5):
assert_(abs(to_choi(identity(dims)).tr() - dims) <= tol)
开发者ID:PhilipVinc,项目名称:qutip,代码行数:6,代码来源:test_superop_reps.py
示例10: dnorm
def dnorm(A, B=None, solver="CVXOPT", verbose=False, force_solve=False):
"""
Calculates the diamond norm of the quantum map q_oper, using
the simplified semidefinite program of [Wat12]_.
The diamond norm SDP is solved by using CVXPY_.
Parameters
----------
A : Qobj
Quantum map to take the diamond norm of.
B : Qobj or None
If provided, the diamond norm of :math:`A - B` is
taken instead.
solver : str
Solver to use with CVXPY. One of "CVXOPT" (default)
or "SCS". The latter tends to be significantly faster,
but somewhat less accurate.
verbose : bool
If True, prints additional information about the
solution.
force_solve : bool
If True, forces dnorm to solve the associated SDP, even if a special
case is known for the argument.
Returns
-------
dn : float
Diamond norm of q_oper.
Raises
------
ImportError
If CVXPY cannot be imported.
.. _cvxpy: http://www.cvxpy.org/en/latest/
"""
if cvxpy is None: # pragma: no cover
raise ImportError("dnorm() requires CVXPY to be installed.")
# We follow the strategy of using Watrous' simpler semidefinite
# program in its primal form. This is the same strategy used,
# for instance, by both pyGSTi and SchattenNorms.jl. (By contrast,
# QETLAB uses the dual problem.)
# Check if A and B are both unitaries. If so, then we can without
# loss of generality choose B to be the identity by using the
# unitary invariance of the diamond norm,
# || A - B ||_♢ = || A B⁺ - I ||_♢.
# Then, using the technique mentioned by each of Johnston and
# da Silva,
# || A B⁺ - I ||_♢ = max_{i, j} | \lambda_i(A B⁺) - \lambda_j(A B⁺) |,
# where \lambda_i(U) is the ith eigenvalue of U.
if (
# There's a lot of conditions to check for this path.
not force_solve and B is not None and
# Only check if they aren't superoperators.
A.type == "oper" and B.type == "oper" and
# The difference of unitaries optimization is currently
# only implemented for d == 2. Much of the code below is more general,
# though, in anticipation of generalizing the optimization.
A.shape[0] == 2
):
# Make an identity the same size as A and B to
# compare against.
I = qeye(A.dims[0])
# Compare to B first, so that an error is raised
# as soon as possible.
Bd = B.dag()
if (
(B * Bd - I).norm() < 1e-6 and
(A * A.dag() - I).norm() < 1e-6
):
# Now we are on the fast path, so let's compute the
# eigenvalues, then find the diameter of the smallest circle
# containing all of them.
#
# For now, this is only implemented for dim = 2, such that
# generalizing here will allow for generalizing the optimization.
# A reasonable approach would probably be to use Welzl's algorithm
# (https://en.wikipedia.org/wiki/Smallest-circle_problem).
U = A * B.dag()
eigs = U.eigenenergies()
eig_distances = np.abs(eigs[:, None] - eigs[None, :])
return np.max(eig_distances)
# Force the input superoperator to be a Choi matrix.
J = to_choi(A)
if B is not None:
J -= to_choi(B)
# Watrous 2012 also points out that the diamond norm of Lambda
# is the same as the completely-bounded operator-norm (∞-norm)
# of the dual map of Lambda. We can evaluate that norm much more
# easily if Lambda is completely positive, since then the largest
# eigenvalue is the same as the largest singular value.
if not force_solve and J.iscp:
#.........这里部分代码省略.........
开发者ID:ajgpitch,项目名称:qutip,代码行数:101,代码来源:metrics.py
示例11: test_dnorm_qubit_known_cases
def test_dnorm_qubit_known_cases():
"""
Metrics: check agreement for known qubit channels.
"""
def case(chan1, chan2, expected, significant=4):
# We again take a generous tolerance so that we don't kill off
# SCS solvers.
assert_approx_equal(
dnorm(chan1, chan2), expected,
significant=significant
)
id_chan = to_choi(qeye(2))
S_eye = to_super(id_chan)
X_chan = to_choi(sigmax())
depol = to_choi(Qobj(
diag(ones((4,))),
dims=[[[2], [2]], [[2], [2]]], superrep='chi'
))
S_H = to_super(hadamard_transform())
W = swap()
# We need to restrict the number of iterations for things on the boundary,
# such as perfectly distinguishable channels.
yield case, id_chan, X_chan, 2
yield case, id_chan, depol, 1.5
# Next, we'll generate some test cases based on comparisons to pre-existing
# dnorm() implementations. In particular, the targets for the following
# test cases were generated using QuantumUtils for MATLAB (https://goo.gl/oWXhO9).
def overrotation(x):
return to_super((1j * np.pi * x * sigmax() / 2).expm())
for x, target in {
1.000000e-03: 3.141591e-03,
3.100000e-03: 9.738899e-03,
1.000000e-02: 3.141463e-02,
3.100000e-02: 9.735089e-02,
1.000000e-01: 3.128689e-01,
3.100000e-01: 9.358596e-01
}.items():
yield case, overrotation(x), id_chan, target
def had_mixture(x):
return (1 - x) * S_eye + x * S_H
for x, target in {
1.000000e-03: 2.000000e-03,
3.100000e-03: 6.200000e-03,
1.000000e-02: 2.000000e-02,
3.100000e-02: 6.200000e-02,
1.000000e-01: 2.000000e-01,
3.100000e-01: 6.200000e-01
}.items():
yield case, had_mixture(x), id_chan, target
def swap_map(x):
S = (1j * x * W).expm()
S._type = None
S.dims = [[[2], [2]], [[2], [2]]]
S.superrep = 'super'
return S
for x, target in {
1.000000e-03: 2.000000e-03,
3.100000e-03: 6.199997e-03,
1.000000e-02: 1.999992e-02,
3.100000e-02: 6.199752e-02,
1.000000e-01: 1.999162e-01,
3.100000e-01: 6.173918e-01
}.items():
yield case, swap_map(x), id_chan, target
# Finally, we add a known case from Johnston's QETLAB documentation,
# || Phi - I ||,_♢ where Phi(X) = UXU⁺ and U = [[1, 1], [-1, 1]] / sqrt(2).
yield case, Qobj([[1, 1], [-1, 1]]) / np.sqrt(2), qeye(2), np.sqrt(2)
开发者ID:QuantumLambda,项目名称:qutip,代码行数:78,代码来源:test_metrics.py
注:本文中的qutip.superop_reps.to_choi函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论