Skip to content

Commit

Permalink
rm smat (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu authored Feb 10, 2020
1 parent 7540356 commit e3e7145
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/symengine/blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ using SymEngine: BasicType, BasicOp, BasicTrigFunction
op_types = [:Mul, :Add, :Pow]
const BiVarOp = Union{[SymEngine.BasicType{Val{i}} for i in op_types]...}

export smat, @vars
smat(block::AbstractBlock) = mat(Basic, block)
export @vars

simag = SymFunction("Im")
sreal = SymFunction("Re")
Expand Down Expand Up @@ -137,3 +136,7 @@ function SymEngine.subs(::Type{T}, c::AbstractBlock, args...; kwargs...) where {
c = chiparams(c, map(x -> T(subs(x, args...; kwargs...)), getiparams(c))...)
chsubblocks(c, [subs(T, blk, args..., kwargs...) for blk in subblocks(c)])
end

# dumpload
YaoBlocks.tokenize_param(param::Basic) = QuoteNode(Symbol(param))
YaoBlocks.parse_param(x::QuoteNode) = :(Basic($x))
20 changes: 17 additions & 3 deletions test/symengine/blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end

G = Rz(θ) * Rx(γ) * Rz(θ)
m = mat(Basic, G)
@test smat(G) == m
@test mat(G) == m
@test_throws ArgumentError mat(Float64, G)
m = subs.(m, Ref=> Basic(π) / 2), Ref=> Basic(π) / 6))
@test Matrix(mat(Rz/ 2) * Rx/ 6) * Rz/ 2))) Matrix(m)
Expand Down Expand Up @@ -62,11 +62,11 @@ end
@vars a b
@test cos(exp(a + im * b))' == cos(exp(a - im * b))
@test cos(exp(a + im * b))' == cos(exp(a - im * b))
@test smat(Rx(a)) == [
@test mat(Rx(a)) == [
cos(a / 2) -im * sin(a / 2)
-im * sin(a / 2) cos(a / 2)
]
@test smat(Rx(a)') == [
@test mat(Rx(a)') == [
cos(a / 2) im * sin(a / 2)
im * sin(a / 2) cos(a / 2)
]
Expand Down Expand Up @@ -104,3 +104,17 @@ end
ex = subs(ex[], a => 0.9)
@test ComplexF64(ex) expect'(op, reg2)[2][]
end

function check_dumpload(gate::AbstractBlock{N}) where N
gate2 = eval(YaoBlocks.parse_ex(YaoBlocks.dump_gate(gate), N))
gate2 == gate || mat(gate2) mat(gate)
end

@testset "dumpload" begin
# basic types
@vars θ
@test check_dumpload(phase(θ))
@test check_dumpload(shift(θ))
@test check_dumpload(time_evolve(X, θ))
@test check_dumpload(rot(X, θ))
end

0 comments on commit e3e7145

Please sign in to comment.