Skip to content
Permalink
Browse files

Clean up source code.

* Order: export, import, using
* Functions in file and exported name in same order.
* More consistent use of white spaces.
* Use qualifier when adding imported methods.
  • Loading branch information
bastikr committed Jun 25, 2017
1 parent e80c032 commit 2b11793346966e89c3a97daa9c98ede864cec6c9
@@ -1,14 +1,14 @@
module bases

using Compat
import Base.==

export Basis, GenericBasis, CompositeBasis, basis,
tensor, ⊗, ptrace, permutesystems,
IncompatibleBases,
samebases, multiplicable,
check_samebases, check_multiplicable

import Base: ==

using Compat

"""
Abstract base class for all specialized bases.
@@ -26,6 +26,26 @@ class.
@compat abstract type Basis end


==(b1::Basis, b2::Basis) = false

"""
length(b::Basis)
Total dimension of the Hilbert space.
"""
Base.length(b::Basis) = prod(b.shape)

"""
basis(a)
Return the basis of an object.
If it's ambiguous, e.g. if an operator has a different left and right basis,
an [`IncompatibleBases`](@ref) error is thrown.
"""
function basis end


"""
GenericBasis(N)
@@ -41,6 +61,8 @@ end

GenericBasis(N::Int) = GenericBasis(Int[N])

==(b1::GenericBasis, b2::GenericBasis) = equal_shape(b1.shape, b2.shape)


"""
CompositeBasis(b1, b2...)
@@ -58,6 +80,8 @@ end
CompositeBasis(bases::Vector{Basis}) = CompositeBasis(Int[prod(b.shape) for b in bases], bases)
CompositeBasis(bases::Basis...) = CompositeBasis(Basis[bases...])

==(b1::CompositeBasis, b2::CompositeBasis) = equal_shape(b1.shape, b2.shape) && equal_bases(b1.bases, b2.bases)

"""
tensor(x, y, z...)
@@ -104,13 +128,6 @@ end
tensor(bases::Basis...) = reduce(tensor, bases)
⊗(a,b) = tensor(a,b)

"""
length(b::Basis)
Total dimension of the Hilbert space.
"""
Base.length(b::Basis) = prod(b.shape)

"""
equal_shape(a, b)
@@ -131,7 +148,6 @@ function equal_shape(a::Vector{Int}, b::Vector{Int})
return true
end


"""
equal_bases(a, b)
@@ -149,12 +165,6 @@ function equal_bases(a::Vector{Basis}, b::Vector{Basis})
return true
end


==(b1::Basis, b2::Basis) = false
==(b1::GenericBasis, b2::GenericBasis) = equal_shape(b1.shape,b2.shape)
==(b1::CompositeBasis, b2::CompositeBasis) = equal_shape(b1.shape,b2.shape) && equal_bases(b1.bases,b2.bases)


"""
Exception that should be raised for an illegal algebraic operation.
"""
@@ -211,16 +221,6 @@ function check_multiplicable(b1, b2)
end
end

"""
basis(a)
Return the basis of an object.
If it's ambiguous, e.g. if an operator has a different left and right basis,
an [`IncompatibleBases`](@ref) error is thrown.
"""
function basis end


"""
ptrace(a, indices)
@@ -1,10 +1,10 @@
module fock

import Base.==
export FockBasis, number, destroy, create, displace, fockstate, coherentstate

using ..bases, ..states, ..operators, ..operators_dense, ..operators_sparse
import Base: ==

export FockBasis, number, destroy, create, displace, fockstate, coherentstate
using ..bases, ..states, ..operators, ..operators_dense, ..operators_sparse


"""
@@ -3,7 +3,7 @@ module manybody
export ManyBodyBasis, fermionstates, bosonstates,
manybodyoperator, onebodyexpect, occupation

import Base.==
import Base: ==
import ..states: basisstate
import ..fock: number, create, destroy
import ..nlevel: transition
@@ -3,11 +3,10 @@ module timeevolution_master
export master, master_nh, master_h, master_dynamic, master_nh_dynamic

import ..integrate, ..recast!
using ...bases
using ...states
using ...operators
using ...operators_dense
using ...operators_sparse

using ...bases, ...states, ...operators
using ...operators_dense, ...operators_sparse


const DecayRates = Union{Vector{Float64}, Matrix{Float64}, Void}

@@ -2,10 +2,8 @@ module timeevolution_mcwf

export mcwf, mcwf_h, mcwf_nh, diagonaljumps

using ...bases
using ...states
using ...operators
using ...ode_dopri
using ...bases, ...states, ...operators, ...ode_dopri


"""
integrate_mcwf(dmcwf, jumpfun, tspan, psi0, seed; fout, kwargs...)
@@ -1,10 +1,11 @@
module metrics

using ..bases, ..operators, ..operators_dense

export tracedistance, tracedistance_general, tracenorm, tracenorm_general,
entropy_vn, fidelity

using ..bases, ..operators, ..operators_dense


"""
tracenorm(rho)
@@ -1,10 +1,11 @@
module nlevel

import Base.==
export NLevelBasis, transition, nlevelstate

import Base: ==

using ..bases, ..states, ..operators, ..operators_sparse

export NLevelBasis, transition, nlevelstate

"""
NLevelBasis(N)
@@ -4,6 +4,7 @@ export ode, ode_event

using Roots


const order = 5

# Runge-Kutta table

0 comments on commit 2b11793

Please sign in to comment.
You can’t perform that action at this time.