amazon-braket-sdk-python icon indicating copy to clipboard operation
amazon-braket-sdk-python copied to clipboard

feat: support Hybrid Job decorator with AutoQASM

Open yitchen-tim opened this issue 2 years ago • 1 comments

Issue #, if available: closes https://github.com/amazon-braket/amazon-braket-sdk-python/issues/839

Description of changes: Draft PR for testing the proposed solution: I made the following change to enable the job decorator + AutoQASM. Still need to add new tests and adapt existing tests.

  • Persist source code of all inner functions of the job decorated function, as py files
  • Upload the py file to the job as input data
  • Replace the source location of all inner functions to a path in the job This change strictly only applies to remote job decorator. When using regular job (ie. without decorator) or no job, there is no change in user code, and there is no artifact about source code.

working example:

import json
from braket.jobs import hybrid_job
from braket.devices import Devices
import braket.experimental.autoqasm as aq
from braket.experimental.autoqasm import instructions as ops

@hybrid_job(
    device=Devices.Amazon.SV1,
    dependencies=["git+https://github.com/amazon-braket/amazon-braket-sdk-python.git@feature/autoqasm#egg=amazon-braket-sdk"],
    local=True
) 
def bell_circuit_job():
    @aq.main
    def bell_circuit():
        ops.h(0)
        ops.cnot(0, 1)

    print(bell_circuit.to_ir())

bell_circuit_job()

Testing done: More complete tests are needed. I tested few examples of aq.main, aq.subroutine, aq.gate, aq.gate_calibration and they all work. Also tested with non-decorator UX, also worked.

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

  • [ ] I have read the CONTRIBUTING doc
  • [ ] I used the commit message format described in CONTRIBUTING
  • [ ] I have updated any necessary documentation, including READMEs and API docs (if appropriate)

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.

yitchen-tim avatar Jan 19 '24 01:01 yitchen-tim

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:exclamation: No coverage uploaded for pull request base (feature/autoqasm@64a331d). Click here to learn what that means.

Additional details and impacted files
@@                 Coverage Diff                 @@
##             feature/autoqasm     #855   +/-   ##
===================================================
  Coverage                    ?   99.77%           
===================================================
  Files                       ?      167           
  Lines                       ?    10287           
  Branches                    ?     2195           
===================================================
  Hits                        ?    10264           
  Misses                      ?       18           
  Partials                    ?        5           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 10 '24 16:02 codecov[bot]

As we discussed offline with @yitchen-tim, we should modify this PR to create a new AutoQASM-specific decorator like @aq.hybrid_job which implements this functionality. This will eliminate any impact to the behavior of the core SDK code, and will also make it simpler to decouple AutoQASM when we are ready to move it to a standalone repo.

rmshaffer avatar Apr 25 '24 17:04 rmshaffer