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

Conversation

contra-bit
Copy link

*Issue #38

Description of changes:
Convert BraketSimulator.Circuit to Braket.Circuit

Testing done:
Added base test for conversion

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@contra-bit contra-bit force-pushed the lgh/convert_to_braket branch 2 times, most recently from 54b700b to 2c901f7 Compare August 24, 2024 16:56
@contra-bit contra-bit force-pushed the lgh/convert_to_braket branch from 2c901f7 to 3ccdce9 Compare August 24, 2024 17:01
@@ -154,6 +154,13 @@ 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)

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
Member

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.

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]
brs = [convert(Braket.Instruction, ix) for ix in c.basis_rotation_instructions]
Braket.Circuit(Braket.Moments(), ixs, rts, brs)
Copy link
Member

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.

@@ -27,6 +27,83 @@ using Braket: I, name
end
end

@testset "BraketSimulator to Braket Conversion" begin
Copy link
Member

Choose a reason for hiding this comment

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

These are great but it might be good to have a couple smaller tests too, for example covering the non-empty results situation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants