Skip to content

Commit 992ebba

Browse files
authored
Fix embed method for operators acting on different bases (#27)
* Fix embed method for operators acting on different bases * Update Project.toml
1 parent 016ae40 commit 992ebba

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "QuantumOpticsBase"
22
uuid = "4f57444f-1401-5e15-980d-4471b28d5678"
3-
version = "v0.2.10"
3+
version = "v0.2.11"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/operators.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,6 @@ function embed(basis_l::CompositeBasis, basis_r::CompositeBasis,
139139
# Create the operator.
140140
permuted_op = tensor(all_operators...)
141141

142-
# Create a copy to fill with correctly-ordered objects (basis and data).
143-
unpermuted_op = copy(permuted_op)
144-
145-
# Create the correctly ordered basis.
146-
unpermuted_op.basis_l = basis_l
147-
unpermuted_op.basis_r = basis_r
148-
149142
# Reorient the matrix to act in the correctly ordered basis.
150143
# Get the dimensions necessary for index permuting.
151144
dims_l = [b.shape[1] for b in basis_l.bases]
@@ -167,7 +160,9 @@ function embed(basis_l::CompositeBasis, basis_r::CompositeBasis,
167160
x -> permutedims(x, [perm_order_l; perm_order_r .+ length(dims_l)]) |>
168161
x -> sparse(reshape(x, (prod(dims_l), prod(dims_r)))))
169162

170-
unpermuted_op.data = M
163+
# Create operator with proper data and bases
164+
constructor = Base.typename(T)
165+
unpermuted_op = constructor.wrapper(basis_l, basis_r, M)
171166

172167
return unpermuted_op
173168
end

test/test_operators.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,13 @@ OP_cnot = embed(b8, [1,3], op_cnot)
118118

119119
@test_throws ArgumentError conj!(op_test)
120120

121+
bfock = FockBasis(2)
122+
bspin = SpinBasis(1//2)
123+
b = bfockbspinbspin
124+
125+
op12 = destroy(bfock)sigmap(bspin)
126+
127+
@test embed(b, [1,2], op12) == destroy(bfock)sigmap(bspin)one(bspin)
128+
@test embed(b, [1,3], op12) == destroy(bfock)one(bspin)sigmap(bspin)
129+
121130
end # testset

0 commit comments

Comments
 (0)