Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed May 6, 2021
1 parent 6833b08 commit 60912f6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ function Base.show(io::IO, ::Type{T}) where {name,T<:GenericRoutine{name}}
mod === Main || print(io, mod, ".")
print(io, name, ")")
end

function Base.show(io::IO, op::Operation)
print(io, routine_name(op.parent))
print(io, "(")
join(io, op.args, ", ")
print(io, ")")
end

function Base.show(io::IO, ::MIME"text/plain", g::Gate)
print(io, g.locations, " => ", g.operation)
end

Base.show(io::IO, g::Chain) = show(io, MIME"text/plain"(), g)

function Base.show(io::IO, ::MIME"text/plain", g::Chain)
print(io, "Chain(")
join(io, g.args, ", ")
print(io, ")")
end

27 changes: 21 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ using MLStyle
using YaoHIR
using Test

@testset "YaoHIR.jl" begin
# Write your tests here.
module TestIntrinsic
using YaoHIR: @intrinsic

@intrinsic X
@intrinsic R(theta::T) where {T <: Real}

end
using YaoHIR: intrinsic_m
intrinsic_m(:X)
intrinsic_m(:(Rx(theta::T) where {T <: Real}))

Chain([Gate(YaoHIR.X, Locations(1)), ])
@test YaoHIR.routine_name(TestIntrinsic.X) == :X
@test YaoHIR.routine_name(TestIntrinsic.R(1.0)) == :R
@test TestIntrinsic.R(1.0).theta == 1.0

display(YaoHIR.X)
display(YaoHIR.Rx(1.0))
display(YaoHIR.Operation(YaoHIR.X, 2.0))

circ = Chain(
Gate(YaoHIR.X, Locations(1)),
Core.SSAValue(1),
Ctrl(Gate(Core.SSAValue(1), Locations(3)), CtrlLocations(2))
)

print(circ_1)

0 comments on commit 60912f6

Please sign in to comment.