Skip to content

Commit

Permalink
Add descriptions for some tests (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
speller26 authored Apr 27, 2024
1 parent 2d79fcb commit f8a580e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/*
12 changes: 6 additions & 6 deletions test/test_gate_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using BraketSimulator: DoubleExcitation, SingleExcitation, matrix_rep, Control
q1_mat = [0 -im; im 0]
q2_mat = [1 0 0 0; 0 1 0 0 ; 0 0 0 -im; 0 0 im 0]
@testset "Inverted gates" begin
@testset for g in [X(), Y(), Z(), H(), GPi(ϕ), GPi2(ϕ), Rx(ϕ), Ry(ϕ), Rz(ϕ), PhaseShift(ϕ), S(), Si(), T(), Ti(), V(), Vi(), U(θ, ϕ, λ), Unitary(q1_mat)]
@testset "1q Gate $g" for g in [X(), Y(), Z(), H(), GPi(ϕ), GPi2(ϕ), Rx(ϕ), Ry(ϕ), Rz(ϕ), PhaseShift(ϕ), S(), Si(), T(), Ti(), V(), Vi(), U(θ, ϕ, λ), Unitary(q1_mat)]
@test inv(matrix_rep(g)) matrix_rep(inv(g))
@test matrix_rep(inv(g)) * matrix_rep(g) Diagonal(ones(2))
sim = StateVectorSimulator(nq, 0)
Expand All @@ -21,7 +21,7 @@ using BraketSimulator: DoubleExcitation, SingleExcitation, matrix_rep, Control
new_sim = evolve!(new_sim, [Instruction(g, [0]), Instruction(inv(g), [0])])
@test new_sim.state_vector sim.state_vector
end
@testset for g in [XX(ϕ), YY(ϕ), ZZ(ϕ), XY(ϕ), ECR(), Swap(), ISwap(), PSwap(ϕ), MS(θ, ϕ, λ), CPhaseShift(ϕ), CPhaseShift00(ϕ), CPhaseShift01(ϕ), CPhaseShift10(ϕ), Unitary(q2_mat), CNot(), CY(), CZ(), CV()]
@testset "2q Gate $g" for g in [XX(ϕ), YY(ϕ), ZZ(ϕ), XY(ϕ), ECR(), Swap(), ISwap(), PSwap(ϕ), MS(θ, ϕ, λ), CPhaseShift(ϕ), CPhaseShift00(ϕ), CPhaseShift01(ϕ), CPhaseShift10(ϕ), Unitary(q2_mat), CNot(), CY(), CZ(), CV()]
@test inv(matrix_rep(g)) matrix_rep(inv(g))
@test matrix_rep(inv(g)) * matrix_rep(g) Diagonal(ones(4))
sim = StateVectorSimulator(nq, 0)
Expand All @@ -31,7 +31,7 @@ using BraketSimulator: DoubleExcitation, SingleExcitation, matrix_rep, Control
new_sim = evolve!(new_sim, [Instruction(g, [0, 1]), Instruction(inv(g), [0, 1])])
@test new_sim.state_vector sim.state_vector atol=1e-5
end
@testset for g in [CCNot(), CSwap()]
@testset "3q Gate $g" for g in [CCNot(), CSwap()]
@test inv(matrix_rep(g)) matrix_rep(inv(g))
@test matrix_rep(inv(g)) * matrix_rep(g) Diagonal(ones(8))
sim = StateVectorSimulator(nq, 0)
Expand All @@ -43,7 +43,7 @@ using BraketSimulator: DoubleExcitation, SingleExcitation, matrix_rep, Control
end
end
@testset "Exponentiated gates" begin
@testset "Gate $g, pow $pow" for g in [X(), Y(), Z(), H(), GPi(ϕ), GPi2(ϕ), Rx(ϕ), Ry(ϕ), Rz(ϕ), PhaseShift(ϕ), S(), Si(), T(), Ti(), V(), Vi(), U(θ, ϕ, λ), Unitary(q1_mat), MultiQubitPhaseShift{1}(ϕ)], pow in (0, 1, 2, 3, 4)
@testset "1q Gate $g, pow $pow" for g in [X(), Y(), Z(), H(), GPi(ϕ), GPi2(ϕ), Rx(ϕ), Ry(ϕ), Rz(ϕ), PhaseShift(ϕ), S(), Si(), T(), Ti(), V(), Vi(), U(θ, ϕ, λ), Unitary(q1_mat), MultiQubitPhaseShift{1}(ϕ)], pow in (0, 1, 2, 3, 4)
sim = StateVectorSimulator(nq, 0)
new_sim = StateVectorSimulator(nq, 0)
instructions = vcat([Instruction(H(), [q]) for q in 0:nq-1], [Instruction(g^pow, [0])])
Expand All @@ -53,7 +53,7 @@ using BraketSimulator: DoubleExcitation, SingleExcitation, matrix_rep, Control
new_sim = evolve!(new_sim, new_instructions)
@test new_sim.state_vector sim.state_vector
end
@testset "Gate $g, pow $pow" for g in [XX(ϕ), YY(ϕ), ZZ(ϕ), XY(ϕ), CNot(), CY(), CZ(), CV(), ECR(), Swap(), ISwap(), PSwap(ϕ), MS(θ, ϕ, λ), CPhaseShift(ϕ), CPhaseShift00(ϕ), CPhaseShift01(ϕ), CPhaseShift10(ϕ), Unitary(q2_mat), MultiQubitPhaseShift{2}(ϕ), Control(MultiQubitPhaseShift{2}(ϕ), (0,0)), Control(X(), (1,))], pow in (0, 1, 2, 3, 4)
@testset "2q Gate $g, pow $pow" for g in [XX(ϕ), YY(ϕ), ZZ(ϕ), XY(ϕ), CNot(), CY(), CZ(), CV(), ECR(), Swap(), ISwap(), PSwap(ϕ), MS(θ, ϕ, λ), CPhaseShift(ϕ), CPhaseShift00(ϕ), CPhaseShift01(ϕ), CPhaseShift10(ϕ), Unitary(q2_mat), MultiQubitPhaseShift{2}(ϕ), Control(MultiQubitPhaseShift{2}(ϕ), (0,0)), Control(X(), (1,))], pow in (0, 1, 2, 3, 4)
sim = StateVectorSimulator(nq, 0)
new_sim = StateVectorSimulator(nq, 0)
instructions = vcat([Instruction(H(), [q]) for q in 0:nq-1], [Instruction(g^pow, [0, 1])])
Expand All @@ -66,7 +66,7 @@ using BraketSimulator: DoubleExcitation, SingleExcitation, matrix_rep, Control
new_sim = evolve!(new_sim, new_instructions)
@test new_sim.state_vector sim.state_vector
end
@testset "Gate $g, pow $pow" for g in [CCNot(), CSwap()], pow in (0, 1, 2, 3, 4)
@testset "3q Gate $g, pow $pow" for g in [CCNot(), CSwap()], pow in (0, 1, 2, 3, 4)
sim = StateVectorSimulator(nq, 0)
new_sim = StateVectorSimulator(nq, 0)
instructions = vcat([Instruction(H(), [q]) for q in 0:nq-1], [Instruction(g^pow, [0, 1, 3])])
Expand Down
4 changes: 2 additions & 2 deletions test/test_observables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ single_qubit_tests = [
end
@test collect(eigvals(obs)) collect(eigenvalues)
end
@testset "Tensor product of standard gates" begin
@testset "Tensor product of Pauli-like (with eigenvalues ±1) observables" begin
tensor = Observables.TensorProduct([
Observables.H(),
Observables.X(),
Expand All @@ -36,7 +36,7 @@ single_qubit_tests = [
@test actual_gates[2] == Braket.basis_rotation_gates(Observables.X())
@test actual_gates[4] == Braket.basis_rotation_gates(Observables.Y())
end
@testset "Tensor product of nonstandard gates" begin
@testset "Tensor product of arbitrary observables" begin
tensor = Observables.TensorProduct([
Observables.H(),
Observables.I(),
Expand Down
18 changes: 9 additions & 9 deletions test/test_python_ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using Test, PythonCall, BraketSimulator, Braket
py_mat = pylist([pylist([pylist([0.0; 0.0]); pylist([1.0; 0.0])]); pylist([pylist([1.0; 0.0]); pylist([0.0; 0.0])])])
py_sim_mat = np.array(pylist([pylist([0.0, 1.0]); pylist([1.0, 0.0])]))
@testset "Gates" begin
@testset for (jl_gate, py_gate, py_sim_gate) in zip(
@testset "1q static gate $jl_gate" for (jl_gate, py_gate, py_sim_gate) in zip(
[Braket.I(), H(), X(), Y(), Z(), V(), Vi(), T(), Ti(), S(), Si(), Unitary(jl_mat)],
[
braket_ixs.I(target=0),
Expand Down Expand Up @@ -52,7 +52,7 @@ using Test, PythonCall, BraketSimulator, Braket
angle = π / 3.5
angle2 = π / 5.2
angle3 = π / 0.6
@testset for (jl_gate, py_gate, py_sim_gate) in zip(
@testset "1q 1-parameter gate $jl_gate" for (jl_gate, py_gate, py_sim_gate) in zip(
[Rx(angle), Ry(angle), Rz(angle), PhaseShift(angle)],
[
braket_ixs.Rx(target=0, angle=angle),
Expand All @@ -73,7 +73,7 @@ using Test, PythonCall, BraketSimulator, Braket
@test pyconvert(Braket.Instruction, py_gate) == Braket.Instruction(jl_gate, 0)
@test pyconvert(Braket.Instruction, py_sim_gate) == Braket.Instruction(jl_gate, 0)
end
@testset for (jl_gate, py_sim_gate) in zip(
@testset "1q 1-parameter gate $jl_gate" for (jl_gate, py_sim_gate) in zip(
[
GPi(angle),
GPi2(angle),
Expand All @@ -87,7 +87,7 @@ using Test, PythonCall, BraketSimulator, Braket
)
@test pyconvert(Braket.Instruction, py_sim_gate) == Braket.Instruction(jl_gate, 0)
end
@testset for (jl_gate, py_sim_gate, targets) in zip(
@testset "3-parameter gate $jl_gate" for (jl_gate, py_sim_gate, targets) in zip(
[
MS(angle, angle2, angle3),
U(angle, angle2, angle3),
Expand All @@ -103,7 +103,7 @@ using Test, PythonCall, BraketSimulator, Braket
)
@test pyconvert(Braket.Instruction, py_sim_gate) == Braket.Instruction(jl_gate, targets)
end
@testset for (jl_gate, py_gate, py_sim_gate) in zip(
@testset "2q static gate $jl_gate" for (jl_gate, py_gate, py_sim_gate) in zip(
[CNot(), CY(), CZ(), CV(), Swap(), ISwap(), ECR()],
[
braket_ixs.CNot(control=0, target=1),
Expand All @@ -130,7 +130,7 @@ using Test, PythonCall, BraketSimulator, Braket
@test pyconvert(Braket.Instruction, py_gate) == Braket.Instruction(jl_gate, [0, 1])
@test pyconvert(Braket.Instruction, py_sim_gate) == Braket.Instruction(jl_gate, [0, 1])
end
@testset for (jl_gate, py_gate, py_sim_gate) in zip(
@testset "2q 1-parameter gate $jl_gate" for (jl_gate, py_gate, py_sim_gate) in zip(
[
XX(angle),
XY(angle),
Expand Down Expand Up @@ -171,7 +171,7 @@ using Test, PythonCall, BraketSimulator, Braket
@test pyconvert(Braket.Instruction, py_gate) == Braket.Instruction(jl_gate, [0, 1])
@test pyconvert(Braket.Instruction, py_sim_gate) == Braket.Instruction(jl_gate, [0, 1])
end
@testset for (jl_gate, py_gate, py_sim_gate) in zip(
@testset "3q static gate $jl_gate" for (jl_gate, py_gate, py_sim_gate) in zip(
[CCNot(), CSwap()],
[braket_ixs.CCNot(controls=pylist([0, 1]), target=2),
braket_ixs.CSwap(control=0, targets=pylist([1, 2]))],
Expand All @@ -191,7 +191,7 @@ using Test, PythonCall, BraketSimulator, Braket
proby = 0.2
probz = 0.3
@testset "Noises" begin
@testset for (jl_noise, py_noise, py_sim_noise) in zip(
@testset "1q noise $jl_noise" for (jl_noise, py_noise, py_sim_noise) in zip(
[
BitFlip(prob),
PhaseFlip(prob),
Expand Down Expand Up @@ -229,7 +229,7 @@ using Test, PythonCall, BraketSimulator, Braket
@test pyconvert(Braket.Instruction, py_noise) == Braket.Instruction(jl_noise, 0)
@test pyconvert(Braket.Instruction, py_sim_noise) == Braket.Instruction(jl_noise, 0)
end
@testset for (jl_noise, py_noise, py_sim_noise) in zip(
@testset "2q noise $jl_noise" for (jl_noise, py_noise, py_sim_noise) in zip(
[TwoQubitDepolarizing(prob), TwoQubitDephasing(prob)],
[
braket_ixs.TwoQubitDepolarizing(targets=pylist([0, 1]), probability=prob),
Expand Down
1 change: 0 additions & 1 deletion test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ using Test, BraketSimulator
@test BraketSimulator._index_to_endian_bits(ix, 12) ==
reverse(digits(ix, base = 2, pad = 12))
end

end

0 comments on commit f8a580e

Please sign in to comment.