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: support FreeParameter binding via make_bound_program #779

Merged

Conversation

laurencap
Copy link
Contributor

@laurencap laurencap commented Nov 1, 2023

Issue #, if available:
Closes #769

Description of changes:

Support make_bound_program

@aq.main
def my_circuit(main_argument: float):
    free_param = FreeParameter("alpha")
    rx(0, main_argument)
    rx(1, free_param)
    measure([0, 1])

my_circuit(3.14/2).make_bound_program({"alpha": 3.14}).to_ir()

The name and signature is patterned after make_bound_circuit. This name also helps inform the user that the method will make and return a new object, with the original left unchanged.

    def make_bound_program(self, param_values: dict[str, float]) -> Program:
    def make_bound_circuit(self, param_values: dict[str, Number], strict: bool = False) -> Circuit:

Testing done:

New unit tests

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 1, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (3dd806e) 100.00% compared to head (4ba90f2) 99.98%.

❗ Current head 4ba90f2 differs from pull request most recent head f838ddd. Consider uploading reports for the commit f838ddd to get more accurate results

Additional details and impacted files
@@                 Coverage Diff                  @@
##           feature/autoqasm     #779      +/-   ##
====================================================
- Coverage            100.00%   99.98%   -0.02%     
====================================================
  Files                   163      163              
  Lines                  9761     9773      +12     
  Branches               2080     2085       +5     
====================================================
+ Hits                   9761     9772      +11     
- Partials                  0        1       +1     
Files Coverage Δ
src/braket/experimental/autoqasm/api.py 100.00% <100.00%> (ø)
...rc/braket/experimental/autoqasm/program/program.py 99.64% <93.33%> (-0.36%) ⬇️

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

@laurencap laurencap self-assigned this Nov 2, 2023
@laurencap laurencap marked this pull request as ready for review November 3, 2023 17:34
@laurencap laurencap requested a review from a team as a code owner November 3, 2023 17:34
Copy link
Contributor

@rmshaffer rmshaffer left a comment

Choose a reason for hiding this comment

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

I like the API choice! Left a few minor comments, and also it would be good to get @jcjaskula-aws's opinion on the oqpy program manipulation here.

src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
@jcjaskula-aws
Copy link
Contributor

Adding some thoughts, if the IODeclaration does not need to be added in-place, we could investigate the use of _add_var.

@laurencap laurencap force-pushed the lcap/bind-parameters branch from 63c146d to 435ff75 Compare November 3, 2023 20:10
@jcjaskula-aws
Copy link
Contributor

jcjaskula-aws commented Nov 3, 2023

I like the API choice! Left a few minor comments, and also it would be good to get @jcjaskula-aws's opinion on the oqpy program manipulation here.

Following up my comments, I'm proposing to explore something using _add_var.

@rmshaffer rmshaffer self-requested a review November 6, 2023 15:30
@laurencap laurencap merged commit 9bfd34c into amazon-braket:feature/autoqasm Nov 6, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants