Skip to content

Commit cd247d8

Browse files
authored
declare identitysuperoperator (#16)
1 parent e73f39a commit cd247d8

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# News
22

3+
## v0.3.1
4+
5+
- `identitysuperoperator` declared.
6+
37
## v0.3.0
48

59
- Redo some of the `identityoperator` methods.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuantumInterface"
22
uuid = "5717a53b-5d69-4fa3-b976-0bf2f97ca1e5"
33
authors = ["QuantumInterface.jl contributors"]
4-
version = "0.3.0"
4+
version = "0.3.1"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/identityoperator.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ identityoperator(op::T) where {T<:AbstractOperator} = identityoperator(T, op.bas
2020
identityoperator(::Type{T}, ::Type{Any}, b1::Basis, b2::Basis) where T<:AbstractOperator = identityoperator(T, ComplexF64, b1, b2)
2121

2222
identityoperator(b1::Basis, b2::Basis) = identityoperator(ComplexF64, b1, b2)
23+
24+
"""Prepare the identity superoperator over a given space."""
25+
function identitysuperoperator end

src/sparse.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,27 @@ Convert an arbitrary operator into a [`SparseOperator`](@ref).
99
"""
1010
sparse(a::AbstractOperator) = throw(ArgumentError("Direct conversion from $(typeof(a)) not implemented. Use sparse(full(op)) from QuantumOptics instead."))
1111

12-
function ptrace(x::AbstractSparseMatrix, shape_nd, indices)
12+
function ptrace(x::AbstractSparseMatrix, shape_nd, indices) # A fairly QuantumOptics-specific method, left here to avoid piracy
1313
shape_nd = (shape_nd...,)
1414
N = div(length(shape_nd), 2)
1515
shape_2d = (x.m, x.n)
1616
shape_nd_after = ([i indices || i-N indices ? 1 : shape_nd[i] for i=1:2*N]...,)
1717
shape_2d_after = (prod(shape_nd_after[1:N]), prod(shape_nd_after[N+1:end]))
1818
I_nd_after_max = CartesianIndex(shape_nd_after...)
1919
y = spzeros(eltype(x), shape_2d_after...)
20-
for I in eachindex(x)
21-
I_nd = sub2sub(shape_2d, shape_nd, I)
20+
for I in eachindex(x)::CartesianIndices # Manual type assertions to help JET
21+
println(I.I)
22+
I_nd = sub2sub(shape_2d, shape_nd, I)::CartesianIndex
2223
if I_nd.I[indices] != I_nd.I[indices .+ N]
2324
continue
2425
end
25-
I_after = sub2sub(shape_nd_after, shape_2d_after, min(I_nd, I_nd_after_max))
26+
I_after = sub2sub(shape_nd_after, shape_2d_after, min(I_nd, I_nd_after_max)::CartesianIndex)
2627
y[I_after] += x[I]
2728
end
2829
y
2930
end
3031

31-
function sub2sub(shape1, shape2, I)
32+
function sub2sub(shape1, shape2, I::CartesianIndex)::CartesianIndex # Manual type assertions to help JET
3233
linearindex = LinearIndices(shape1)[I.I...]
3334
CartesianIndices(shape2)[linearindex]
3435
end

test/test_jet.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using QuantumInterface
2+
using Test
23
using JET
34

45
using JET: ReportPass, BasicPass, InferenceErrorReport, UncaughtExceptionReport, MethodErrorReport

0 commit comments

Comments
 (0)