Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert BraketSimulator.Circuit to Braket.Circuit #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
convert the instruction, do not use BraketSimulator.Program
  • Loading branch information
contra-bit committed Sep 1, 2024
commit 3ee97852a3786a605417a65f5c791c1f41379315
8 changes: 7 additions & 1 deletion ext/BraketSimulatorBraketExt/BraketSimulatorBraketExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ function Base.convert(::Type{BraketSimulator.Program}, p::Braket.Program)
end
Base.convert(::Type{Braket.AbstractProgram}, p::BraketSimulator.Program) = Braket.Program(Braket.braketSchemaHeader("braket.ir.jaqcd.program", "1"), [convert(Braket.Instruction, ix) for ix in p.instructions],[convert(Braket.AbstractProgramResult, rt) for rt in p.results], [convert(Braket.Instruction, ix) for ix in p.basis_rotation_instructions])
Base.convert(::Type{Braket.AbstractProgram}, p::BraketSimulator.OpenQasmProgram) = Braket.OpenQasmProgram(Braket.braketSchemaHeader("braket.ir.openqasm.program", "1"), p.source, p.inputs)
Base.convert(::Type{Braket.Circuit}, c::BraketSimulator.Circuit) = convert(Braket.Circuit, convert(Braket.AbstractProgram, BraketSimulator.Program(c)))

function Base.convert(::Type{Braket.Circuit}, c::BraketSimulator.Circuit)
ixs = [convert(Braket.Instruction, ix) for ix in c.instructions]
rts = isempty(c.result_types) ? Braket.Result[] : [convert(Braket.Result, rt) for rt in c.result_types]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the isempty check here,
rts = Braket.Result[convert(Braket.Result, rt) for rt in c.result_types] should be enough.

brs = [convert(Braket.Instruction, ix) for ix in c.basis_rotation_instructions]
Braket.Circuit(Braket.Moments(), ixs, rts, brs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use add_instruction! for the instructions to populate the moments, so that the returned Braket.Circuit can have noise models applied correctly.

end

function __init__()
Braket._simulator_devices[]["braket_dm_v2"] =
Expand Down
Loading