Skip to content

Commit

Permalink
fix: Semgrep
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws committed Aug 26, 2024
1 parent ad78abc commit f11684d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/BraketSimulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,26 @@ function _generate_results(
return results
end

_translate_result_type(r::IR.Amplitude, qc::Int) = Amplitude(r.states)
_translate_result_type(r::IR.StateVector, qc::Int) = StateVector()
_translate_result_type(r::IR.Amplitude) = Amplitude(r.states)
_translate_result_type(r::IR.StateVector) = StateVector()

Check warning on line 156 in src/BraketSimulator.jl

View check run for this annotation

Codecov / codecov/patch

src/BraketSimulator.jl#L156

Added line #L156 was not covered by tests
# The IR result types support `nothing` as a valid option for the `targets` field,
# however `Result`s represent this with an empty `QubitSet` for type
# stability reasons. Here we take a `nothing` value for `targets` and translate it
# to apply to all qubits.
_translate_result_type(r::IR.DensityMatrix, qc::Int) = DensityMatrix(r.targets)
_translate_result_type(r::IR.Probability, qc::Int) = Probability(r.targets)
_translate_result_type(r::IR.DensityMatrix) = DensityMatrix(r.targets)

Check warning on line 161 in src/BraketSimulator.jl

View check run for this annotation

Codecov / codecov/patch

src/BraketSimulator.jl#L161

Added line #L161 was not covered by tests
_translate_result_type(r::IR.Probability) = Probability(r.targets)
for (RT, IRT) in ((:Expectation, :(IR.Expectation)), (:Variance, :(IR.Variance)), (:Sample, :(IR.Sample)))
@eval begin
function _translate_result_type(r::$IRT, qc::Int)
obs = StructTypes.constructfrom(Observables.Observable, r.observable)
function _translate_result_type(r::$IRT)
obs = StructTypes.constructfrom(Observables.Observable, r.observable)
$RT(obs, QubitSet(r.targets))
end
end
end
_translate_result_types(results::Vector{AbstractProgramResult}, qubit_count::Int) = map(result->_translate_result_type(result, qubit_count), results)
_translate_result_types(results::Vector{AbstractProgramResult}) = map(_translate_result_type, results)

function _compute_exact_results(d::AbstractSimulator, program::Program, qubit_count::Int)
result_types = _translate_result_types(program.results, qubit_count)
result_types = _translate_result_types(program.results)
_validate_result_types_qubits_exist(result_types, qubit_count)
return _generate_results(result_types, d)
end
Expand Down Expand Up @@ -220,7 +220,7 @@ end
Apply any `inputs` provided for the simulation. Return the `Program`
(with bound parameters) and the qubit count of the circuit.
"""
function _prepare_program(circuit_ir::Program, inputs::Dict{String, <:Any}, shots::Int) #nosemgrep
function _prepare_program(circuit_ir::Program, inputs::Dict{String, <:Any}, shots::Int) # nosemgrep
operations::Vector{Instruction} = circuit_ir.instructions
symbol_inputs = Dict(Symbol(k) => v for (k, v) in inputs)
operations = [bind_value!(operation, symbol_inputs) for operation in operations]
Expand Down
2 changes: 1 addition & 1 deletion src/circuit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ julia> qubit_count(c)
qubit_count(c::Circuit) = length(qubits(c))
qubit_count(p::Program) = length(qubits(p))

function Base.convert(::Type{Program}, c::Circuit)
function Base.convert(::Type{Program}, c::Circuit) # nosemgrep
lowered_rts = map(StructTypes.lower, c.result_types)
header = braketSchemaHeader("braket.ir.jaqcd.program" ,"1")
return Program(header, c.instructions, lowered_rts, c.basis_rotation_instructions)
Expand Down
4 changes: 2 additions & 2 deletions src/custom_gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mutable struct DoubleExcitation <: AngledGate{1}
new(angle, Float64(pow_exponent))
end
qubit_count(::Type{DoubleExcitation}) = 4
function matrix_rep_raw(g::DoubleExcitation, ϕ)
function matrix_rep_raw(::DoubleExcitation, ϕ) # nosemgrep
sθ, cθ = sincos/2.0)
mat = diagm(ones(ComplexF64, 16))
mat[4, 4] =
Expand All @@ -22,7 +22,7 @@ mutable struct SingleExcitation <: AngledGate{1}
new(angle, Float64(pow_exponent))
end
qubit_count(::Type{SingleExcitation}) = 2
matrix_rep_raw(g::SingleExcitation, ϕ) = ((sθ, cθ) = sincos/2.0); return SMatrix{4,4,ComplexF64}(complex(1.0), 0, 0, 0, 0, cθ, -sθ, 0, 0, sθ, cθ, 0, 0, 0, 0, complex(1.0)))
matrix_rep_raw(::SingleExcitation, ϕ) = ((sθ, cθ) = sincos/2.0); return SMatrix{4,4,ComplexF64}(complex(1.0), 0, 0, 0, 0, cθ, -sθ, 0, 0, sθ, cθ, 0, 0, 0, 0, complex(1.0)))
"""
MultiRz(angle)
Expand Down

0 comments on commit f11684d

Please sign in to comment.