Skip to content

Commit

Permalink
fix: More coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws committed Oct 7, 2024
1 parent b8867f4 commit ebbca4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ struct PauliEigenvalues{N}
end
PauliEigenvalues(::Val{N}, coeff::Float64=1.0) where {N} = PauliEigenvalues{N}(coeff)
Base.length(p::PauliEigenvalues{N}) where {N} = 2^N
function Base.iterate(p::PauliEigenvalues{N}, ix::Int=1) where {N}
return ix <= length(p) ? (p[ix], ix+1) : nothing
end
Base.iterate(p::PauliEigenvalues{N}, ix::Int=1) where {N} = ix <= length(p) ? (p[ix], ix+1) : nothing

Check warning on line 33 in src/operators.jl

View check run for this annotation

Codecov / codecov/patch

src/operators.jl#L33

Added line #L33 was not covered by tests

Base.getindex(p::PauliEigenvalues{1}, i::Int)::Float64 = getindex((p.coeff, -p.coeff), i)
function Base.getindex(p::PauliEigenvalues{N}, i::Int)::Float64 where N
Expand Down Expand Up @@ -71,8 +69,9 @@ end
Measure() = Measure(-1)
Parametrizable(m::Measure) = NonParametrized()
chars(::Type{Measure}) = ("M",)
chars(m::Measure) = ("M",)
chars(::Measure) = chars(Measure)
qubit_count(::Type{Measure}) = 1
qubit_count(::Measure) = qubit_count(Measure)
ir(m::Measure, target::QubitSet, ::Val{:JAQCD}; kwargs...) = error("measure instructions are not supported with JAQCD.")
function ir(m::Measure, target::QubitSet, ::Val{:OpenQASM}; serialization_properties=OpenQASMSerializationProperties())
instructions = Vector{String}(undef, length(target))
Expand All @@ -92,7 +91,7 @@ Represents an active reset operation on targeted qubit.
struct Reset <: QuantumOperator end
Parametrizable(m::Reset) = NonParametrized()
chars(::Type{Reset}) = ("Reset",)
chars(r::Reset) = ("Reset",)
chars(::Reset) = chars(Reset)
label(::Reset) = "reset"
qubit_count(::Type{Reset}) = 1
qubit_count(r::Reset) = qubit_count(Reset)
Expand All @@ -105,7 +104,7 @@ Represents a barrier operation on targeted qubit.
struct Barrier <: QuantumOperator end
Parametrizable(b::Barrier) = NonParametrized()
chars(::Type{Barrier}) = ("Barrier",)
chars(r::Barrier) = ("Barrier",)
chars(r::Barrier) = chars(Barrier)
label(::Barrier) = "barrier"
qubit_count(::Type{Barrier}) = 1
qubit_count(b::Barrier) = qubit_count(Barrier)
Expand Down
10 changes: 8 additions & 2 deletions test/circuit_timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ using Braket: Instruction, VIRTUAL, PHYSICAL, OpenQASMSerializationProperties
@testset "Barrier, reset, and delay operators" begin
@test Barrier() isa Braket.QuantumOperator
@test Reset() isa Braket.QuantumOperator
@test Delay(Microsecond(200)) isa Braket.QuantumOperator
@test Braket.Parametrizable(Reset()) == Braket.NonParametrized()
@test Braket.Parametrizable(Barrier()) == Braket.NonParametrized()
@test Braket.Parametrizable(Delay(Microsecond(200))) == Braket.NonParametrized()
@test qubit_count(Reset()) == 1
@test qubit_count(Barrier()) == 1
@test qubit_count(Delay(Microsecond(200))) == 1
@test Delay(Microsecond(200)) isa Braket.QuantumOperator
@testset "Equality" for t in (Barrier, Reset)
t1 = t()
t2 = t()
Expand All @@ -17,7 +23,7 @@ using Braket: Instruction, VIRTUAL, PHYSICAL, OpenQASMSerializationProperties
@test Braket.chars(Barrier()) == ("Barrier",)
@test Braket.chars(Reset()) == ("Reset",)
@test Braket.chars(Delay(Nanosecond(4))) == ("Delay(4ns)",)

@test Braket.chars(Delay(Microsecond(4))) == ("Delay(4ms)",)
@testset "To IR" for (t, str) in ((Barrier(), "barrier"),
(Reset(), "reset"),
(Delay(Second(1)), "delay[1s]"),
Expand Down
2 changes: 2 additions & 0 deletions test/measure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ using Braket: Instruction, VIRTUAL, PHYSICAL, OpenQASMSerializationProperties

@testset "Measure operator" begin
@test Measure() isa Braket.QuantumOperator
@test Braket.Parametrizable(Measure()) == Braket.NonParametrized()
@test qubit_count(Measure()) == 1
@testset "Equality" begin
measure1 = Measure()
measure2 = Measure()
Expand Down

0 comments on commit ebbca4d

Please sign in to comment.