From e3d625202ae15f00e9664e4f79916ecef77e4aee Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Mon, 10 Apr 2017 00:59:03 +0530 Subject: [PATCH 01/13] Skinned update to v0.6 --- src/innerexpr.jl | 10 +++++----- src/labels.jl | 14 +++++++------- src/mapfuncs.jl | 34 +++++++++++++++++----------------- src/opsum.jl | 34 ++++++++++++++++++++-------------- src/outerproduct.jl | 5 ++++- src/state.jl | 23 +++++++++++++---------- src/str_macros.jl | 4 ++-- 7 files changed, 68 insertions(+), 56 deletions(-) diff --git a/src/innerexpr.jl b/src/innerexpr.jl index 799633f..7a4ad58 100644 --- a/src/innerexpr.jl +++ b/src/innerexpr.jl @@ -17,7 +17,7 @@ Base.(:(==))(::InnerProduct, ::Number) = false Base.(:(==))(::Number, ::InnerProduct) = false Base.hash(i::InnerProduct) = hash(blabel(i), hash(klabel(i))) -Base.hash(i::InnerProduct, h::Uint64) = hash(hash(i), h) +Base.hash(i::InnerProduct, h::UInt64) = hash(hash(i), h) Base.conj(i::InnerProduct) = InnerProduct(klabel(i), blabel(i)) @@ -75,7 +75,7 @@ same_num(iex::InnerExpr, n::Number) = iex == InnerExpr(n) same_num(n::Number, iex::InnerExpr) = iex == n Base.hash(iex::InnerExpr) = hash(iex.ex) -Base.hash(iex::InnerExpr, h::Uint64) = hash(hash(iex), h) +Base.hash(iex::InnerExpr, h::UInt64) = hash(hash(iex), h) Base.one(::InnerExpr) = InnerExpr(1) Base.zero(::InnerExpr) = InnerExpr(0) @@ -127,7 +127,7 @@ Base.(:^)(a::InnerExpr, b::Integer) = iexpr_exp(a, b) Base.(:^)(a::InnerExpr, b::Rational) = iexpr_exp(a, b) Base.(:^)(a::InnerExpr, b::InnerExpr) = iexpr_exp(a, b) Base.(:^)(a::InnerExpr, b::Number) = iexpr_exp(a, b) -Base.(:^)(a::MathConst{:e}, b::InnerExpr) = iexpr_exp(a, b) +#Base.(:^)(a::MathConst{:e}, b::InnerExpr) = iexpr_exp(a, b) Base.(:^)(a::Number, b::InnerExpr) = iexpr_exp(a, b) Base.exp(iex::InnerExpr) = InnerExpr(:(exp($(iex)))) @@ -136,7 +136,7 @@ Base.exp2(iex::InnerExpr) = InnerExpr(:(exp2($(iex)))) Base.sqrt(iex::InnerExpr) = InnerExpr(:(sqrt($(iex)))) Base.log(iex::InnerExpr) = length(iex)==2 && iex[1]==:exp ? iex[2] : InnerExpr(:(log($(iex)))) -Base.log(a::MathConst{:e}, b::InnerExpr) = InnerExpr(:(log($(a),$(b)))) +#Base.log(a::MathConst{:e}, b::InnerExpr) = InnerExpr(:(log($(a),$(b)))) Base.log(a::InnerExpr, b::InnerExpr) = InnerExpr(:(log($(a),$(b)))) Base.log(a::InnerExpr, b::Number) = InnerExpr(:(log($(a),$(b)))) Base.log(a::Number, b::InnerExpr) = InnerExpr(:(log($(a),$(b)))) @@ -239,7 +239,7 @@ Base.ctranspose(iex::InnerExpr) = conj(iex) # Elementwise Operations # ########################## for op=(:*,:-,:+,:/,:^) - elop = symbol(string(:.) * string(op)) + elop = Symbol(string(:.) * string(op)) @eval begin ($elop)(a::InnerExpr, b::InnerExpr) = ($op)(a,b) ($elop)(a::InnerExpr, b::Number) = ($op)(a,b) diff --git a/src/labels.jl b/src/labels.jl index aae96e9..c849cf6 100644 --- a/src/labels.jl +++ b/src/labels.jl @@ -3,9 +3,9 @@ ############## immutable StateLabel{N} label::NTuple{N} - hash::Uint64 + hash::UInt64 StateLabel(label::NTuple{N}) = new(label, hash(label)) - StateLabel(label::NTuple{N}, h::Uint64) = new(label, h) + StateLabel(label::NTuple{N}, h::UInt64) = new(label, h) end StateLabel(s::StateLabel) = s @@ -18,7 +18,7 @@ Base.getindex(s::StateLabel, arr::AbstractArray) = s.label[arr] Base.copy{N}(s::StateLabel{N}) = StateLabel{N}(s.label, s.hash) Base.hash(s::StateLabel) = s.hash -Base.hash(s::StateLabel, h::Uint64) = hash(hash(s), h) +Base.hash(s::StateLabel, h::UInt64) = hash(hash(s), h) Base.(:(==)){N}(a::StateLabel{N},b::StateLabel{N}) = hash(a) == hash(b) @@ -32,7 +32,7 @@ Base.endof(s::StateLabel) = endof(s.label) Base.length{N}(::StateLabel{N}) = N -Base.map(f::Union(Function,DataType), s::StateLabel) = StateLabel(map(f, s.label)) +#Base.map(f::Union(Function,DataType), s::StateLabel) = StateLabel(map(f, s.label)) tensor(a::StateLabel, b::StateLabel) = StateLabel(tuple(a.label..., b.label...)) @@ -46,9 +46,9 @@ Base.show(io::IO, s::StateLabel) = print(io, repr(s)) immutable OpLabel{N} k::StateLabel{N} b::StateLabel{N} - hash::Uint64 + hash::UInt64 OpLabel(k::StateLabel{N}, b::StateLabel{N}) = new(k, b, hash(k, hash(b))) - OpLabel(k::StateLabel{N}, b::StateLabel{N}, h::Uint64) = new(k, b, h) + OpLabel(k::StateLabel{N}, b::StateLabel{N}, h::UInt64) = new(k, b, h) end OpLabel(op::OpLabel) = op @@ -61,7 +61,7 @@ blabel(o::OpLabel) = o.b Base.copy{N}(o::OpLabel{N}) = OpLabel{N}(o.k, o.b, o.hash) Base.hash(o::OpLabel) = o.hash -Base.hash(o::OpLabel, h::Uint64) = hash(hash(o), h) +Base.hash(o::OpLabel, h::UInt64) = hash(hash(o), h) Base.(:(==)){N}(a::OpLabel{N}, b::OpLabel{N}) = hash(a) == hash(b) diff --git a/src/mapfuncs.jl b/src/mapfuncs.jl index 226670b..91b5693 100644 --- a/src/mapfuncs.jl +++ b/src/mapfuncs.jl @@ -29,32 +29,32 @@ Base.filter(f::Function, op::OuterProduct) = filter(f, convert(OpSum, op)) ######################## # mapcoeffs!/mapcoeffs # ######################## -mapcoeffs!(f::Union(Function,DataType), k::Ket) = (mapvals!(f, dict(k)); return k) -mapcoeffs!(f::Union(Function,DataType), b::Bra) = (mapvals!(v->f(v')', dict(b)); return b) -mapcoeffs!(f::Union(Function,DataType), op::OpSum) = (mapvals!(f, dict(op)); return op) -mapcoeffs!(f::Union(Function,DataType), opc::DualOpSum) = (mapvals!(v->f(v')', dict(opc)); return opc) +mapcoeffs!(f::Function, k::Ket) = (mapvals!(f, dict(k)); return k) +mapcoeffs!(f::Function, b::Bra) = (mapvals!(v->f(v')', dict(b)); return b) +mapcoeffs!(f::Function, op::OpSum) = (mapvals!(f, dict(op)); return op) +mapcoeffs!(f::Function, opc::DualOpSum) = (mapvals!(v->f(v')', dict(opc)); return opc) -mapcoeffs(f::Union(Function,DataType), kt::Ket) = similar(kt, mapvals(f, dict(kt))) -mapcoeffs(f::Union(Function,DataType), br::Bra) = similar(br, mapvals(v->f(v')', dict(br))) -mapcoeffs(f::Union(Function,DataType), op::OpSum) = similar(op, mapvals(f, dict(op))) -mapcoeffs(f::Union(Function,DataType), opc::DualOpSum) = similar(opc, mapvals(v->f(v')', dict(opc))) -mapcoeffs(f::Union(Function,DataType), op::OuterProduct) = mapcoeffs(f, convert(OpSum, op)) +mapcoeffs(f::Function, kt::Ket) = similar(kt, mapvals(f, dict(kt))) +mapcoeffs(f::Function, br::Bra) = similar(br, mapvals(v->f(v')', dict(br))) +mapcoeffs(f::Function, op::OpSum) = similar(op, mapvals(f, dict(op))) +mapcoeffs(f::Function, opc::DualOpSum) = similar(opc, mapvals(v->f(v')', dict(opc))) +mapcoeffs(f::Function, op::OuterProduct) = mapcoeffs(f, convert(OpSum, op)) ######################## # maplabels!/maplabels # ######################## -maplabels(f::Union(Function,DataType), s::DiracState) = similar(s, mapkeys(f, dict(s))) -maplabels(f::Union(Function,DataType), op::OpSum) = similar(op, mapkeys(f, dict(op))) -maplabels(f::Union(Function,DataType), opc::DualOpSum) = OpSum(ptype(opc), mapkeys(label->f(label'), dict(op))) -maplabels(f::Union(Function,DataType), op::OuterProduct) = maplabels(f, convert(OpSum, op)) +maplabels(f::Function, s::DiracState) = similar(s, mapkeys(f, dict(s))) +maplabels(f::Function, op::OpSum) = similar(op, mapkeys(f, dict(op))) +maplabels(f::Function, opc::DualOpSum) = OpSum(ptype(opc), mapkeys(label->f(label'), dict(op))) +maplabels(f::Function, op::OuterProduct) = maplabels(f, convert(OpSum, op)) ####### # map # ####### -Base.map(f::Union(Function,DataType), obj::AbstractDirac) = similar(obj, mapkv(kv->f(kv[1], kv[2]), dict(obj))) -Base.map(f::Union(Function,DataType), br::Bra) = similar(br, mapkv(kv->br_tup(f(kv[1], kv[2]')), dict(d))) -Base.map(f::Union(Function,DataType), opc::DualOpSum) = OpSum(ptype(opc), mapkv(kv->f(kv[1]', kv[2]'), dict(d))) -Base.map(f::Union(Function,DataType), op::OuterProduct) = map(f, convert(OpSum, op)) +Base.map(f::Function, obj::AbstractDirac) = similar(obj, mapkv(kv->f(kv[1], kv[2]), dict(obj))) +Base.map(f::Function, br::Bra) = similar(br, mapkv(kv->br_tup(f(kv[1], kv[2]')), dict(d))) +Base.map(f::Function, opc::DualOpSum) = OpSum(ptype(opc), mapkv(kv->f(kv[1]', kv[2]'), dict(d))) +Base.map(f::Function, op::OuterProduct) = map(f, convert(OpSum, op)) br_tup(tup) = (tup[1], tup[2]') diff --git a/src/opsum.jl b/src/opsum.jl index 6464cd7..0c3975c 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -62,7 +62,7 @@ Base.(:(==)){P,N}(a::DualOpSum{P,N}, b::DualOpSum{P,N}) = a.op == b.op Base.(:(==))(a::DiracOp, b::DiracOp) = ==(promote(a,b)...) Base.hash(op::AbsOpSum) = hash(dict(filternz(op)), hash(ptype(op))) -Base.hash(op::AbsOpSum, h::Uint64) = hash(hash(op), h) +Base.hash(op::AbsOpSum, h::UInt64) = hash(hash(op), h) Base.length(op::AbsOpSum) = length(dict(op)) @@ -160,7 +160,7 @@ inner(a::DualOpSum, b::DualOpSum) = inner(b.op, a.op)' function inner_load!(result, a::OpSum, b::OpSum, prodtype) for (o1,v) in dict(a), (o2,c) in dict(b) - add_to_dict!(result, + add_to_dict!(result, OpLabel(klabel(o1), blabel(o2)), inner_mul(v, c, prodtype, blabel(o1), klabel(o2))) end @@ -169,7 +169,7 @@ end function inner_load!(result, a::OpSum, b::DualOpSum, prodtype) for (o1,v) in dict(a), (o2,c) in dict(b) - add_to_dict!(result, + add_to_dict!(result, OpLabel(klabel(o1), klabel(o2)), inner_mul(v, c', prodtype, blabel(o1), blabel(o2))) end @@ -202,7 +202,7 @@ end function brcoeff{T}(brdict, prodtype, klabel, v, ::Type{T}) coeff = predict_zero(T) for (blabel,c) in brdict - coeff += inner_mul(c', v, prodtype, klabel, blabel) + coeff += inner_mul(c', v, prodtype, klabel, blabel) end return coeff' end @@ -257,7 +257,7 @@ end function act_on_dict!(result, op::OpSum, kt::Ket, i, prodtype) for (o,c) in dict(op), (k,v) in dict(kt) - add_to_dict!(result, + add_to_dict!(result, setindex(k, klabel(o)[1], i), inner_mul(c, v, prodtype, blabel(o)[1], k[i])) end @@ -290,19 +290,22 @@ Base.scale!(c::Number, op::OpSum) = scale!(op, c) Base.scale!(opc::DualOpSum, c::Number) = DualOpSum(scale!(opc.op, c')) Base.scale!(c::Number, opc::DualOpSum) = scale!(opc, c) -Base.scale(op::OpSum, c::Number) = similar(op, dscale(dict(op), c)) -Base.scale(c::Number, op::OpSum) = scale(op, c) -Base.scale(opc::DualOpSum, c::Number) = DualOpSum(scale(opc.op, c')) -Base.scale(c::Number, opc::DualOpSum) = scale(opc, c) +# See #15258 in JuliaLang/julia +#= +diagonal(op::OpSum) * (c::Number) = similar(op, dscale(dict(op), c)) +diagonal(c::Number) * (op::OpSum) = diagonal(op) * c +diagonal(opc::DualOpSum) * c::Number = DualOpSum(diagonal(opc.op) * c') +diagonal(c::Number) * opc::DualOpSum = diagonal(opc) * c +=# -Base.(:*)(c::Number, op::DiracOp) = scale(c, op) -Base.(:*)(op::DiracOp, c::Number) = scale(op, c) -Base.(:/)(op::DiracOp, c::Number) = scale(op, 1/c) +Base.(:*)(c::Number, op::DiracOp) = diagonal(c)*op +Base.(:*)(op::DiracOp, c::Number) = diagonal(op)*c +Base.(:/)(op::DiracOp, c::Number) = diagonal(op)* 1/c ########### # + and - # ########### -Base.(:-)(op::OpSum) = scale(-1, op) +Base.(:-)(op::OpSum) = diagonal(-1) * op Base.(:-)(opc::DualOpSum) = DualOpSum(-opc.op) Base.(:+){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, add_merge(dict(a), dict(b))) @@ -320,7 +323,7 @@ Base.(:-)(a::DiracOp, b::DiracOp) = a + (-b) Base.norm(op::OpSum) = sqrt(sum(abs2, values(dict(op)))) Base.norm(opc::DualOpSum) = norm(opc.op) -normalize(op::DiracOp) = scale(1/norm(op), op) +normalize(op::DiracOp) = diagonal(1/norm(op))*op normalize!(op::DiracOp) = scale!(1/norm(op), op) ######### @@ -408,6 +411,8 @@ function matrep(op::DiracOp, labels...) return T[bra(i...) * op * ket(j...) for i in iter, j in iter] end +#TODO Fix +#= function matrep(op::Union(DualFunc, Function), labels) return [bra(i) * op * ket(j) for i in labels, j in labels] end @@ -416,6 +421,7 @@ function matrep(op::Union(DualFunc, Function), labels...) iter = Iterators.product(labels...) return [bra(i...) * op * ket(j...) for i in iter, j in iter] end +=# ###################### # Printing Functions # diff --git a/src/outerproduct.jl b/src/outerproduct.jl index 74152f0..02c707f 100644 --- a/src/outerproduct.jl +++ b/src/outerproduct.jl @@ -29,7 +29,7 @@ Base.eltype(op::OuterProduct) = promote_type(typeof(op.scalar), eltype(op.kt), e # these equality/hash functions are pretty inefficient... Base.(:(==)){P,N}(a::OuterProduct{P,N}, b::OuterProduct{P,N}) = convert(OpSum, a) == convert(OpSum, b) Base.hash(op::OuterProduct) = hash(convert(OpSum, op)) -Base.hash(op::OuterProduct, h::Uint64) = hash(hash(op), h) +Base.hash(op::OuterProduct, h::UInt64) = hash(hash(op), h) Base.length(op::OuterProduct) = length(op.kt)*length(op.br) @@ -98,8 +98,11 @@ tensor(a::OuterProduct, b::OuterProduct) = OuterProduct(a.scalar * b.scalar, ten Base.scale!(c::Number, op::OuterProduct) = (op.scalar = c*op.scalar; return op) Base.scale!(op::OuterProduct, c::Number) = (op.scalar = op.scalar*c; return op) +#TODO Fix +#= Base.scale(c::Number, op::OuterProduct) = OuterProduct(c * op.scalar, copy(op.kt), copy(op.br)) Base.scale(op::OuterProduct, c::Number) = OuterProduct(op.scalar * c, copy(op.kt), copy(op.br)) +=# ########### # + and - # diff --git a/src/state.jl b/src/state.jl index 46fedc3..618b3e9 100644 --- a/src/state.jl +++ b/src/state.jl @@ -47,7 +47,7 @@ Base.similar(br::Bra, d=similar(dict(br)); P=ptype(br)) = Bra(P, d) Base.(:(==)){P,N}(a::Ket{P,N}, b::Ket{P,N}) = ptype(a) == ptype(b) && dict(filternz(a)) == dict(filternz(b)) Base.(:(==)){P,N}(a::Bra{P,N}, b::Bra{P,N}) = a.kt == b.kt Base.hash(s::DiracState) = hash(dict(filternz(s)), hash(ptype(s))) -Base.hash(s::DiracState, h::Uint64) = hash(hash(s), h) +Base.hash(s::DiracState, h::UInt64) = hash(hash(s), h) Base.length(s::DiracState) = length(dict(s)) @@ -115,7 +115,7 @@ function inner{P,N,T1,T2}(br::Bra{P,N,T1}, kt::Ket{P,N,T2}) for (b,c) in dict(br), (k,v) in dict(kt) result += inner_mul(c',v,prodtype,b,k) end - return result + return result end function ortho_inner(a::DiracState{KroneckerDelta}, b::DiracState{KroneckerDelta}) @@ -168,14 +168,17 @@ Base.scale!(c::Number, k::Ket) = scale!(k,c) Base.scale!(b::Bra, c::Number) = Bra(scale!(b.kt, c')) Base.scale!(c::Number, b::Bra) = scale!(b,c) -Base.scale(k::Ket, c::Number) = similar(k, dscale(dict(k), c)) -Base.scale(c::Number, k::Ket) = scale(k,c) -Base.scale(b::Bra, c::Number) = Bra(scale(b.kt, c')) -Base.scale(c::Number, b::Bra) = scale(b,c) - -Base.(:*)(c::Number, s::DiracState) = scale(c, s) -Base.(:*)(s::DiracState, c::Number) = scale(s, c) -Base.(:/)(s::DiracState, c::Number) = scale(s, 1/c) +# See #15258 in JuliaLang/julia +#= +diagonal(k::Ket) * c::Number = similar(k, dscale(dict(k), c)) +diagonal(c::Number)* k::Ket = diagonal(k) * c +diagonal(b::Bra) * c::Number = Bra(diagonal(b.kt)* c') +diagonal(c::Number) * b::Bra = diagoanl(b) * c +=# + +Base.(:*)(c::Number, s::DiracState) = diagonal(c) * s +Base.(:*)(s::DiracState, c::Number) = diagonal(s) * c +Base.(:/)(s::DiracState, c::Number) = diagonal(s) * 1/c ########### # + and - # diff --git a/src/str_macros.jl b/src/str_macros.jl index f358217..707cff7 100644 --- a/src/str_macros.jl +++ b/src/str_macros.jl @@ -63,9 +63,9 @@ end immutable OpDefExpr op_sym::Symbol - label_args::Union(Symbol, Expr) + label_args::Symbol lhs_type::Symbol - rhs::Union(Symbol, Expr) + rhs::Symbol end OpDefExpr(ods::OpDefStr) = OpDefExpr(symbol(ods.op_name), parse(ods.label_args), symbol(ods.lhs_type), parse(ods.rhs)) From cd993a315bfa3ef04eebd922ac5bfb8ce3885f12 Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Mon, 10 Apr 2017 08:28:08 +0530 Subject: [PATCH 02/13] Fix scale and scale! version problem Base.scale and Base.scale! were deprecated in v0.5 and removed in v0.6-pre.alpha. Removing their import permits use on v0.6- May require a look in the future. --- REQUIRE | 2 +- src/opsum.jl | 30 +++++++++++++++--------------- src/outerproduct.jl | 4 ++-- src/state.jl | 28 ++++++++++++++-------------- src/str_macros.jl | 18 +++++++++--------- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/REQUIRE b/REQUIRE index d76558f..5b8a764 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ -julia 0.3 0.4- +julia 0.4-,0.6- Compat Iterators \ No newline at end of file diff --git a/src/opsum.jl b/src/opsum.jl index 0c3975c..ffac6bb 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -285,27 +285,27 @@ Base.(:*)(kt::Ket, br::Bra) = tensor(kt,br) ########### # Scaling # ########### -Base.scale!(op::OpSum, c::Number) = (dscale!(dict(op), c); return op) -Base.scale!(c::Number, op::OpSum) = scale!(op, c) -Base.scale!(opc::DualOpSum, c::Number) = DualOpSum(scale!(opc.op, c')) -Base.scale!(c::Number, opc::DualOpSum) = scale!(opc, c) +scale!(op::OpSum, c::Number) = (dscale!(dict(op), c); return op) +scale!(c::Number, op::OpSum) = scale!(op, c) +scale!(opc::DualOpSum, c::Number) = DualOpSum(scale!(opc.op, c')) +scale!(c::Number, opc::DualOpSum) = scale!(opc, c) # See #15258 in JuliaLang/julia -#= -diagonal(op::OpSum) * (c::Number) = similar(op, dscale(dict(op), c)) -diagonal(c::Number) * (op::OpSum) = diagonal(op) * c -diagonal(opc::DualOpSum) * c::Number = DualOpSum(diagonal(opc.op) * c') -diagonal(c::Number) * opc::DualOpSum = diagonal(opc) * c -=# -Base.(:*)(c::Number, op::DiracOp) = diagonal(c)*op -Base.(:*)(op::DiracOp, c::Number) = diagonal(op)*c -Base.(:/)(op::DiracOp, c::Number) = diagonal(op)* 1/c +scale(op::OpSum, c::Number) = similar(op, dscale(dict(op), c)) +scale(c::Number , op::OpSum) = Diagonal(op) * c +scale(opc::DualOpSum, c::Number) = DualOpSum(diagonal(opc.op) * c') +scale(c::Number, opc::DualOpSum) = diagonal(opc) * c + + +Base.(:*)(c::Number, op::DiracOp) = Diagonal(c)*op +Base.(:*)(op::DiracOp, c::Number) = Diagonal(op)*c +Base.(:/)(op::DiracOp, c::Number) = Diagonal(op)* 1/c ########### # + and - # ########### -Base.(:-)(op::OpSum) = diagonal(-1) * op +Base.(:-)(op::OpSum) = Diagonal(-1) * op Base.(:-)(opc::DualOpSum) = DualOpSum(-opc.op) Base.(:+){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, add_merge(dict(a), dict(b))) @@ -323,7 +323,7 @@ Base.(:-)(a::DiracOp, b::DiracOp) = a + (-b) Base.norm(op::OpSum) = sqrt(sum(abs2, values(dict(op)))) Base.norm(opc::DualOpSum) = norm(opc.op) -normalize(op::DiracOp) = diagonal(1/norm(op))*op +normalize(op::DiracOp) = Diagonal(1/norm(op))*op normalize!(op::DiracOp) = scale!(1/norm(op), op) ######### diff --git a/src/outerproduct.jl b/src/outerproduct.jl index 02c707f..a06f181 100644 --- a/src/outerproduct.jl +++ b/src/outerproduct.jl @@ -95,8 +95,8 @@ tensor(a::OuterProduct, b::OuterProduct) = OuterProduct(a.scalar * b.scalar, ten ########### # Scaling # ########### -Base.scale!(c::Number, op::OuterProduct) = (op.scalar = c*op.scalar; return op) -Base.scale!(op::OuterProduct, c::Number) = (op.scalar = op.scalar*c; return op) +scale!(c::Number, op::OuterProduct) = (op.scalar = c*op.scalar; return op) +scale!(op::OuterProduct, c::Number) = (op.scalar = op.scalar*c; return op) #TODO Fix #= diff --git a/src/state.jl b/src/state.jl index 618b3e9..c5c757f 100644 --- a/src/state.jl +++ b/src/state.jl @@ -163,22 +163,22 @@ end ########### # Scaling # ########### -Base.scale!(k::Ket, c::Number) = (dscale!(dict(k), c); return k) -Base.scale!(c::Number, k::Ket) = scale!(k,c) -Base.scale!(b::Bra, c::Number) = Bra(scale!(b.kt, c')) -Base.scale!(c::Number, b::Bra) = scale!(b,c) +scale!(k::Ket, c::Number) = (dscale!(dict(k), c); return k) +scale!(c::Number, k::Ket) = scale!(k,c) +scale!(b::Bra, c::Number) = Bra(scale!(b.kt, c')) +scale!(c::Number, b::Bra) = scale!(b,c) # See #15258 in JuliaLang/julia -#= -diagonal(k::Ket) * c::Number = similar(k, dscale(dict(k), c)) -diagonal(c::Number)* k::Ket = diagonal(k) * c -diagonal(b::Bra) * c::Number = Bra(diagonal(b.kt)* c') -diagonal(c::Number) * b::Bra = diagoanl(b) * c -=# - -Base.(:*)(c::Number, s::DiracState) = diagonal(c) * s -Base.(:*)(s::DiracState, c::Number) = diagonal(s) * c -Base.(:/)(s::DiracState, c::Number) = diagonal(s) * 1/c + +scale(k::Ket, c::Number) = similar(k, dscale(dict(k), c)) +scale(c::Number, k::Ket) = Diagonal(k) * c +scale(b::Bra, c::Number) = Bra(Diagonal(b.kt)* c') +scale(c::Number, b::Bra) = diagoanl(b) * c + + +Base.(:*)(c::Number, s::DiracState) = Diagonal(c) * s +Base.(:*)(s::DiracState, c::Number) = Diagonal(s) * c +Base.(:/)(s::DiracState, c::Number) = Diagonal(s) * 1/c ########### # + and - # diff --git a/src/str_macros.jl b/src/str_macros.jl index 707cff7..c860de1 100644 --- a/src/str_macros.jl +++ b/src/str_macros.jl @@ -97,18 +97,18 @@ end macro def_op(str) result_expr = def_op_expr(OpDefStr(str)) return esc(result_expr) -end +end function def_op_expr(ods::OpDefStr) odex = OpDefExpr(ods) if isa(odex.label_args, Expr) - func_on_label_def = quote + func_on_label_def = quote local func_on_args($(odex.label_args.args...)) = $(odex.rhs) local func_on_label(label::StateLabel) = func_on_args(label...) end else # isa(label_expr, Symbol) - func_on_label_def = quote + func_on_label_def = quote local func_on_args($(odex.label_args)) = $(odex.rhs) local func_on_label(label::StateLabel) = func_on_args(first(label)) end @@ -123,7 +123,7 @@ function def_op_expr(ods::OpDefStr) function func_on_pair(pair::Tuple) label, c = pair return $(coeff) * func_on_label(label) - end + end $(odex.op_sym)(state::$(odex.lhs_type)) = sum(func_on_pair, QuDirac.dict(state)) end @@ -140,7 +140,7 @@ coeff_sym(odex::OpDefExpr) = odex.lhs_type == :Ket ? :c : :(c') macro rep_op(str, bases...) result_expr = rep_op_expr(OpDefStr(str), build_prod_basis(bases...)) return esc(result_expr) -end +end build_prod_basis(basis) = basis build_prod_basis(first, bases...) = :(Iterators.product($first, $(bases...))) @@ -157,12 +157,12 @@ end function gen_ket_repr_expr(odex::OpDefExpr, basis) if isa(odex.label_args, Expr) - ex = quote + ex = quote local func_on_args($(odex.label_args.args...)) = $(odex.rhs) * bra($(odex.label_args.args...)) $(odex.op_sym) = sum(args->func_on_args(args...), $basis) end else - ex = quote + ex = quote $(odex.op_sym) = sum($(odex.label_args) -> $(odex.rhs) * bra($(odex.label_args)), $basis) end end @@ -171,12 +171,12 @@ end function gen_bra_repr_expr(odex::OpDefExpr, basis) if isa(odex.label_args, Expr) - ex = quote + ex = quote local func_on_args($(odex.label_args.args...)) = ket($(odex.label_args.args...)) * $(odex.rhs) $(odex.op_sym) = sum(args->func_on_args(args...), $basis) end else - ex = quote + ex = quote $(odex.op_sym) = sum($(odex.label_args) -> ket($(odex.label_args)) * $(odex.rhs), $basis) end end From c49097aab6ee0523b56c89a0315b17f84719a376 Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Mon, 10 Apr 2017 11:10:55 +0530 Subject: [PATCH 03/13] Update version --- REQUIRE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/REQUIRE b/REQUIRE index 5b8a764..3df93e9 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ -julia 0.4-,0.6- +julia 0.6 Compat -Iterators \ No newline at end of file +Iterators From 36fab762313add444a474d043f68d1ada62137dd Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Mon, 10 Apr 2017 12:12:34 +0530 Subject: [PATCH 04/13] Fix scaling conversion --- src/opsum.jl | 14 +++++++------- src/state.jl | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/opsum.jl b/src/opsum.jl index ffac6bb..87826f9 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -293,19 +293,19 @@ scale!(c::Number, opc::DualOpSum) = scale!(opc, c) # See #15258 in JuliaLang/julia scale(op::OpSum, c::Number) = similar(op, dscale(dict(op), c)) -scale(c::Number , op::OpSum) = Diagonal(op) * c -scale(opc::DualOpSum, c::Number) = DualOpSum(diagonal(opc.op) * c') -scale(c::Number, opc::DualOpSum) = diagonal(opc) * c +scale(c::Number , op::OpSum) = op * Diagonal(diagm(c)) +scale(opc::DualOpSum, c::Number) = DualOpSum(opc.op * diagonal(diagm(c'))) +scale(c::Number, opc::DualOpSum) = opc * Diagonal(diagm(c)) -Base.(:*)(c::Number, op::DiracOp) = Diagonal(c)*op -Base.(:*)(op::DiracOp, c::Number) = Diagonal(op)*c -Base.(:/)(op::DiracOp, c::Number) = Diagonal(op)* 1/c +Base.(:*)(c::Number, op::DiracOp) = Diagonal(diagm(c)) * op +Base.(:*)(op::DiracOp, c::Number) = op * Diagonal(diagm(c)) +Base.(:/)(op::DiracOp, c::Number) = op * Diagonal(diagm(1/c)) ########### # + and - # ########### -Base.(:-)(op::OpSum) = Diagonal(-1) * op +Base.(:-)(op::OpSum) = Diagonal(diagm(-1)) * op Base.(:-)(opc::DualOpSum) = DualOpSum(-opc.op) Base.(:+){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, add_merge(dict(a), dict(b))) diff --git a/src/state.jl b/src/state.jl index c5c757f..bbad181 100644 --- a/src/state.jl +++ b/src/state.jl @@ -171,14 +171,14 @@ scale!(c::Number, b::Bra) = scale!(b,c) # See #15258 in JuliaLang/julia scale(k::Ket, c::Number) = similar(k, dscale(dict(k), c)) -scale(c::Number, k::Ket) = Diagonal(k) * c -scale(b::Bra, c::Number) = Bra(Diagonal(b.kt)* c') -scale(c::Number, b::Bra) = diagoanl(b) * c +scale(c::Number, k::Ket) = Diagonal(diagm(k)) * c +scale(b::Bra, c::Number) = Bra(b.kt* Diagonal(diagm(c'))) +scale(c::Number, b::Bra) = b * Diagonal(diagm(c)) Base.(:*)(c::Number, s::DiracState) = Diagonal(c) * s -Base.(:*)(s::DiracState, c::Number) = Diagonal(s) * c -Base.(:/)(s::DiracState, c::Number) = Diagonal(s) * 1/c +Base.(:*)(s::DiracState, c::Number) = s * Diagonal(diagm(c)) +Base.(:/)(s::DiracState, c::Number) = s * Diagonal(diagm(1/c)) ########### # + and - # From 0a79adbaf38585dce0ac7c4e2bf86a34404b638b Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Mon, 10 Apr 2017 12:19:12 +0530 Subject: [PATCH 05/13] Fix overlooked case --- src/state.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/state.jl b/src/state.jl index bbad181..154255e 100644 --- a/src/state.jl +++ b/src/state.jl @@ -176,7 +176,7 @@ scale(b::Bra, c::Number) = Bra(b.kt* Diagonal(diagm(c'))) scale(c::Number, b::Bra) = b * Diagonal(diagm(c)) -Base.(:*)(c::Number, s::DiracState) = Diagonal(c) * s +Base.(:*)(c::Number, s::DiracState) = Diagonal(diagm(c)) * s Base.(:*)(s::DiracState, c::Number) = s * Diagonal(diagm(c)) Base.(:/)(s::DiracState, c::Number) = s * Diagonal(diagm(1/c)) From b7edf8c2f6965cb69e758968bd1ddc8fbb510c47 Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Tue, 11 Apr 2017 00:15:16 +0530 Subject: [PATCH 06/13] Simplified scale alternative --- src/QuDirac.jl | 32 ++++++++++++++++---------------- src/opsum.jl | 16 ++++++++-------- src/state.jl | 12 ++++++------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/QuDirac.jl b/src/QuDirac.jl index c018411..9a662a8 100644 --- a/src/QuDirac.jl +++ b/src/QuDirac.jl @@ -1,12 +1,12 @@ module QuDirac - + using Compat using Iterators.product - if !(v"0.3-" <= VERSION < v"0.4-") - warn("QuDirac v0.1 only officially supports the v0.3 release of Julia. Your version of Julia is $VERSION.") + if !( VERSION < v"0.6") + warn("QuDirac v0.1 only officially supports the v0.6 release of Julia. Your version of Julia is $VERSION.") end - + #################### # String Constants # #################### @@ -19,10 +19,10 @@ module QuDirac # Abstract Types # ################## abstract AbstractInner - - immutable UndefinedInner <: AbstractInner end + + immutable UndefinedInner <: AbstractInner end immutable KroneckerDelta <: AbstractInner end - + abstract AbstractDirac{P<:AbstractInner,N} abstract DiracOp{P,N} <: AbstractDirac{P,N} abstract DiracState{P,N} <: AbstractDirac{P,N} @@ -32,7 +32,7 @@ module QuDirac ############# # Functions # ############# - # These functions will be in + # These functions will be in # QuBase when it releases tensor() = error("Cannot call tensor function without arguments") tensor(s...) = reduce(tensor, s) @@ -49,19 +49,19 @@ module QuDirac include("dictfuncs.jl") include("mapfuncs.jl") include("str_macros.jl") - + ################# # default_inner # ################# - # Julia doesn't recompile functions within other - # previously compiled functions, so we can't have a + # Julia doesn't recompile functions within other + # previously compiled functions, so we can't have a # get_default_inner() or something like that. # # Also, global optimization is poor, so we don't want # to use that either. Thus, we go for a function that - # straight-up redefines the default constructors for - # the relevant objects. This is hacky, but works for now, - # seeing as how only a few functions actually "use" + # straight-up redefines the default constructors for + # the relevant objects. This is hacky, but works for now, + # seeing as how only a few functions actually "use" # the default ptype. function default_inner(ptype::AbstractInner) QuDirac.OpSum(dict::Dict) = OpSum(ptype, dict) @@ -80,8 +80,8 @@ module QuDirac AbstractDirac, DiracState, DiracOp, - # All functions that conflict - # with QuBase should be exported + # All functions that conflict + # with QuBase should be exported # below: tensor, commute, diff --git a/src/opsum.jl b/src/opsum.jl index 87826f9..f516142 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -293,19 +293,19 @@ scale!(c::Number, opc::DualOpSum) = scale!(opc, c) # See #15258 in JuliaLang/julia scale(op::OpSum, c::Number) = similar(op, dscale(dict(op), c)) -scale(c::Number , op::OpSum) = op * Diagonal(diagm(c)) -scale(opc::DualOpSum, c::Number) = DualOpSum(opc.op * diagonal(diagm(c'))) -scale(c::Number, opc::DualOpSum) = opc * Diagonal(diagm(c)) +scale(c::Number , op::OpSum) = op * c +scale(opc::DualOpSum, c::Number) = DualOpSum(opc.op * (c')) +scale(c::Number, opc::DualOpSum) = opc * c -Base.(:*)(c::Number, op::DiracOp) = Diagonal(diagm(c)) * op -Base.(:*)(op::DiracOp, c::Number) = op * Diagonal(diagm(c)) -Base.(:/)(op::DiracOp, c::Number) = op * Diagonal(diagm(1/c)) +Base.(:*)(c::Number, op::DiracOp) = c * op +Base.(:*)(op::DiracOp, c::Number) = op * c +Base.(:/)(op::DiracOp, c::Number) = op * (1/c) ########### # + and - # ########### -Base.(:-)(op::OpSum) = Diagonal(diagm(-1)) * op +Base.(:-)(op::OpSum) = (-1) * op Base.(:-)(opc::DualOpSum) = DualOpSum(-opc.op) Base.(:+){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, add_merge(dict(a), dict(b))) @@ -323,7 +323,7 @@ Base.(:-)(a::DiracOp, b::DiracOp) = a + (-b) Base.norm(op::OpSum) = sqrt(sum(abs2, values(dict(op)))) Base.norm(opc::DualOpSum) = norm(opc.op) -normalize(op::DiracOp) = Diagonal(1/norm(op))*op +normalize(op::DiracOp) = (1/norm(op))*op normalize!(op::DiracOp) = scale!(1/norm(op), op) ######### diff --git a/src/state.jl b/src/state.jl index 154255e..3b3b218 100644 --- a/src/state.jl +++ b/src/state.jl @@ -171,14 +171,14 @@ scale!(c::Number, b::Bra) = scale!(b,c) # See #15258 in JuliaLang/julia scale(k::Ket, c::Number) = similar(k, dscale(dict(k), c)) -scale(c::Number, k::Ket) = Diagonal(diagm(k)) * c -scale(b::Bra, c::Number) = Bra(b.kt* Diagonal(diagm(c'))) -scale(c::Number, b::Bra) = b * Diagonal(diagm(c)) +scale(c::Number, k::Ket) = k * c +scale(b::Bra, c::Number) = Bra(b.kt* (c')) +scale(c::Number, b::Bra) = b * c -Base.(:*)(c::Number, s::DiracState) = Diagonal(diagm(c)) * s -Base.(:*)(s::DiracState, c::Number) = s * Diagonal(diagm(c)) -Base.(:/)(s::DiracState, c::Number) = s * Diagonal(diagm(1/c)) +Base.(:*)(c::Number, s::DiracState) = c * s +Base.(:*)(s::DiracState, c::Number) = s * c +Base.(:/)(s::DiracState, c::Number) = s * (1/c) ########### # + and - # From 7b5b38f17158dcc652a3997c1d296e3f620a5cbd Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Tue, 11 Apr 2017 06:58:00 +0530 Subject: [PATCH 07/13] Multiplication errors fixed --- src/QuDirac.jl | 2 +- src/opsum.jl | 8 ++++---- src/outerproduct.jl | 9 +++------ src/state.jl | 7 +++---- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/QuDirac.jl b/src/QuDirac.jl index 9a662a8..b530727 100644 --- a/src/QuDirac.jl +++ b/src/QuDirac.jl @@ -3,7 +3,7 @@ module QuDirac using Compat using Iterators.product - if !( VERSION < v"0.6") + if !(VERSION < v"0.6") warn("QuDirac v0.1 only officially supports the v0.6 release of Julia. Your version of Julia is $VERSION.") end diff --git a/src/opsum.jl b/src/opsum.jl index f516142..d923bb7 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -298,14 +298,14 @@ scale(opc::DualOpSum, c::Number) = DualOpSum(opc.op * (c')) scale(c::Number, opc::DualOpSum) = opc * c -Base.(:*)(c::Number, op::DiracOp) = c * op -Base.(:*)(op::DiracOp, c::Number) = op * c -Base.(:/)(op::DiracOp, c::Number) = op * (1/c) +Base.(:*)(c::Number, op::DiracOp) = scale(c, op) +Base.(:*)(op::DiracOp, c::Number) = scale(op, c) +Base.(:/)(op::DiracOp, c::Number) = scale(op, 1/c) ########### # + and - # ########### -Base.(:-)(op::OpSum) = (-1) * op +Base.(:-)(op::OpSum) = scale(-1, op) Base.(:-)(opc::DualOpSum) = DualOpSum(-opc.op) Base.(:+){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, add_merge(dict(a), dict(b))) diff --git a/src/outerproduct.jl b/src/outerproduct.jl index a06f181..63e832c 100644 --- a/src/outerproduct.jl +++ b/src/outerproduct.jl @@ -27,7 +27,7 @@ Base.promote_rule{G<:OpSum, O<:OuterProduct}(::Type{G}, ::Type{O}) = OpSum Base.eltype(op::OuterProduct) = promote_type(typeof(op.scalar), eltype(op.kt), eltype(op.br)) # these equality/hash functions are pretty inefficient... -Base.(:(==)){P,N}(a::OuterProduct{P,N}, b::OuterProduct{P,N}) = convert(OpSum, a) == convert(OpSum, b) +Base.(:(==)){P,N}(a::OuterProduct{P,N}, b::OuterProduct{P,N}) = convert(OpSum, a) == convert(OpSum, b) Base.hash(op::OuterProduct) = hash(convert(OpSum, op)) Base.hash(op::OuterProduct, h::UInt64) = hash(hash(op), h) @@ -98,11 +98,8 @@ tensor(a::OuterProduct, b::OuterProduct) = OuterProduct(a.scalar * b.scalar, ten scale!(c::Number, op::OuterProduct) = (op.scalar = c*op.scalar; return op) scale!(op::OuterProduct, c::Number) = (op.scalar = op.scalar*c; return op) -#TODO Fix -#= -Base.scale(c::Number, op::OuterProduct) = OuterProduct(c * op.scalar, copy(op.kt), copy(op.br)) -Base.scale(op::OuterProduct, c::Number) = OuterProduct(op.scalar * c, copy(op.kt), copy(op.br)) -=# +scale(c::Number, op::OuterProduct) = OuterProduct(c * op.scalar, copy(op.kt), copy(op.br)) +scale(op::OuterProduct, c::Number) = OuterProduct(op.scalar * c, copy(op.kt), copy(op.br)) ########### # + and - # diff --git a/src/state.jl b/src/state.jl index 3b3b218..de6db86 100644 --- a/src/state.jl +++ b/src/state.jl @@ -175,10 +175,9 @@ scale(c::Number, k::Ket) = k * c scale(b::Bra, c::Number) = Bra(b.kt* (c')) scale(c::Number, b::Bra) = b * c - -Base.(:*)(c::Number, s::DiracState) = c * s -Base.(:*)(s::DiracState, c::Number) = s * c -Base.(:/)(s::DiracState, c::Number) = s * (1/c) +Base.(:*)(c::Number, s::DiracState) = scale(c, s) +Base.(:*)(s::DiracState, c::Number) = scale(s, c) +Base.(:/)(s::DiracState, c::Number) = scale(s, 1/c) ########### # + and - # From 3da17cdf0054a685b46db769868eed49937bf028 Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Tue, 11 Apr 2017 16:38:59 +0530 Subject: [PATCH 08/13] Change symbol to Symbol The lowercase symbol function has been deprecated in favor of the Symbol constructor (#16154) --- src/str_macros.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/str_macros.jl b/src/str_macros.jl index c860de1..a018bec 100644 --- a/src/str_macros.jl +++ b/src/str_macros.jl @@ -68,7 +68,7 @@ immutable OpDefExpr rhs::Symbol end -OpDefExpr(ods::OpDefStr) = OpDefExpr(symbol(ods.op_name), parse(ods.label_args), symbol(ods.lhs_type), parse(ods.rhs)) +OpDefExpr(ods::OpDefStr) = OpDefExpr(Symbol(ods.op_name), parse(ods.label_args), Symbol(ods.lhs_type), parse(ods.rhs)) rm_whspace(str) = join(split(str, r"\s")) From cae0fbf7ceb05283d56098472ca38e239b38911a Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Tue, 11 Apr 2017 21:48:10 +0530 Subject: [PATCH 09/13] Update nomralize, normalize! and Symbol sections New normalize and normalize! convenience functions were introduced for normalizing vectors (#13681) This created ambiguity with QuDirac's normalize and normalize! Fix for that In addition, used Symbol constructor to convert Expr objects to Symbol --- src/innerexpr.jl | 16 ++++++++-------- src/opsum.jl | 4 ++-- src/state.jl | 6 +++--- src/str_macros.jl | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/innerexpr.jl b/src/innerexpr.jl index 7a4ad58..a987044 100644 --- a/src/innerexpr.jl +++ b/src/innerexpr.jl @@ -12,7 +12,7 @@ klabel(i::InnerProduct) = i.k Base.repr(i::InnerProduct) = brstr(blabel(i))*ktstr(klabel(i))[2:end] Base.show(io::IO, i::InnerProduct) = print(io, repr(i)) -Base.(:(==))(a::InnerProduct, b::InnerProduct) = blabel(a) == blabel(b) && klabel(a) == klabel(b) +Base.(:(==))(a::InnerProduct, b::InnerProduct) = blabel(a) == blabel(b) && klabel(a) == klabel(b) Base.(:(==))(::InnerProduct, ::Number) = false Base.(:(==))(::Number, ::InnerProduct) = false @@ -26,7 +26,7 @@ Base.conj(i::InnerProduct) = InnerProduct(klabel(i), blabel(i)) ############## # we can cheat here to avoid tempory StateLabel construction -# to evaluate KroneckerDelta inner products +# to evaluate KroneckerDelta inner products eval_inner_rule(p::KroneckerDelta, b, k) = inner_rule(p, b, k) eval_inner_rule(p::KroneckerDelta, b::StateLabel, k::StateLabel) = inner_rule(p, b, k) @@ -48,10 +48,10 @@ inner_mul(v,c,prodtype,b,k) = v * c * eval_inner_rule(prodtype, b, k) # InnerExpr # ############## # A InnerExpr is a type that wraps arthimetic expressions -# performed with InnerExprs. The allows storage and -# delayed evaluation of expressions. For example, this +# performed with InnerExprs. The allows storage and +# delayed evaluation of expressions. For example, this # expression: -# +# # (< a | b >^2 + < c | d >^2 - 3.13+im) / 2 # # is representable as a InnerExpr. @@ -83,7 +83,7 @@ Base.zero(::InnerExpr) = InnerExpr(0) Base.promote_rule{N<:Number}(::Type{InnerExpr}, ::Type{N}) = InnerExpr Base.length(iex::InnerExpr) = length(iex.ex.args) -Base.getindex(iex::InnerExpr, i) = iex.ex.args[i] +Base.getindex(iex::InnerExpr, i::Integer) = iex.ex.args[i] ############## # inner_eval # @@ -157,7 +157,7 @@ function iexpr_mul(a,b) end end -Base.(:*)(a::InnerExpr, b::InnerExpr) =iexpr_mul(a,b) +Base.(:*)(a::InnerExpr, b::InnerExpr) =iexpr_mul(a,b) Base.(:*)(a::Bool, b::InnerExpr) = iexpr_mul(a,b) Base.(:*)(a::InnerExpr, b::Bool) = iexpr_mul(a,b) Base.(:*)(a::InnerExpr, b::Number) = iexpr_mul(a,b) @@ -189,7 +189,7 @@ Base.(:/)(a::Number, b::InnerExpr) = iexpr_div(a, b) # Addition # ############ function iexpr_add(a, b) - if same_num(a, 0) + if same_num(a, 0) return InnerExpr(b) elseif same_num(b, 0) return InnerExpr(a) diff --git a/src/opsum.jl b/src/opsum.jl index d923bb7..0c8e28b 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -323,8 +323,8 @@ Base.(:-)(a::DiracOp, b::DiracOp) = a + (-b) Base.norm(op::OpSum) = sqrt(sum(abs2, values(dict(op)))) Base.norm(opc::DualOpSum) = norm(opc.op) -normalize(op::DiracOp) = (1/norm(op))*op -normalize!(op::DiracOp) = scale!(1/norm(op), op) +QuDirac.normalize(op::DiracOp) = (1/norm(op))*op +QuDirac.normalize!(op::DiracOp) = scale!(1/norm(op), op) ######### # Trace # diff --git a/src/state.jl b/src/state.jl index de6db86..e2194bb 100644 --- a/src/state.jl +++ b/src/state.jl @@ -204,8 +204,8 @@ Base.(:*)(a::Bra, b::Bra) = tensor(a,b) # Normalization # ################# Base.norm(s::DiracState) = sqrt(sum(abs2, values(dict(s)))) -normalize(s::DiracState) = (1/norm(s))*s -normalize!(s::DiracState) = scale!(1/norm(s), s) +QuDirac.normalize(s::DiracState) = (1/norm(s))*s +QuDirac.normalize!(s::DiracState) = scale!(1/norm(s), s) ######################## # Misc. Math Functions # @@ -289,4 +289,4 @@ export Ket, lower, raise, act_on, - inner_eval \ No newline at end of file + inner_eval diff --git a/src/str_macros.jl b/src/str_macros.jl index a018bec..5928644 100644 --- a/src/str_macros.jl +++ b/src/str_macros.jl @@ -68,7 +68,7 @@ immutable OpDefExpr rhs::Symbol end -OpDefExpr(ods::OpDefStr) = OpDefExpr(Symbol(ods.op_name), parse(ods.label_args), Symbol(ods.lhs_type), parse(ods.rhs)) +OpDefExpr(ods::OpDefStr) = OpDefExpr(Symbol(ods.op_name), Symbol(parse(ods.label_args)), Symbol(ods.lhs_type), Symbol(parse(ods.rhs))) rm_whspace(str) = join(split(str, r"\s")) @@ -186,4 +186,4 @@ end export @d_str, @d_mstr, @def_op, - @rep_op \ No newline at end of file + @rep_op From ee23ef6566d0c8354b4c831eabe115238f860211 Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Tue, 11 Apr 2017 22:28:21 +0530 Subject: [PATCH 10/13] Fixed several deprecation warnings, by product of the Julia version moving from v0.3 to v0.6 The keywords used to define types have changed (#19157, #20418) of JuliaLang/julia. "abstract changes to abstract type ... end", fix for the same. The typealias keyword is deprecated, and should be replaced with Vector{T} = Array{T,1} or a const assignment (#20500) of JuliaLang/julia. Fix for the same Changed Base.(operator) to Base.operator to fix deprecation warnings. Note, this should be replaced in the future as one no longer defines methods for .* etcetera due to (#17623) of JuliaLang/julia. --- src/QuDirac.jl | 10 ++++----- src/innerexpr.jl | 52 ++++++++++++++++++++++----------------------- src/labels.jl | 4 ++-- src/mapfuncs.jl | 2 +- src/opsum.jl | 46 +++++++++++++++++++-------------------- src/outerproduct.jl | 6 +++--- src/state.jl | 28 ++++++++++++------------ 7 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/QuDirac.jl b/src/QuDirac.jl index b530727..25919b7 100644 --- a/src/QuDirac.jl +++ b/src/QuDirac.jl @@ -18,16 +18,16 @@ module QuDirac ################## # Abstract Types # ################## - abstract AbstractInner + abstract type AbstractInner end immutable UndefinedInner <: AbstractInner end immutable KroneckerDelta <: AbstractInner end - abstract AbstractDirac{P<:AbstractInner,N} - abstract DiracOp{P,N} <: AbstractDirac{P,N} - abstract DiracState{P,N} <: AbstractDirac{P,N} + abstract type AbstractDirac{P<:AbstractInner,N} end + abstract type DiracOp{P,N} <: AbstractDirac{P,N} end + abstract type DiracState{P,N} <: AbstractDirac{P,N} end - abstract DiracScalar <: Number + abstract type DiracScalar <: Number end ############# # Functions # diff --git a/src/innerexpr.jl b/src/innerexpr.jl index a987044..26d8946 100644 --- a/src/innerexpr.jl +++ b/src/innerexpr.jl @@ -12,9 +12,9 @@ klabel(i::InnerProduct) = i.k Base.repr(i::InnerProduct) = brstr(blabel(i))*ktstr(klabel(i))[2:end] Base.show(io::IO, i::InnerProduct) = print(io, repr(i)) -Base.(:(==))(a::InnerProduct, b::InnerProduct) = blabel(a) == blabel(b) && klabel(a) == klabel(b) -Base.(:(==))(::InnerProduct, ::Number) = false -Base.(:(==))(::Number, ::InnerProduct) = false +Base.:(==)(a::InnerProduct, b::InnerProduct) = blabel(a) == blabel(b) && klabel(a) == klabel(b) +Base.:(==)(::InnerProduct, ::Number) = false +Base.:(==)(::Number, ::InnerProduct) = false Base.hash(i::InnerProduct) = hash(blabel(i), hash(klabel(i))) Base.hash(i::InnerProduct, h::UInt64) = hash(hash(i), h) @@ -66,7 +66,7 @@ InnerExpr{N<:Number}(n::N) = convert(InnerExpr, n) Base.convert(::Type{InnerExpr}, iex::InnerExpr) = iex Base.convert{N<:Number}(::Type{InnerExpr}, n::N) = InnerExpr(Expr(:call, +, n)) -Base.(:(==))(a::InnerExpr, b::InnerExpr) = a.ex == b.ex +Base.:(==)(a::InnerExpr, b::InnerExpr) = a.ex == b.ex same_num(a::Number, b::Number) = a == b same_num(a::InnerExpr, b::InnerExpr) = a == b same_num(iex::InnerExpr, i::InnerProduct) = iex == InnerExpr(i) @@ -123,12 +123,12 @@ function iexpr_exp(a, b) end end -Base.(:^)(a::InnerExpr, b::Integer) = iexpr_exp(a, b) -Base.(:^)(a::InnerExpr, b::Rational) = iexpr_exp(a, b) -Base.(:^)(a::InnerExpr, b::InnerExpr) = iexpr_exp(a, b) -Base.(:^)(a::InnerExpr, b::Number) = iexpr_exp(a, b) -#Base.(:^)(a::MathConst{:e}, b::InnerExpr) = iexpr_exp(a, b) -Base.(:^)(a::Number, b::InnerExpr) = iexpr_exp(a, b) +Base.:^(a::InnerExpr, b::Integer) = iexpr_exp(a, b) +Base.:^(a::InnerExpr, b::Rational) = iexpr_exp(a, b) +Base.:^(a::InnerExpr, b::InnerExpr) = iexpr_exp(a, b) +Base.:^(a::InnerExpr, b::Number) = iexpr_exp(a, b) +#Base.:^(a::MathConst{:e}, b::InnerExpr) = iexpr_exp(a, b) +Base.:^(a::Number, b::InnerExpr) = iexpr_exp(a, b) Base.exp(iex::InnerExpr) = InnerExpr(:(exp($(iex)))) Base.exp2(iex::InnerExpr) = InnerExpr(:(exp2($(iex)))) @@ -157,11 +157,11 @@ function iexpr_mul(a,b) end end -Base.(:*)(a::InnerExpr, b::InnerExpr) =iexpr_mul(a,b) -Base.(:*)(a::Bool, b::InnerExpr) = iexpr_mul(a,b) -Base.(:*)(a::InnerExpr, b::Bool) = iexpr_mul(a,b) -Base.(:*)(a::InnerExpr, b::Number) = iexpr_mul(a,b) -Base.(:*)(a::Number, b::InnerExpr) = iexpr_mul(a,b) +Base.:*(a::InnerExpr, b::InnerExpr) =iexpr_mul(a,b) +Base.:*(a::Bool, b::InnerExpr) = iexpr_mul(a,b) +Base.:*(a::InnerExpr, b::Bool) = iexpr_mul(a,b) +Base.:*(a::InnerExpr, b::Number) = iexpr_mul(a,b) +Base.:*(a::Number, b::InnerExpr) = iexpr_mul(a,b) ############ # Division # @@ -180,10 +180,10 @@ function iexpr_div(a, b) end end -Base.(:/)(a::InnerExpr, b::InnerExpr) = iexpr_div(a, b) -Base.(:/)(a::InnerExpr, b::Complex) = iexpr_div(a, b) -Base.(:/)(a::InnerExpr, b::Number) = iexpr_div(a, b) -Base.(:/)(a::Number, b::InnerExpr) = iexpr_div(a, b) +Base.:/(a::InnerExpr, b::InnerExpr) = iexpr_div(a, b) +Base.:/(a::InnerExpr, b::Complex) = iexpr_div(a, b) +Base.:/(a::InnerExpr, b::Number) = iexpr_div(a, b) +Base.:/(a::Number, b::InnerExpr) = iexpr_div(a, b) ############ # Addition # @@ -198,14 +198,14 @@ function iexpr_add(a, b) end end -Base.(:+)(a::InnerExpr, b::InnerExpr) = iexpr_add(a, b) -Base.(:+)(a::InnerExpr, b::Number) = iexpr_add(a, b) -Base.(:+)(a::Number, b::InnerExpr) = iexpr_add(a, b) +Base.:+(a::InnerExpr, b::InnerExpr) = iexpr_add(a, b) +Base.:+(a::InnerExpr, b::Number) = iexpr_add(a, b) +Base.:+(a::Number, b::InnerExpr) = iexpr_add(a, b) ############### # Subtraction # ############### -Base.(:-)(iex::InnerExpr) = length(iex)==2 && iex[1]==:- ? InnerExpr(iex[2]) : InnerExpr(:(-$(iex))) +Base.:-(iex::InnerExpr) = length(iex)==2 && iex[1]==:- ? InnerExpr(iex[2]) : InnerExpr(:(-$(iex))) function iexpr_subtract(a, b) if same_num(a, b) @@ -219,9 +219,9 @@ function iexpr_subtract(a, b) end end -Base.(:-)(a::InnerExpr, b::InnerExpr) = iexpr_subtract(a, b) -Base.(:-)(a::InnerExpr, b::Number) = iexpr_subtract(a, b) -Base.(:-)(a::Number, b::InnerExpr) = iexpr_subtract(a, b) +Base.:-(a::InnerExpr, b::InnerExpr) = iexpr_subtract(a, b) +Base.:-(a::InnerExpr, b::Number) = iexpr_subtract(a, b) +Base.:-(a::Number, b::InnerExpr) = iexpr_subtract(a, b) ################## # Absolute Value # diff --git a/src/labels.jl b/src/labels.jl index c849cf6..edbd79b 100644 --- a/src/labels.jl +++ b/src/labels.jl @@ -20,7 +20,7 @@ Base.copy{N}(s::StateLabel{N}) = StateLabel{N}(s.label, s.hash) Base.hash(s::StateLabel) = s.hash Base.hash(s::StateLabel, h::UInt64) = hash(hash(s), h) -Base.(:(==)){N}(a::StateLabel{N},b::StateLabel{N}) = hash(a) == hash(b) +Base.:(==){N}(a::StateLabel{N},b::StateLabel{N}) = hash(a) == hash(b) Base.start(s::StateLabel) = start(s.label) Base.next(s::StateLabel, i) = next(s.label, i) @@ -63,7 +63,7 @@ Base.copy{N}(o::OpLabel{N}) = OpLabel{N}(o.k, o.b, o.hash) Base.hash(o::OpLabel) = o.hash Base.hash(o::OpLabel, h::UInt64) = hash(hash(o), h) -Base.(:(==)){N}(a::OpLabel{N}, b::OpLabel{N}) = hash(a) == hash(b) +Base.:(==){N}(a::OpLabel{N}, b::OpLabel{N}) = hash(a) == hash(b) Base.length{N}(::OpLabel{N}) = N diff --git a/src/mapfuncs.jl b/src/mapfuncs.jl index 91b5693..8bc0e78 100644 --- a/src/mapfuncs.jl +++ b/src/mapfuncs.jl @@ -61,4 +61,4 @@ br_tup(tup) = (tup[1], tup[2]') export maplabels!, mapcoeffs!, maplabels, - mapcoeffs \ No newline at end of file + mapcoeffs diff --git a/src/opsum.jl b/src/opsum.jl index 0c8e28b..ceda950 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -1,7 +1,7 @@ ################### # OpSum/DualOpSum # ################### -abstract AbsOpSum{P,N,T} <: DiracOp{P,N} +abstract type AbsOpSum{P,N,T} <: DiracOp{P,N} end typealias OpDict{N,T} Dict{OpLabel{N},T} @@ -57,9 +57,9 @@ Base.copy(opc::DualOpSum) = DualOpSum(copy(opc.op)) Base.similar(op::OpSum, d=similar(dict(op)); P=ptype(op)) = OpSum(P, d) Base.similar(opc::DualOpSum, d=similar(dict(opc)); P=ptype(opc)) = DualOpSum(P, d) -Base.(:(==)){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = ptype(a) == ptype(b) && dict(filternz(a)) == dict(filternz(b)) -Base.(:(==)){P,N}(a::DualOpSum{P,N}, b::DualOpSum{P,N}) = a.op == b.op -Base.(:(==))(a::DiracOp, b::DiracOp) = ==(promote(a,b)...) +Base.:(==){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = ptype(a) == ptype(b) && dict(filternz(a)) == dict(filternz(b)) +Base.:(==){P,N}(a::DualOpSum{P,N}, b::DualOpSum{P,N}) = a.op == b.op +Base.:(==)(a::DiracOp, b::DiracOp) = ==(promote(a,b)...) Base.hash(op::AbsOpSum) = hash(dict(filternz(op)), hash(ptype(op))) Base.hash(op::AbsOpSum, h::UInt64) = hash(hash(op), h) @@ -215,9 +215,9 @@ function ktcoeff{T}(ktdict, prodtype, blabel, v, ::Type{T}) return coeff end -Base.(:*)(br::Bra, op::DiracOp) = inner(br,op) -Base.(:*)(op::DiracOp, kt::Ket) = inner(op,kt) -Base.(:*)(a::DiracOp, b::DiracOp) = inner(a,b) +Base.:*(br::Bra, op::DiracOp) = inner(br,op) +Base.:*(op::DiracOp, kt::Ket) = inner(op,kt) +Base.:*(a::DiracOp, b::DiracOp) = inner(a,b) ################################### # Functional Operator Application # @@ -226,10 +226,10 @@ immutable DualFunc f::Function end -Base.(:*)(op::Function, kt::Ket) = op(kt) -Base.(:*)(br::Bra, op::Function) = op(br) -Base.(:*)(op::DualFunc, kt::Ket) = (kt' * op.f)' -Base.(:*)(br::Bra, op::DualFunc) = (op.f * br')' +Base.:*(op::Function, kt::Ket) = op(kt) +Base.:*(br::Bra, op::Function) = op(br) +Base.:*(op::DualFunc, kt::Ket) = (kt' * op.f)' +Base.:*(br::Bra, op::DualFunc) = (op.f * br')' Base.ctranspose(f::Function) = DualFunc(f) Base.ctranspose(fc::DualFunc) = fc.f @@ -280,7 +280,7 @@ tensor{P}(a::OpSum{P}, b::OpSum{P}) = OpSum(ptype(a), tensordict(dict(a), dict(b tensor(a::DualOpSum, b::DualOpSum) = tensor(a.opc, b.opc)' tensor(a::DiracOp, b::DiracOp) = tensor(promote(a,b)...) -Base.(:*)(kt::Ket, br::Bra) = tensor(kt,br) +Base.:*(kt::Ket, br::Bra) = tensor(kt,br) ########### # Scaling # @@ -298,24 +298,24 @@ scale(opc::DualOpSum, c::Number) = DualOpSum(opc.op * (c')) scale(c::Number, opc::DualOpSum) = opc * c -Base.(:*)(c::Number, op::DiracOp) = scale(c, op) -Base.(:*)(op::DiracOp, c::Number) = scale(op, c) -Base.(:/)(op::DiracOp, c::Number) = scale(op, 1/c) +Base.:*(c::Number, op::DiracOp) = scale(c, op) +Base.:*(op::DiracOp, c::Number) = scale(op, c) +Base.:/(op::DiracOp, c::Number) = scale(op, 1/c) ########### # + and - # ########### -Base.(:-)(op::OpSum) = scale(-1, op) -Base.(:-)(opc::DualOpSum) = DualOpSum(-opc.op) +Base.:-(op::OpSum) = scale(-1, op) +Base.:-(opc::DualOpSum) = DualOpSum(-opc.op) -Base.(:+){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, add_merge(dict(a), dict(b))) -Base.(:-){P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, sub_merge(dict(a), dict(b))) +Base.:+{P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, add_merge(dict(a), dict(b))) +Base.:-{P,N}(a::OpSum{P,N}, b::OpSum{P,N}) = similar(b, sub_merge(dict(a), dict(b))) -Base.(:+){P,N}(a::DualOpSum{P,N}, b::DualOpSum{P,N}) = DualOpSum(a.op + b.op) -Base.(:-){P,N}(a::DualOpSum{P,N}, b::DualOpSum{P,N}) = DualOpSum(a.op - b.op) +Base.:+{P,N}(a::DualOpSum{P,N}, b::DualOpSum{P,N}) = DualOpSum(a.op + b.op) +Base.:-{P,N}(a::DualOpSum{P,N}, b::DualOpSum{P,N}) = DualOpSum(a.op - b.op) -Base.(:+)(a::DiracOp, b::DiracOp) = +(promote(a,b)...) -Base.(:-)(a::DiracOp, b::DiracOp) = a + (-b) +Base.:+(a::DiracOp, b::DiracOp) = +(promote(a,b)...) +Base.:-(a::DiracOp, b::DiracOp) = a + (-b) ################# # Normalization # diff --git a/src/outerproduct.jl b/src/outerproduct.jl index 63e832c..b84c01f 100644 --- a/src/outerproduct.jl +++ b/src/outerproduct.jl @@ -27,7 +27,7 @@ Base.promote_rule{G<:OpSum, O<:OuterProduct}(::Type{G}, ::Type{O}) = OpSum Base.eltype(op::OuterProduct) = promote_type(typeof(op.scalar), eltype(op.kt), eltype(op.br)) # these equality/hash functions are pretty inefficient... -Base.(:(==)){P,N}(a::OuterProduct{P,N}, b::OuterProduct{P,N}) = convert(OpSum, a) == convert(OpSum, b) +Base.:(==){P,N}(a::OuterProduct{P,N}, b::OuterProduct{P,N}) = convert(OpSum, a) == convert(OpSum, b) Base.hash(op::OuterProduct) = hash(convert(OpSum, op)) Base.hash(op::OuterProduct, h::UInt64) = hash(hash(op), h) @@ -104,8 +104,8 @@ scale(op::OuterProduct, c::Number) = OuterProduct(op.scalar * c, copy(op.kt), co ########### # + and - # ########### -Base.(:-)(op::OuterProduct) = scale(-1, op) -Base.(:+)(a::OuterProduct, b::OuterProduct) = convert(OpSum, a) + convert(OpSum, b) +Base.:-(op::OuterProduct) = scale(-1, op) +Base.:+(a::OuterProduct, b::OuterProduct) = convert(OpSum, a) + convert(OpSum, b) ################# # Normalization # diff --git a/src/state.jl b/src/state.jl index e2194bb..610ecc1 100644 --- a/src/state.jl +++ b/src/state.jl @@ -44,8 +44,8 @@ Base.copy(br::Bra) = Bra(copy(br.kt)) Base.similar(kt::Ket, d=similar(dict(kt)); P=ptype(kt)) = Ket(P, d) Base.similar(br::Bra, d=similar(dict(br)); P=ptype(br)) = Bra(P, d) -Base.(:(==)){P,N}(a::Ket{P,N}, b::Ket{P,N}) = ptype(a) == ptype(b) && dict(filternz(a)) == dict(filternz(b)) -Base.(:(==)){P,N}(a::Bra{P,N}, b::Bra{P,N}) = a.kt == b.kt +Base.:(==){P,N}(a::Ket{P,N}, b::Ket{P,N}) = ptype(a) == ptype(b) && dict(filternz(a)) == dict(filternz(b)) +Base.:(==){P,N}(a::Bra{P,N}, b::Bra{P,N}) = a.kt == b.kt Base.hash(s::DiracState) = hash(dict(filternz(s)), hash(ptype(s))) Base.hash(s::DiracState, h::UInt64) = hash(hash(s), h) @@ -136,7 +136,7 @@ function inner{N}(br::Bra{KroneckerDelta,N}, kt::Ket{KroneckerDelta,N}) end end -Base.(:*)(br::Bra, kt::Ket) = inner(br,kt) +Base.:*(br::Bra, kt::Ket) = inner(br,kt) inner_eval(f, s::DiracState) = mapcoeffs(x->inner_eval(f,x),s) @@ -175,21 +175,21 @@ scale(c::Number, k::Ket) = k * c scale(b::Bra, c::Number) = Bra(b.kt* (c')) scale(c::Number, b::Bra) = b * c -Base.(:*)(c::Number, s::DiracState) = scale(c, s) -Base.(:*)(s::DiracState, c::Number) = scale(s, c) -Base.(:/)(s::DiracState, c::Number) = scale(s, 1/c) +Base.:*(c::Number, s::DiracState) = scale(c, s) +Base.:*(s::DiracState, c::Number) = scale(s, c) +Base.:/(s::DiracState, c::Number) = scale(s, 1/c) ########### # + and - # ########### -Base.(:-){P,N}(kt::Ket{P,N}) = -1 * kt -Base.(:-)(br::Bra) = Bra(-br.kt) +Base.:-{P,N}(kt::Ket{P,N}) = -1 * kt +Base.:-(br::Bra) = Bra(-br.kt) -Base.(:+){P,N}(a::Ket{P,N}, b::Ket{P,N}) = similar(b, add_merge(dict(a), dict(b))) -Base.(:-){P,N}(a::Ket{P,N}, b::Ket{P,N}) = similar(b, sub_merge(dict(a), dict(b))) +Base.:+{P,N}(a::Ket{P,N}, b::Ket{P,N}) = similar(b, add_merge(dict(a), dict(b))) +Base.:-{P,N}(a::Ket{P,N}, b::Ket{P,N}) = similar(b, sub_merge(dict(a), dict(b))) -Base.(:+)(a::Bra, b::Bra) = Bra(a.kt + b.kt) -Base.(:-)(a::Bra, b::Bra) = Bra(a.kt - b.kt) +Base.:+(a::Bra, b::Bra) = Bra(a.kt + b.kt) +Base.:-(a::Bra, b::Bra) = Bra(a.kt - b.kt) ########## # tensor # @@ -197,8 +197,8 @@ Base.(:-)(a::Bra, b::Bra) = Bra(a.kt - b.kt) tensor{P}(a::Ket{P}, b::Ket{P}) = Ket(ptype(b), tensordict(dict(a), dict(b))) tensor(a::Bra, b::Bra) = tensor(a.kt, b.kt)' -Base.(:*)(a::Ket, b::Ket) = tensor(a,b) -Base.(:*)(a::Bra, b::Bra) = tensor(a,b) +Base.:*(a::Ket, b::Ket) = tensor(a,b) +Base.:*(a::Bra, b::Bra) = tensor(a,b) ################# # Normalization # From 3b0058f2228a96bb6c46635529da8bf3c7579367 Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Tue, 11 Apr 2017 22:53:40 +0530 Subject: [PATCH 11/13] Typealias deprecation fix --- src/opsum.jl | 2 +- src/state.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/opsum.jl b/src/opsum.jl index ceda950..e0063d3 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -3,7 +3,7 @@ ################### abstract type AbsOpSum{P,N,T} <: DiracOp{P,N} end -typealias OpDict{N,T} Dict{OpLabel{N},T} +OpDict{N,T} = Dict{OpLabel{N},T} type OpSum{P,N,T} <: AbsOpSum{P,N,T} ptype::P diff --git a/src/state.jl b/src/state.jl index 610ecc1..e1572f3 100644 --- a/src/state.jl +++ b/src/state.jl @@ -1,7 +1,7 @@ ########### # Ket/Bra # ########### -typealias StateDict{N,T} Dict{StateLabel{N},T} +StateDict{N,T} = Dict{StateLabel{N},T} type Ket{P,N,T} <: DiracState{P,N} ptype::P From 150bbe4bc8cc3d066ab318990aab292edfaf7ee4 Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Wed, 12 Apr 2017 21:06:48 +0530 Subject: [PATCH 12/13] Fix more deprecation errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * "Inner constructor" syntax for parametric types is deprecated. (#11310) of JuliaLang/julia. Fix for the same * @test_approx_eq x y has been deprecated in favor of @test isapprox(x,y) or @test x ≈ y (#4615) of JuliaLang/julia. Partial fix for the same --- src/labels.jl | 8 ++++---- src/opsum.jl | 4 ++-- src/outerproduct.jl | 2 +- src/state.jl | 4 ++-- test/generaltests.jl | 2 +- test/orthotests.jl | 12 ++++++------ 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/labels.jl b/src/labels.jl index edbd79b..e93566e 100644 --- a/src/labels.jl +++ b/src/labels.jl @@ -4,8 +4,8 @@ immutable StateLabel{N} label::NTuple{N} hash::UInt64 - StateLabel(label::NTuple{N}) = new(label, hash(label)) - StateLabel(label::NTuple{N}, h::UInt64) = new(label, h) + StateLabel{N}(label::NTuple{N}) where N = new(label, hash(label)) + StateLabel{N}(label::NTuple{N}, h::UInt64) where N = new(label, h) end StateLabel(s::StateLabel) = s @@ -47,8 +47,8 @@ immutable OpLabel{N} k::StateLabel{N} b::StateLabel{N} hash::UInt64 - OpLabel(k::StateLabel{N}, b::StateLabel{N}) = new(k, b, hash(k, hash(b))) - OpLabel(k::StateLabel{N}, b::StateLabel{N}, h::UInt64) = new(k, b, h) + OpLabel{N}(k::StateLabel{N}, b::StateLabel{N}) where N = new(k, b, hash(k, hash(b))) + OpLabel{N}(k::StateLabel{N}, b::StateLabel{N}, h::UInt64) where N = new(k, b, h) end OpLabel(op::OpLabel) = op diff --git a/src/opsum.jl b/src/opsum.jl index e0063d3..3847146 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -8,8 +8,8 @@ OpDict{N,T} = Dict{OpLabel{N},T} type OpSum{P,N,T} <: AbsOpSum{P,N,T} ptype::P dict::OpDict{N,T} - OpSum(ptype, dict) = new(ptype, dict) - OpSum(ptype, dict::OpDict{0}) = error("Cannot construct a 0-factor operator; did you mean to construct a scalar?") + OpSum{P,N,T}(ptype, dict) where {P,N,T} = new(ptype, dict) + OpSum{P,N,T}(ptype, dict::OpDict{0}) where {P,N,T} = error("Cannot construct a 0-factor operator; did you mean to construct a scalar?") end OpSum{P,N,T}(ptype::P, dict::OpDict{N,T}) = OpSum{P,N,T}(ptype, dict) diff --git a/src/outerproduct.jl b/src/outerproduct.jl index b84c01f..164a072 100644 --- a/src/outerproduct.jl +++ b/src/outerproduct.jl @@ -5,7 +5,7 @@ type OuterProduct{P,N,S,K<:Ket,B<:Bra} <: DiracOp{P,N} scalar::S kt::K br::B - OuterProduct(scalar::S, kt::Ket{P,N}, br::Bra{P,N}) = new(scalar, kt, br) + OuterProduct{P,N,S,K,B}(scalar::S, kt::Ket{P,N}, br::Bra{P,N}) where {P,N,S,K<:Ket,B<:Bra} = new(scalar, kt, br) end OuterProduct{P,N,S}(scalar::S, kt::Ket{P,N}, br::Bra{P,N}) = OuterProduct{P,N,S,typeof(kt),typeof(br)}(scalar, kt, br) diff --git a/src/state.jl b/src/state.jl index e1572f3..ad7179f 100644 --- a/src/state.jl +++ b/src/state.jl @@ -6,8 +6,8 @@ StateDict{N,T} = Dict{StateLabel{N},T} type Ket{P,N,T} <: DiracState{P,N} ptype::P dict::StateDict{N,T} - Ket(ptype, dict) = new(ptype, dict) - Ket(ptype, dict::StateDict{0}) = error("Cannot construct a 0-factor state.") + Ket{P,N,T}(ptype, dict) where {P,N,T} = new(ptype, dict) + Ket{P,N,T}(ptype, dict::StateDict{0}) where {P,N,T} = error("Cannot construct a 0-factor state.") end Ket{P,N,T}(ptype::P, dict::StateDict{N,T}) = Ket{P,N,T}(ptype, dict) diff --git a/test/generaltests.jl b/test/generaltests.jl index 3d1b1e8..533e124 100644 --- a/test/generaltests.jl +++ b/test/generaltests.jl @@ -19,7 +19,7 @@ op_copy[3,0] = 32+im @assert op_copy[3,0] == 32+im @assert tensor(op_copy, op_copy')[(3,1),(1,2)] == 120 -@test_approx_eq norm(qubits) 1 +@test norm(qubits) ≈ 1 @assert ptrace(belldens, 1) == ptrace(belldens, 2) @assert d" act_on(< 1 |, | 'a','b','c' >, 2) == < 1 | 'b' >| 'a','c' > " diff --git a/test/orthotests.jl b/test/orthotests.jl index c4bf9a5..614daf3 100644 --- a/test/orthotests.jl +++ b/test/orthotests.jl @@ -7,16 +7,16 @@ @assert b*k == 56 - 28im @assert b*op*k == 2352 - 3136im -@test_approx_eq qubits'*qubits 1 -@test_approx_eq norm(ptrace(bitdens, 2)) 1 -@test_approx_eq trace(ptrace(bitdens, 2)) 1 -@test_approx_eq trace(ptrace(belldens, 1)^2) .5 -@test_approx_eq purity(bell) 1 +@test qubits'*qubits ≈ 1 +@test norm(ptrace(bitdens, 2)) ≈ 1 +@test trace(ptrace(bitdens, 2)) ≈ 1 +@test trace(ptrace(belldens, 1)^2) ≈ .5 +@test purity(bell) ≈ 1 @rep_op " H | n > = 1/√2 * ( | 0 > + (-1)^n * | 1 > )" 0:1 @assert matrep(H, 0:1) == 1/√2 * [1 1 ; 1 -1] m = 0.5 * [1 1;1 -1] -@test_approx_eq matrep(tensor(H, H), 0:1, 0:1) [m m ; m -m] +@test matrep(tensor(H, H), 0:1, 0:1) ≈ [m m ; m -m] @assert ptrace(ptrace(bitdens, 2), 1) == ptrace(ptrace(bitdens, 1), 2) From 24f365c33bc3742881dc5e2a8a73d1d610cbe5c2 Mon Sep 17 00:00:00 2001 From: TestSubjector Date: Mon, 17 Apr 2017 23:19:01 +0530 Subject: [PATCH 13/13] Minor Fix * Removed enclosing comments from error-prone code * Fixed method matching error for matrep( cannot be tested till str_macros' errors are resolved) --- src/opsum.jl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/opsum.jl b/src/opsum.jl index 3847146..1b0613f 100644 --- a/src/opsum.jl +++ b/src/opsum.jl @@ -411,17 +411,14 @@ function matrep(op::DiracOp, labels...) return T[bra(i...) * op * ket(j...) for i in iter, j in iter] end -#TODO Fix -#= -function matrep(op::Union(DualFunc, Function), labels) +function matrep(op::DualFunc, labels) return [bra(i) * op * ket(j) for i in labels, j in labels] end -function matrep(op::Union(DualFunc, Function), labels...) +function matrep(op::DualFunc, labels...) iter = Iterators.product(labels...) return [bra(i...) * op * ket(j...) for i in iter, j in iter] end -=# ###################### # Printing Functions #