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

feature: Add get_compiled_circuit convenience method #787

Merged

Conversation

laurencap
Copy link
Contributor

@laurencap laurencap commented Nov 7, 2023

Add get_compiled_circuit to GateModelQuantumTaskResult

Issue #, if available:
Closes #780

Description of changes:

Proposed method:

compiled_program = task.result().get_compiled_circuit()

For Rigetti and OQC tasks, this could be used instead of the method described here: https://docs.aws.amazon.com/braket/latest/developerguide/braket-compiled-circuits-inspecting.html

Testing done:
New unit tests, local testing with successful quantum tasks ran on hardware

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.

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5408783) 100.00% compared to head (63d50e5) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #787   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          129       129           
  Lines         8363      8372    +9     
  Branches      1862      1865    +3     
=========================================
+ Hits          8363      8372    +9     
Files Coverage Δ
src/braket/tasks/gate_model_quantum_task_result.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@laurencap laurencap marked this pull request as ready for review November 8, 2023 17:53
@laurencap laurencap requested a review from a team as a code owner November 8, 2023 17:53
@laurencap laurencap self-assigned this Nov 8, 2023
@laurencap laurencap requested a review from ajberdy November 8, 2023 17:53
assert result_rigetti.get_compiled_circuit() == quil_program


def test_get_compiled_circuit_oqc(result_oqc, qasm2_program):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: several of these tests/fixtures can be parametrized with pytest instead of duplicated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like I should be able to do something like this -- but afaiu parameter inputs can't be fixtures. Do you know how to do it, beyond accepting the fixture name as a string and looking up the function from it? If you have other more specific recommendations please let me know.

@pytest.mark.parametrize("result,program", [(result_rigetti, quil_program), (result_oqc, qasm2_program)])
def test_get_compiled_circuit(result, program):
    """Test get_compiled_circuit method."""
    assert result.get_compiled_circuit() == program

Copy link
Contributor Author

@laurencap laurencap Nov 8, 2023

Choose a reason for hiding this comment

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

Updated the result fixtures to reduce duplicated code

@laurencap laurencap requested a review from ajberdy November 8, 2023 19:27
@laurencap laurencap merged commit 5ed43f3 into amazon-braket:main Nov 8, 2023
22 checks passed
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.

Convenience method: get compiled circuit
2 participants