Skip to content

Convert BraketSimulator.Circuit to Braket.Circuit#42

Open
contra-bit wants to merge 2 commits into
amazon-braket:mainfrom
contra-bit:lgh/convert_to_braket
Open

Convert BraketSimulator.Circuit to Braket.Circuit#42
contra-bit wants to merge 2 commits into
amazon-braket:mainfrom
contra-bit:lgh/convert_to_braket

Conversation

@contra-bit

Copy link
Copy Markdown

*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.

Comment thread test/test_braket_integration.jl Outdated
@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
Comment thread ext/BraketSimulatorBraketExt/BraketSimulatorBraketExt.jl Outdated

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
Copy Markdown
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.

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
Copy Markdown
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
end

@testset "BraketSimulator to Braket Conversion" begin

Copy link
Copy Markdown
Contributor

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