Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sov-trotter committed May 21, 2021
1 parent c093eb7 commit 7b448d4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/qbir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function convert_to_qbir(inst)
locs[nc+1:end] => name_index(name[nc+1:end], x.params),
)
elseif name == "measure"
put(n, locs =>Yao.Measure(locs...))
put(n, locs => Yao.Measure(locs...))
else
put(n, locs => name_index(name, x.params))
end
Expand Down
64 changes: 50 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,29 @@ using Test
put(2 => Y),
put(3 => Z),
put(2 => T),
put(2 => I2),
swap(1, 2),
put(3 => Ry(0.7)),
control(2, 1 => Y),
control(3, 2 => Z),
)
qc1 = chain(3, put(1 => H), put(3 => Rx(0.7)), control(2, 1 => Y), control(3, 2 => Z), put(1=>Yao.Measure(1)))
qc1 = chain(
3,
put(1 => H),
put(3 => Rx(0.7)),
control(2, 1 => Y),
control(3, 2 => Z),
put(1 => Yao.Measure(1)),
)

header = Dict("description" => "test circuits")
exp_header = [Dict("description" => "1"), Dict("description" => "2")]
circuits = [qc, qc1]
circuits = [qc, qc1]

q = convert_to_qobj(circuits, id = "test", header = header, exp_header = exp_header)
q1 = convert_to_qobj(circuits)
q2 = convert_to_qobj(circuits, exp_header = exp_header)

set = [q, q1, q2]
for i in set
experiments = i.experiments
Expand All @@ -35,17 +43,45 @@ using Test
ir = convert_to_qbir(inst)
@test ir == circuits[i]
end

qc_inst = chain(1, put(1 => YaoBlocksQobj.U1{Float64}(2)),
put(1 => YaoBlocksQobj.U2{Float64}(1, 0.7)),
put(1 => YaoBlocksQobj.U3{Float64}(0, 1, 0.7)))

inst = [
qc_inst = chain(
1,
put(1 => YaoBlocksQobj.U1{Float64}(2)),
put(1 => YaoBlocksQobj.U2{Float64}(1, 0.7)),
put(1 => YaoBlocksQobj.U3{Float64}(0, 1, 0.7)),
)

inst = [
IBMQClient.Schema.Gate("u1", [0], [2], nothing, nothing),
IBMQClient.Schema.Gate("u2", [0], [1 , 0.7], nothing, nothing),
IBMQClient.Schema.Gate("u3", [0],[0,1, 0.7], nothing, nothing),
]
IBMQClient.Schema.Gate("u2", [0], [1, 0.7], nothing, nothing),
IBMQClient.Schema.Gate("u3", [0], [0, 1, 0.7], nothing, nothing),
]

@test qc_inst == convert_to_qbir(inst)
end
@test qc_inst == convert_to_qbir(inst)
end

@testset "qbir misc." begin
@test YaoBlocksQobj.mat(Number, YaoBlocksQobj.U1(0.7)) Number[
1 0
0 exp(im * 0.7)
]

@test YaoBlocksQobj.mat(Number, YaoBlocksQobj.U2(0.7, 0.5)) Number[
1/√2 (-exp(im * 0.5))/√2
(exp(im * 0.7))/√2 (exp(im * (1.2)))/√2
]

@test YaoBlocksQobj.mat(Number, YaoBlocksQobj.U3(0.7, 0.5, 0.2)) Number[
cos(0.7 / 2) -sin(0.7 / 2)*exp(im * 0.2)
sin(0.7 / 2)*exp(im * 0.5) cos(0.7 / 2)*exp(im * (0.7))
]

@test YaoBlocksQobj.iparams_eltype(YaoBlocksQobj.U1(0.7)) == Float64
@test YaoBlocksQobj.iparams_eltype(YaoBlocksQobj.U2(0.7, 0.5)) == Float64
@test YaoBlocksQobj.iparams_eltype(YaoBlocksQobj.U3(0.7, 0.5, 0.2)) == Float64

@test YaoBlocksQobj.getiparams(YaoBlocksQobj.U1(0.7)) == (0.7)
@test YaoBlocksQobj.getiparams(YaoBlocksQobj.U2(0.7, 0.5)) == (0.7, 0.5)
@test YaoBlocksQobj.getiparams(YaoBlocksQobj.U3(0.7, 0.5, 0.2)) == (0.7, 0.5, 0.2)
end
end

0 comments on commit 7b448d4

Please sign in to comment.