本文整理汇总了Python中qutip.random_objects.rand_herm函数的典型用法代码示例。如果您正苦于以下问题:Python rand_herm函数的具体用法?Python rand_herm怎么用?Python rand_herm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rand_herm函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_CheckMulType
def test_CheckMulType():
"Qobj multiplication type"
# ket-bra and bra-ket multiplication
psi = basis(5)
dm = psi * psi.dag()
assert_(dm.isoper)
assert_(dm.isherm)
nrm = psi.dag() * psi
assert_equal(np.prod(nrm.shape), 1)
assert_((abs(nrm) == 1)[0, 0])
# operator-operator multiplication
H1 = rand_herm(3)
H2 = rand_herm(3)
out = H1 * H2
assert_(out.isoper)
out = H1 * H1
assert_(out.isoper)
assert_(out.isherm)
out = H2 * H2
assert_(out.isoper)
assert_(out.isherm)
U = rand_unitary(5)
out = U.dag() * U
assert_(out.isoper)
assert_(out.isherm)
N = num(5)
out = N * N
assert_(out.isoper)
assert_(out.isherm)
# operator-ket and bra-operator multiplication
op = sigmax()
ket1 = basis(2)
ket2 = op * ket1
assert_(ket2.isket)
bra1 = basis(2).dag()
bra2 = bra1 * op
assert_(bra2.isbra)
assert_(bra2.dag() == ket2)
# superoperator-operket and operbra-superoperator multiplication
sop = to_super(sigmax())
opket1 = operator_to_vector(fock_dm(2))
opket2 = sop * opket1
assert(opket2.isoperket)
opbra1 = operator_to_vector(fock_dm(2)).dag()
opbra2 = opbra1 * sop
assert(opbra2.isoperbra)
assert_(opbra2.dag() == opket2)
开发者ID:arnelg,项目名称:qutip,代码行数:59,代码来源:test_qobj.py
示例2: test_zcsr_isherm
def test_zcsr_isherm():
"spmath: zcsr_isherm"
N = 100
for kk in range(100):
A = rand_herm(N, 0.1)
B = rand_herm(N, 0.05) + 1j*rand_herm(N, 0.05)
assert_(zcsr_isherm(A.data))
assert_(zcsr_isherm(B.data)==0)
开发者ID:ajgpitch,项目名称:qutip,代码行数:8,代码来源:test_spmath.py
示例3: test_csr_kron
def test_csr_kron():
"spmath: zcsr_kron"
for kk in range(10):
ra = np.random.randint(2,100)
rb = np.random.randint(2,100)
A = rand_herm(ra,0.5).data
B = rand_herm(rb,0.5).data
As = A.tocsr(1)
Bs = B.tocsr(1)
C = sp.kron(As,Bs, format='csr')
D = zcsr_kron(A, B)
assert_almost_equal(C.data, D.data)
assert_equal(C.indices, D.indices)
assert_equal(C.indptr, D.indptr)
for kk in range(10):
ra = np.random.randint(2,100)
rb = np.random.randint(2,100)
A = rand_ket(ra,0.5).data
B = rand_herm(rb,0.5).data
As = A.tocsr(1)
Bs = B.tocsr(1)
C = sp.kron(As,Bs, format='csr')
D = zcsr_kron(A, B)
assert_almost_equal(C.data, D.data)
assert_equal(C.indices, D.indices)
assert_equal(C.indptr, D.indptr)
for kk in range(10):
ra = np.random.randint(2,100)
rb = np.random.randint(2,100)
A = rand_dm(ra,0.5).data
B = rand_herm(rb,0.5).data
As = A.tocsr(1)
Bs = B.tocsr(1)
C = sp.kron(As,Bs, format='csr')
D = zcsr_kron(A, B)
assert_almost_equal(C.data, D.data)
assert_equal(C.indices, D.indices)
assert_equal(C.indptr, D.indptr)
for kk in range(10):
ra = np.random.randint(2,100)
rb = np.random.randint(2,100)
A = rand_ket(ra,0.5).data
B = rand_ket(rb,0.5).data
As = A.tocsr(1)
Bs = B.tocsr(1)
C = sp.kron(As,Bs, format='csr')
D = zcsr_kron(A, B)
assert_almost_equal(C.data, D.data)
assert_equal(C.indices, D.indices)
assert_equal(C.indptr, D.indptr)
开发者ID:anubhavvardhan,项目名称:qutip,代码行数:53,代码来源:test_spmath.py
示例4: test_csr_kron
def test_csr_kron():
"Sparse: Test CSR Kron"
for kk in range(10):
ra = np.random.randint(2,100)
rb = np.random.randint(2,100)
A = rand_herm(ra,0.5).data
B = rand_herm(rb,0.5).data
C = sp.kron(A,B, format='csr')
D = _csr_kron(A.data,A.indices,A.indptr, A.shape[0], A.shape[1],
B.data,B.indices,B.indptr, B.shape[0], B.shape[1])
assert_equal(C.data, D.data)
assert_equal(C.indices, D.indices)
assert_equal(C.indptr, D.indptr)
for kk in range(10):
ra = np.random.randint(2,100)
rb = np.random.randint(2,100)
A = rand_ket(ra,0.5).data
B = rand_herm(rb,0.5).data
C = sp.kron(A,B, format='csr')
D = _csr_kron(A.data,A.indices,A.indptr, A.shape[0], A.shape[1],
B.data,B.indices,B.indptr, B.shape[0], B.shape[1])
assert_equal(C.data, D.data)
assert_equal(C.indices, D.indices)
assert_equal(C.indptr, D.indptr)
for kk in range(10):
ra = np.random.randint(2,100)
rb = np.random.randint(2,100)
A = rand_dm(ra,0.5).data
B = rand_herm(rb,0.5).data
C = sp.kron(A,B, format='csr')
D = _csr_kron(A.data,A.indices,A.indptr, A.shape[0], A.shape[1],
B.data,B.indices,B.indptr, B.shape[0], B.shape[1])
assert_equal(C.data, D.data)
assert_equal(C.indices, D.indices)
assert_equal(C.indptr, D.indptr)
for kk in range(10):
ra = np.random.randint(2,100)
rb = np.random.randint(2,100)
A = rand_ket(ra,0.5).data
B = rand_ket(rb,0.5).data
C = sp.kron(A,B, format='csr')
D = _csr_kron(A.data,A.indices,A.indptr, A.shape[0], A.shape[1],
B.data,B.indices,B.indptr, B.shape[0], B.shape[1])
assert_equal(C.data, D.data)
assert_equal(C.indices, D.indices)
assert_equal(C.indptr, D.indptr)
开发者ID:nwlambert,项目名称:qutip,代码行数:49,代码来源:test_sparse.py
示例5: test_Qobj_Spmv
def test_Qobj_Spmv():
"Qobj mult ndarray right"
A = rand_herm(5)
b = rand_ket(5).full()
C = A*b
D = A.full().dot(b)
assert_(np.all((C-D)<1e-14))
开发者ID:arnelg,项目名称:qutip,代码行数:7,代码来源:test_qobj.py
示例6: test_fast_sparse_basic
def test_fast_sparse_basic():
"fastsparse: fast_csr_matrix operations"
H = rand_herm(5).data
assert_(isinstance(H, fast_csr_matrix))
Hadd = H + H
assert_(isinstance(Hadd, fast_csr_matrix))
Hsub = H + H
assert_(isinstance(Hsub, fast_csr_matrix))
Hmult = H * H
assert_(isinstance(Hmult, fast_csr_matrix))
Hcopy = H.copy()
assert_(isinstance(Hcopy, fast_csr_matrix))
assert_(isinstance(-1*H, fast_csr_matrix))
assert(isinstance(H/2., fast_csr_matrix))
G = sp.csr_matrix((H.data, H.indices,H.indptr),
copy=True, shape=H.shape)
assert_(not isinstance(G, fast_csr_matrix))
Hadd = H + G
assert_(not isinstance(Hadd, fast_csr_matrix))
Hadd = G + H
assert_(not isinstance(Hadd, fast_csr_matrix))
Hsub = H - G
assert_(not isinstance(Hsub, fast_csr_matrix))
Hsub = G - H
assert_(not isinstance(Hsub, fast_csr_matrix))
Hmult = H*G
assert_(not isinstance(Hmult, fast_csr_matrix))
Hmult = G*H
assert_(not isinstance(Hmult, fast_csr_matrix))
开发者ID:NunoEdgarGub1,项目名称:qutip,代码行数:30,代码来源:test_fastsparse.py
示例7: test_sp_inf_norm
def test_sp_inf_norm():
"Sparse: inf-norm"
for kk in range(10):
H = rand_herm(100,0.1).data
nrm = sp_inf_norm(H)
ans = max(abs(H).sum(axis=1).flat)
assert_almost_equal(nrm,ans)
开发者ID:NunoEdgarGub1,项目名称:qutip,代码行数:7,代码来源:test_sparse.py
示例8: test_fast_sparse_adjoint
def test_fast_sparse_adjoint():
"fastsparse: adjoint operations"
H = rand_herm(5).data
assert_(isinstance(H, fast_csr_matrix))
assert_(isinstance(H.H, fast_csr_matrix))
assert_(isinstance(H.getH(), fast_csr_matrix))
assert_(isinstance(H.adjoint(), fast_csr_matrix))
开发者ID:NunoEdgarGub1,项目名称:qutip,代码行数:7,代码来源:test_fastsparse.py
示例9: test_fast_sparse_trans
def test_fast_sparse_trans():
"fastsparse: transpose operations"
H = rand_herm(5).data
assert_(isinstance(H, fast_csr_matrix))
assert_(isinstance(H.T, fast_csr_matrix))
assert_(isinstance(H.trans(), fast_csr_matrix))
assert_(isinstance(H.transpose(), fast_csr_matrix))
开发者ID:NunoEdgarGub1,项目名称:qutip,代码行数:7,代码来源:test_fastsparse.py
示例10: test_isherm_skew
def test_isherm_skew():
"""
mul and tensor of skew-Hermitian operators report ``isherm = True``.
"""
iH = 1j * rand_herm(5)
assert_(not iH.isherm)
assert_((iH * iH).isherm)
assert_(tensor(iH, iH).isherm)
开发者ID:arnelg,项目名称:qutip,代码行数:9,代码来源:test_qobj.py
示例11: test_SuperChoiSuper
def test_SuperChoiSuper(self):
"""
Superoperator: Converting superoperator to Choi matrix and back.
"""
h_5 = rand_herm(5)
superoperator = propagator(h_5, scipy.rand(),
[create(5), destroy(5), jmat(2, 'z')])
choi_matrix = super_to_choi(superoperator)
test_supe = choi_to_super(choi_matrix)
assert_((test_supe - superoperator).norm() < 1e-12)
开发者ID:Shuangshuang,项目名称:qutip,代码行数:10,代码来源:test_superop_reps.py
示例12: test_QobjNorm
def test_QobjNorm():
"Qobj norm"
# vector L2-norm test
N = 20
x = np.random.random(N) + 1j * np.random.random(N)
A = Qobj(x)
assert_equal(np.abs(A.norm() - la.norm(A.data.data, 2)) < 1e-12, True)
# vector max (inf) norm test
assert_equal(
np.abs(A.norm('max') - la.norm(A.data.data, np.inf)) < 1e-12, True)
# operator frobius norm
x = np.random.random((N, N)) + 1j * np.random.random((N, N))
A = Qobj(x)
assert_equal(
np.abs(A.norm('fro') - la.norm(A.full(), 'fro')) < 1e-12, True)
# operator trace norm
a = rand_herm(10,0.25)
assert_almost_equal(a.norm(), (a*a.dag()).sqrtm().tr().real)
b = rand_herm(10,0.25) - 1j*rand_herm(10,0.25)
assert_almost_equal(b.norm(), (b*b.dag()).sqrtm().tr().real)
开发者ID:arnelg,项目名称:qutip,代码行数:20,代码来源:test_qobj.py
示例13: test_cosm
def test_cosm():
"""
Test Qobj: cosm
"""
A = rand_herm(5)
B = A.cosm().full()
C = la.cosm(A.full())
assert_(np.all((B-C)< 1e-14))
开发者ID:arnelg,项目名称:qutip,代码行数:11,代码来源:test_qobj.py
示例14: test_sinm
def test_sinm():
"""
Test Qobj: sinm
"""
A = rand_herm(5)
B = A.sinm().full()
C = la.sinm(A.full())
assert_(np.all((B-C)< 1e-14))
开发者ID:arnelg,项目名称:qutip,代码行数:11,代码来源:test_qobj.py
示例15: test_ChoiKrausChoi
def test_ChoiKrausChoi(self):
"""
Superoperator: Converting superoperator to Choi matrix and back.
"""
h_5 = rand_herm(5)
superoperator = propagator(h_5, scipy.rand(),
[create(5), destroy(5), jmat(2, 'z')])
choi_matrix = super_to_choi(superoperator)
kraus_ops = choi_to_kraus(choi_matrix)
test_choi = kraus_to_choi(kraus_ops)
assert_((test_choi - choi_matrix).norm() < 1e-12)
开发者ID:Shuangshuang,项目名称:qutip,代码行数:11,代码来源:test_superop_reps.py
示例16: testExpandGate3toN
def testExpandGate3toN(self):
"""
gates: expand 3 to N (using toffoli, fredkin, and random 3 qubit gate)
"""
a, b = np.random.rand(), np.random.rand()
psi1 = (a * basis(2, 0) + b * basis(2, 1)).unit()
c, d = np.random.rand(), np.random.rand()
psi2 = (c * basis(2, 0) + d * basis(2, 1)).unit()
e, f = np.random.rand(), np.random.rand()
psi3 = (e * basis(2, 0) + f * basis(2, 1)).unit()
N = 4
psi_rand_list = [rand_ket(2) for k in range(N)]
_rand_gate_U = tensor([rand_herm(2, density=1) for k in range(3)])
def _rand_3qubit_gate(N=None, controls=None, k=None):
if N is None:
return _rand_gate_U
else:
return gate_expand_3toN(_rand_gate_U, N, controls, k)
for g in [fredkin, toffoli, _rand_3qubit_gate]:
psi_ref_in = tensor(psi1, psi2, psi3)
psi_ref_out = g() * psi_ref_in
for m in range(N):
for n in set(range(N)) - {m}:
for k in set(range(N)) - {m, n}:
psi_list = [psi_rand_list[p] for p in range(N)]
psi_list[m] = psi1
psi_list[n] = psi2
psi_list[k] = psi3
psi_in = tensor(psi_list)
if g == fredkin:
targets = [n, k]
G = g(N, control=m, targets=targets)
else:
controls = [m, n]
G = g(N, controls, k)
psi_out = G * psi_in
o1 = psi_out.overlap(psi_in)
o2 = psi_ref_out.overlap(psi_ref_in)
assert_(abs(o1 - o2) < 1e-12)
开发者ID:tmng,项目名称:qutip,代码行数:52,代码来源:test_gates.py
示例17: test_zcsr_transpose
def test_zcsr_transpose():
"spmath: zcsr_transpose"
for k in range(50):
ra = np.random.randint(2,100)
A = rand_ket(ra,0.5).data
B = A.T.tocsr()
C = A.trans()
x = np.all(B.data == C.data)
y = np.all(B.indices == C.indices)
z = np.all(B.indptr == C.indptr)
assert_(x*y*z)
for k in range(50):
ra = np.random.randint(2,100)
A = rand_herm(5,1.0/ra).data
B = A.T.tocsr()
C = A.trans()
x = np.all(B.data == C.data)
y = np.all(B.indices == C.indices)
z = np.all(B.indptr == C.indptr)
assert_(x*y*z)
for k in range(50):
ra = np.random.randint(2,100)
A = rand_dm(ra,1.0/ra).data
B = A.T.tocsr()
C = A.trans()
x = np.all(B.data == C.data)
y = np.all(B.indices == C.indices)
z = np.all(B.indptr == C.indptr)
assert_(x*y*z)
for k in range(50):
ra = np.random.randint(2,100)
A = rand_unitary(ra,1.0/ra).data
B = A.T.tocsr()
C = A.trans()
x = np.all(B.data == C.data)
y = np.all(B.indices == C.indices)
z = np.all(B.indptr == C.indptr)
assert_(x*y*z)
开发者ID:anubhavvardhan,项目名称:qutip,代码行数:41,代码来源:test_spmath.py
示例18: test_matelem
def test_matelem():
"""
Test Qobj: Compute matrix elements
"""
for kk in range(10):
N = 20
H = rand_herm(N,0.2)
L = rand_ket(N,0.3)
Ld = L.dag()
R = rand_ket(N,0.3)
ans = (Ld*H*R).tr()
#bra-ket
out1 = H.matrix_element(Ld,R)
#ket-ket
out2 = H.matrix_element(Ld,R)
assert_(abs(ans-out1) < 1e-14)
assert_(abs(ans-out2) < 1e-14)
开发者ID:arnelg,项目名称:qutip,代码行数:21,代码来源:test_qobj.py
示例19: test_zcsr_mult
def test_zcsr_mult():
"spmath: zcsr_mult"
for k in range(50):
A = rand_ket(10,0.5).data
B = rand_herm(10,0.5).data
C = A.tocsr(1)
D = B.tocsr(1)
ans1 = B*A
ans2 = D*C
ans2.sort_indices()
x = np.all(ans1.data == ans2.data)
y = np.all(ans1.indices == ans2.indices)
z = np.all(ans1.indptr == ans2.indptr)
assert_(x*y*z)
for k in range(50):
A = rand_ket(10,0.5).data
B = rand_ket(10,0.5).dag().data
C = A.tocsr(1)
D = B.tocsr(1)
ans1 = B*A
ans2 = D*C
ans2.sort_indices()
x = np.all(ans1.data == ans2.data)
y = np.all(ans1.indices == ans2.indices)
z = np.all(ans1.indptr == ans2.indptr)
assert_(x*y*z)
ans1 = A*B
ans2 = C*D
ans2.sort_indices()
x = np.all(ans1.data == ans2.data)
y = np.all(ans1.indices == ans2.indices)
z = np.all(ans1.indptr == ans2.indptr)
assert_(x*y*z)
for k in range(50):
A = rand_dm(10,0.5).data
B = rand_dm(10,0.5).data
C = A.tocsr(1)
D = B.tocsr(1)
ans1 = B*A
ans2 = D*C
ans2.sort_indices()
x = np.all(ans1.data == ans2.data)
y = np.all(ans1.indices == ans2.indices)
z = np.all(ans1.indptr == ans2.indptr)
assert_(x*y*z)
for k in range(50):
A = rand_dm(10,0.5).data
B = rand_herm(10,0.5).data
C = A.tocsr(1)
D = B.tocsr(1)
ans1 = B*A
ans2 = D*C
ans2.sort_indices()
x = np.all(ans1.data == ans2.data)
y = np.all(ans1.indices == ans2.indices)
z = np.all(ans1.indptr == ans2.indptr)
assert_(x*y*z)
开发者ID:NunoEdgarGub1,项目名称:qutip,代码行数:69,代码来源:test_spmath.py
示例20: rand_super
def rand_super():
h_5 = rand_herm(5)
return propagator(h_5, scipy.rand(), [
create(5), destroy(5), jmat(2, 'z')
])
开发者ID:QuantumLambda,项目名称:qutip,代码行数:5,代码来源:test_metrics.py
注:本文中的qutip.random_objects.rand_herm函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论