Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# News

## v1.0.0

- First release, implementing necessary changes to be compatible with the breaking release of `QuantumInterface` 0.4.0.

4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "QuantumOpticsBase"
uuid = "4f57444f-1401-5e15-980d-4471b28d5678"
version = "0.5.7"
version = "1.0.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand All @@ -25,7 +25,7 @@ FastGaussQuadrature = "0.5, 1"
FillArrays = "0.13, 1"
LRUCache = "1"
LinearAlgebra = "1"
QuantumInterface = "0.3.9"
QuantumInterface = "0.4.0"
Random = "1"
RecursiveArrayTools = "3"
SparseArrays = "1"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ QuantumOpticsBase.check_samebases
```

```@docs
@samebases
@compatiblebases
```

```@docs
Expand Down
23 changes: 13 additions & 10 deletions src/QuantumOpticsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ using SparseArrays, LinearAlgebra, LRUCache, Strided, UnsafeArrays, FillArrays
import LinearAlgebra: mul!, rmul!
import RecursiveArrayTools

import QuantumInterface: dagger, directsum, ⊕, dm, embed, nsubsystems, expect, identityoperator, identitysuperoperator,
permutesystems, projector, ptrace, reduced, tensor, ⊗, variance, apply!, basis, AbstractSuperOperator
import QuantumInterface: Basis, GenericBasis, CompositeBasis, basis, basis_l, basis_r, dimension, shape,
IncompatibleBases, @compatiblebases, samebases, check_samebases,
addible, check_addible, multiplicable, check_multiplicable, reduced, ptrace, permutesystems,
dagger, directsum, ⊕, dm, embed, expect, identityoperator, identitysuperoperator,
permutesystems, projector, ptrace, reduced, tensor, tensor_pow, ⊗, variance, apply!,
vec, unvec, super, choi, kraus, stinespring, pauli, chi, spre, spost, sprepost, liouvillian

# metrics
import QuantumInterface: entropy_vn, fidelity, logarithmic_negativity

# index helpers
import QuantumInterface: complement, remove, shiftremove, reducedindices!, check_indices, check_sortedindices, check_embed_indices

export Basis, GenericBasis, CompositeBasis, basis,
tensor, ⊗, permutesystems, @samebases,
export Basis, GenericBasis, CompositeBasis, basis, basis_l, basis_r, dimension, shape,
tensor, tensor_pow, ⊗, permutesystems, @compatiblebases,
#states
StateVector, Bra, Ket, basisstate, sparsebasisstate, norm,
dagger, normalize, normalize!,
Expand All @@ -38,9 +42,10 @@ export Basis, GenericBasis, CompositeBasis, basis,
AbstractTimeDependentOperator, TimeDependentSum, set_time!,
current_time, time_shift, time_stretch, time_restrict, static_operator,
#superoperators
SuperOperator, DenseSuperOperator, DenseSuperOpType,
SparseSuperOperator, SparseSuperOpType, spre, spost, sprepost, liouvillian,
identitysuperoperator,
KetBraBasis, ChoiBasis, PauliBasis, ChiBasis,
vec, unvec, super, choi, kraus, stinespring, pauli, chi,
spre, spost, sprepost, liouvillian, identitysuperoperator,
SuperOperatorType, ChoiStateType, PauliTransferType, ChiType,
#fock
FockBasis, number, destroy, create,
fockstate, coherentstate, coherentstate!,
Expand All @@ -67,14 +72,12 @@ export Basis, GenericBasis, CompositeBasis, basis,
tracedistance, tracedistance_h, tracedistance_nh,
entropy_vn, entropy_renyi, fidelity, ptranspose, PPT,
negativity, logarithmic_negativity, entanglement_entropy,
PauliBasis, PauliTransferMatrix, DensePauliTransferMatrix,
ChiMatrix, DenseChiMatrix, avg_gate_fidelity,
avg_gate_fidelity,
SumBasis, directsum, ⊕, LazyDirectSum, getblock, setblock!,
qfunc, wigner, coherentspinstate, qfuncsu2, wignersu2
#apply
apply!

include("bases.jl")
include("states.jl")
include("operators.jl")
include("operators_dense.jl")
Expand Down
11 changes: 6 additions & 5 deletions src/apply.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function is_apply_shortcircuit(state, indices, operation)
if nsubsystems(state) == 1
if length(basis(state)) == 1
basis(state)==basis(operation) || throw(ArgumentError("`apply!` failed due to incompatible bases of the state and the operation attempted to be applied on it"))
end
basis(state)==basis(operation) || return false
Expand All @@ -23,13 +23,14 @@ function apply!(state::Operator, indices, operation::Operator)
state
end

function apply!(state::Ket, indices, operation::T) where {T<:AbstractSuperOperator}
function apply!(state::Ket, indices, operation::SuperOperatorType)
apply!(dm(state), indices, operation)
end

function apply!(state::Operator, indices, operation::T) where {T<:AbstractSuperOperator}
if is_apply_shortcircuit(state, indices, operation)
state.data = (operation*state).data
function apply!(state::Operator, indices, operation::SuperOperatorType)
vecd = vec(state)
if is_apply_shortcircuit(vecd, indices, operation)
state.data = unvec(operation*vecd).data
return state
else
error("`apply!` does not yet support embedding superoperators acting only on a subsystem of the given state")
Expand Down
3 changes: 0 additions & 3 deletions src/bases.jl

This file was deleted.

2 changes: 2 additions & 0 deletions src/charge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct ChargeBasis{T} <: Basis
end

Base.:(==)(b1::ChargeBasis, b2::ChargeBasis) = (b1.ncut == b2.ncut)
dimension(b::ChargeBasis) = b.dim

"""
ShiftedChargeBasis(nmin, nmax) <: Basis
Expand All @@ -50,6 +51,7 @@ end

Base.:(==)(b1::ShiftedChargeBasis, b2::ShiftedChargeBasis) =
(b1.nmin == b2.nmin && b1.nmax == b2.nmax)
dimension(b::ShiftedChargeBasis) = b.dim

"""
chargestate([T=ComplexF64,] b::ChargeBasis, n)
Expand Down
24 changes: 13 additions & 11 deletions src/manybody.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ end
ManyBodyBasis(onebodybasis::B, occupations::O) where {B,O} = ManyBodyBasis{B,O}(onebodybasis, occupations)
ManyBodyBasis(onebodybasis::B, occupations::Vector{T}) where {B,T} = ManyBodyBasis(onebodybasis, SortedVector(occupations))

==(b1::ManyBodyBasis, b2::ManyBodyBasis) = b1.occupations_hash == b2.occupations_hash && b1.onebodybasis == b2.onebodybasis
dimension(b::ManyBodyBasis) = length(b.occupations)


allocate_buffer(occ) = similar(occ)
allocate_buffer(mb::ManyBodyBasis) = allocate_buffer(first(mb.occupations))

Expand All @@ -68,7 +72,7 @@ function fermionstates(T::Type, Nmodes::Int, Nparticles::Int)
SortedVector(_distribute_fermions(Nparticles, Nmodes, 1, occ_buffer, OT[]), Base.Reverse)
end
fermionstates(T::Type, Nmodes::Int, Nparticles::Vector{Int}) = union((fermionstates(T, Nmodes, N) for N in Nparticles)...)
fermionstates(T::Type, onebodybasis::Basis, Nparticles) = fermionstates(T, length(onebodybasis), Nparticles)
fermionstates(T::Type, onebodybasis::Basis, Nparticles) = fermionstates(T, dimension(onebodybasis), Nparticles)
fermionstates(arg1, arg2) = fermionstates(OccupationNumbers{FermionStatistics,Int}, arg1, arg2)

"""
Expand All @@ -86,11 +90,9 @@ function bosonstates(T::Type, Nmodes::Int, Nparticles::Int)
SortedVector(_distribute_bosons(Nparticles, Nmodes, 1, occ_buffer, OT[]), Base.Reverse)
end
bosonstates(T::Type, Nmodes::Int, Nparticles::Vector{Int}) = union((bosonstates(T, Nmodes, N) for N in Nparticles)...)
bosonstates(T::Type, onebodybasis::Basis, Nparticles) = bosonstates(T, length(onebodybasis), Nparticles)
bosonstates(T::Type, onebodybasis::Basis, Nparticles) = bosonstates(T, dimension(onebodybasis), Nparticles)
bosonstates(arg1, arg2) = bosonstates(OccupationNumbers{BosonStatistics,Int}, arg1, arg2)

==(b1::ManyBodyBasis, b2::ManyBodyBasis) = b1.occupations_hash == b2.occupations_hash && b1.onebodybasis == b2.onebodybasis

"""
basisstate([T=ComplexF64,] mb::ManyBodyBasis, occupation::Vector)

Expand Down Expand Up @@ -164,7 +166,7 @@ function transition(::Type{T}, mb::ManyBodyBasis, to, from) where {T}
push!(Js, i)
push!(Vs, C)
end
return SparseOperator(mb, sparse(Is, Js, Vs, length(mb), length(mb)))
return SparseOperator(mb, sparse(Is, Js, Vs, dimension(mb), dimension(mb)))
end
transition(mb::ManyBodyBasis, to, from) = transition(ComplexF64, mb, to, from)

Expand Down Expand Up @@ -207,7 +209,7 @@ function manybodyoperator(mb::ManyBodyBasis, op)
end

function manybodyoperator_1(mb::ManyBodyBasis, op::Operator)
S = length(mb.onebodybasis)
S = dimension(mb.onebodybasis)
result = DenseOperator(mb)
buffer = allocate_buffer(mb)
@inbounds for j = 1:S, i = 1:S
Expand All @@ -226,7 +228,7 @@ end
manybodyoperator_1(mb::ManyBodyBasis, op::AdjointOperator) = dagger(manybodyoperator_1(mb, dagger(op)))

function manybodyoperator_1(mb::ManyBodyBasis, op::SparseOpPureType)
N = length(mb)
N = dimension(mb)
Is = Int[]
Js = Int[]
Vs = ComplexF64[]
Expand All @@ -246,7 +248,7 @@ function manybodyoperator_1(mb::ManyBodyBasis, op::SparseOpPureType)
end

function manybodyoperator_2(mb::ManyBodyBasis, op::Operator)
S = length(mb.onebodybasis)
S = dimension(mb.onebodybasis)
result = DenseOperator(mb)
op_data = reshape(op.data, S, S, S, S)
buffer = allocate_buffer(mb)
Expand All @@ -265,8 +267,8 @@ function manybodyoperator_2(mb::ManyBodyBasis, op::Operator)
end

function manybodyoperator_2(mb::ManyBodyBasis, op::SparseOpType)
N = length(mb)
S = length(mb.onebodybasis)
N = dimension(mb)
S = dimension(mb.onebodybasis)
Is = Int[]
Js = Int[]
Vs = ComplexF64[]
Expand Down Expand Up @@ -314,7 +316,7 @@ matrix_element(state::Operator, m, n) = state.data[n, m]
function onebodyexpect_1(op::Operator, state)
mb = basis(state)
occupations = mb.occupations
S = length(mb.onebodybasis)
S = dimension(mb.onebodybasis)
buffer = allocate_buffer(mb)
result = complex(0.0)
for i = 1:S, j = 1:S
Expand Down
Loading
Loading