Skip to content

Commit 0d68b84

Browse files
akirakyleKrastanov
andauthored
Add identitysuperoperator and dagger for SuperOperator (#116)
* Add identitysuperoperator and dagger for SuperOperator * import identitysuperoperator from QuantumInterface * Add identitysuperoperator(b::Basis) and some tests * whitelisth a pirate (identitysuperoperator) --------- Co-authored-by: Stefan Krastanov <[email protected]> Co-authored-by: Stefan Krastanov <[email protected]>
1 parent d04256d commit 0d68b84

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/QuantumOpticsBase.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module QuantumOpticsBase
33
using SparseArrays, LinearAlgebra, LRUCache, Strided, UnsafeArrays, FillArrays
44
import LinearAlgebra: mul!, rmul!
55

6-
import QuantumInterface: dagger, directsum, , dm, embed, expect, identityoperator,
6+
import QuantumInterface: dagger, directsum, , dm, embed, expect, identityoperator, identitysuperoperator,
77
permutesystems, projector, ptrace, reduced, tensor, , variance, apply!, basis, AbstractSuperOperator
88

99
# index helpers
@@ -34,6 +34,7 @@ export Basis, GenericBasis, CompositeBasis, basis,
3434
#superoperators
3535
SuperOperator, DenseSuperOperator, DenseSuperOpType,
3636
SparseSuperOperator, SparseSuperOpType, spre, spost, sprepost, liouvillian,
37+
identitysuperoperator,
3738
#fock
3839
FockBasis, number, destroy, create,
3940
fockstate, coherentstate, coherentstate!,

src/superoperators.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ end
9797
-(a::SuperOperator) = SuperOperator(a.basis_l, a.basis_r, -a.data)
9898
-(a::SuperOperator, b::SuperOperator) = throw(IncompatibleBases())
9999

100+
identitysuperoperator(b::Basis) =
101+
SuperOperator((b,b), (b,b), Eye{ComplexF64}(length(b)^2))
102+
103+
identitysuperoperator(op::DenseSuperOpType) =
104+
SuperOperator(op.basis_l, op.basis_r, Matrix(one(eltype(op.data))I, size(op.data)))
105+
106+
identitysuperoperator(op::SparseSuperOpType) =
107+
SuperOperator(op.basis_l, op.basis_r, sparse(one(eltype(op.data))I, size(op.data)))
108+
109+
dagger(x::DenseSuperOpType) = SuperOperator(x.basis_r, x.basis_l, copy(adjoint(x.data)))
110+
dagger(x::SparseSuperOpType) = SuperOperator(x.basis_r, x.basis_l, sparse(adjoint(x.data)))
111+
112+
100113
"""
101114
spre(op)
102115

test/test_aqua.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ using FillArrays
99
piracy=(broken=true,)
1010
)
1111
# manual piracy check to exclude identityoperator
12-
pirates = [pirate for pirate in Aqua.Piracy.hunt(QuantumOpticsBase) if pirate.name != :identityoperator]
12+
pirates = [pirate for pirate in Aqua.Piracy.hunt(QuantumOpticsBase) if pirate.name [:identityoperator,:identitysuperoperator]]
1313
@test isempty(pirates)
1414
end # testset

test/test_superoperators.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ x = -s1
120120
@test x.basis_l == (b1, b2)
121121
@test x.basis_r == (b3, b4)
122122

123-
124123
# TODO: Clean-up this part
125124
ωc = 1.2
126125
ωa = 0.9
@@ -153,6 +152,9 @@ J = [Ja, Jc]
153152
Ψ₀ = spinup(spinbasis) fockstate(fockbasis, 5)
154153
ρ₀ = dm(Ψ₀)
155154

155+
@test identitysuperoperator(spinbasis)*sx == sx
156+
@test identitysuperoperator(sparse(spre(sx)))*sx == sparse(sx)
157+
@test identitysuperoperator(dense(spre(sx)))*sx == dense(sx)
156158

157159
op1 = DenseOperator(spinbasis, [1.2+0.3im 0.7+1.2im;0.3+0.1im 0.8+3.2im])
158160
op2 = DenseOperator(spinbasis, [0.2+0.1im 0.1+2.3im; 0.8+4.0im 0.3+1.4im])
@@ -161,6 +163,8 @@ op2 = DenseOperator(spinbasis, [0.2+0.1im 0.1+2.3im; 0.8+4.0im 0.3+1.4im])
161163

162164
@test spre(sparse(op1))*op2 == op1*op2
163165
@test spost(sparse(op1))*op2 == op2*op1
166+
@test spre(sparse(dagger(op1)))*op2 == dagger(op1)*op2
167+
@test spre(dense(dagger(op1)))*op2 dagger(op1)*op2
164168
@test sprepost(sparse(op1), op1)*op2 op1*op2*op1
165169

166170
@test spre(sparse(op1))*sparse(op2) == sparse(op1*op2)

0 commit comments

Comments
 (0)