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 for StartPreserveBlock and EndPreserveBlock instruct… #94

Merged
merged 1 commit into from
Jul 30, 2021

Conversation

sergei-kag
Copy link
Contributor

@sergei-kag sergei-kag commented Jul 23, 2021

…ions.

Issue #, if available:

Description of changes:
Support added for StartPreserveBlock and EndPreserveBlock instructions. The code between the start and end instructions will not be optimized by removing, reordering, or decomposing. Thus, creating a preserved block of code.

I've also updated the error messages in program_v1.py. There are three code paths that all had the same error message, so I've separated them into unique messages to help with future debugging.

Testing done:

==================================================================================== test session starts =====================================================================================
platform darwin -- Python 3.7.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /usr/local/opt/python/bin/python3.7
cachedir: .pytest_cache
rootdir: .../amazon-braket-schemas-python, configfile: setup.cfg
collected 14 items                                                                                                                                                                           

test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_missing_instructions_property XFAIL                                                                                           [  7%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_non_instruction XFAIL                                                                                                         [ 14%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_wrong_instruction XFAIL                                                                                                       [ 21%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_wrong_compiler_directive XFAIL                                                                                                [ 28%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_partial_non_instruction XFAIL                                                                                                 [ 35%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_partial_non_result XFAIL                                                                                                      [ 42%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_instruction_no_results PASSED                                                                                                 [ 50%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_instruction_no_noise_results PASSED                                                                                           [ 57%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_instruction_with_results PASSED                                                                                               [ 64%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_partial_non_rotation_basis_instruction XFAIL                                                                                  [ 71%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_no_rotation_basis_instruction PASSED                                                                                          [ 78%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_rotation_basis_instruction PASSED                                                                                             [ 85%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_start_preserve_block_instruction PASSED                                                                                       [ 92%]
test/unit_tests/braket/ir/jaqcd/test_program_v1.py::test_end_preserve_block_instruction PASSED                                                                                         [100%]

================================================================================ 7 passed, 7 xfailed in 0.19s ================================================================================
~

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.

@sergei-kag sergei-kag requested a review from a team as a code owner July 23, 2021 22:40
@@ -899,3 +900,40 @@ class Type(str, Enum):
kraus = "kraus"

type = Type.kraus

"""
StartPreserveBLock.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please provide a description of the functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


class EndPreserveBlock(CompilerDirective):
"""
EndPreserveBLock.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please provide a description of the functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

and EndPreserveBlock directives.

Attributes:
directive (List [Start PreserveBlock | EndPreserveBlock])
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: Start PreserveBlock -> StartPreserveBlock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@codecov
Copy link

codecov bot commented Jul 27, 2021

Codecov Report

Merging #94 (ab887d0) into main (ccd659d) will not change coverage.
The diff coverage is 100.00%.

❗ Current head ab887d0 differs from pull request most recent head 621e780. Consider uploading reports for the commit 621e780 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##              main       #94   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           48        48           
  Lines          776       789   +13     
  Branches         8         9    +1     
=========================================
+ Hits           776       789   +13     
Impacted Files Coverage Δ
src/braket/ir/jaqcd/__init__.py 100.00% <ø> (ø)
src/braket/ir/jaqcd/instructions.py 100.00% <100.00%> (ø)
src/braket/ir/jaqcd/program_v1.py 100.00% <100.00%> (ø)
src/braket/ir/jaqcd/shared_models.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ccd659d...621e780. Read the comment docs.

src/braket/ir/jaqcd/instructions.py Outdated Show resolved Hide resolved
src/braket/ir/jaqcd/program_v1.py Show resolved Hide resolved
jheckey
jheckey previously approved these changes Jul 29, 2021
This should be unique among all instruction types.

Examples:
>>> EndPreserveBlock(directive=["EndPreserveBlock"])
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a little redundant. The information carried by the directive is the same as the class name and the type. Do we expect the directive to diverge from the instruction type ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introduced the default directive for StartVerbatimBlock and EndVerbatimBlock classes to reduce the redundancy.


type = Type.end_verbatim_block

directive: str = "EndVerbatimBlock"
Copy link
Contributor

Choose a reason for hiding this comment

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

Interestingly, you can use this to just do a copy-paste: directive: str = __qualname__

@sergei-kag sergei-kag merged commit 85ba365 into main Jul 30, 2021
@sergei-kag sergei-kag deleted the kag/preserve_block branch July 30, 2021 23:17
kshitijc pushed a commit that referenced this pull request Nov 29, 2021
* feature: support for StartPreserveBlock and EndPreserveBlock instructions. (#94)

* prepare release v1.3.0

* update development version to v1.3.1.dev0

* Update copyright headers (#95)

* feature: StartVerbatimBox and EndVerbatimBox (#96)

Added the StartVerbatimBox and EndVerbatimBox instructions.
The code between the start and end instructions will not be modified by
the compiler, thus delineating a "verbatim" box of code.

The astute reader will notice that this is merely a renaming of the
instructions StartVerbatimBlock and EndVerbatimBlock; this change is
marked as a feature to emphasize the incompatibility with v1.3.0.

* prepare release v1.4.0

* update development version to v1.4.1.dev0

* doc: Fix jaqcd typo in README.md (#97)

* prepare release v1.4.0.post0

* update development version to v1.4.1.dev0

Co-authored-by: Sergei-kag-aws <kag@amazon.com>
Co-authored-by: ci <ci>
Co-authored-by: Cody Wang <speller26@gmail.com>
Co-authored-by: Jacky Ko <60188942+kjacky@users.noreply.github.com>
math411 pushed a commit that referenced this pull request Feb 27, 2022
* feature: support for StartPreserveBlock and EndPreserveBlock instructions. (#94)

* prepare release v1.3.0

* update development version to v1.3.1.dev0

* Update copyright headers (#95)

* feature: StartVerbatimBox and EndVerbatimBox (#96)

Added the StartVerbatimBox and EndVerbatimBox instructions.
The code between the start and end instructions will not be modified by
the compiler, thus delineating a "verbatim" box of code.

The astute reader will notice that this is merely a renaming of the
instructions StartVerbatimBlock and EndVerbatimBlock; this change is
marked as a feature to emphasize the incompatibility with v1.3.0.

* prepare release v1.4.0

* update development version to v1.4.1.dev0

* doc: Fix jaqcd typo in README.md (#97)

* prepare release v1.4.0.post0

* update development version to v1.4.1.dev0

* Fix: Pin pydantic and jsonschema versions (#98)

* prepare release v1.4.1

* update development version to v1.4.2.dev0

* feature: Add support for jobs (#99)

* prepare release v1.5.0

* update development version to v1.5.1.dev0

* fix: change annealingDurationRange to a list of floats. (#100)

* prepare release v1.5.1

* update development version to v1.5.2.dev0

Co-authored-by: Sergei-kag-aws <kag@amazon.com>
Co-authored-by: ci <ci>
Co-authored-by: Cody Wang <speller26@gmail.com>
Co-authored-by: Jacky Ko <60188942+kjacky@users.noreply.github.com>
Co-authored-by: Milan <30416311+krneta@users.noreply.github.com>
math411 pushed a commit that referenced this pull request Feb 27, 2022
* feature: support for StartPreserveBlock and EndPreserveBlock instructions. (#94)

* prepare release v1.3.0

* update development version to v1.3.1.dev0

* Update copyright headers (#95)

* feature: StartVerbatimBox and EndVerbatimBox (#96)

Added the StartVerbatimBox and EndVerbatimBox instructions.
The code between the start and end instructions will not be modified by
the compiler, thus delineating a "verbatim" box of code.

The astute reader will notice that this is merely a renaming of the
instructions StartVerbatimBlock and EndVerbatimBlock; this change is
marked as a feature to emphasize the incompatibility with v1.3.0.

* prepare release v1.4.0

* update development version to v1.4.1.dev0

* doc: Fix jaqcd typo in README.md (#97)

* prepare release v1.4.0.post0

* update development version to v1.4.1.dev0

* Fix: Pin pydantic and jsonschema versions (#98)

* prepare release v1.4.1

* update development version to v1.4.2.dev0

* added openqasm program and device capability.

* OpenQASM support initial commit.

* added rigetti/ionq tests; added result_type.py

* updated README.md

* reformatted.

* removed unused import.

* reformatted docstring in openqasm_device_action_properties.py

* reformatted.

* [fix] updated docstring.

* [fix] incoporate Kshitij's comments.

* added openqasm schema header in test_schema_base.py

* reformatted.

* reformatted.

* turn off flake8 for jaqcd results/shared_models import alias.

* updated jaqcd __init__.py to support import results from jaqcd folder.

* empty commit to test github checker.

* empty commit 2 to test github checker.

* Merging in changes from main and updating imports for OpenQASM

* Fixing names and defaults to match docs

* Reformatted with `black`

* Bring in internal changes

* Merge changes from the internal repository (#8)

* Fix typo in supportsPhysicalQubits

cr: https://code.amazon.com/reviews/CR-61878135

* Removing `results` from OpenQASM Program

cr: https://code.amazon.com/reviews/CR-62355578

* Reformat files

Co-authored-by: Srikrishna Jaliparthy <jalipart@amazon.com>
Co-authored-by: Jeffrey Heckey <heckey@amazon.com>

* fix: Revert to old module structure (#9)

Co-authored-by: Sergei-kag-aws <kag@amazon.com>
Co-authored-by: ci <ci>
Co-authored-by: Cody Wang <speller26@gmail.com>
Co-authored-by: Jacky Ko <60188942+kjacky@users.noreply.github.com>
Co-authored-by: Jeffrey Heckey <heckey@amazon.com>
Co-authored-by: shiyunon <shiyunon@amazon.com>
Co-authored-by: Jeff Heckey <jheckey@gmail.com>
Co-authored-by: ℂ𝓞𝔇𝚈 <caw@amazon.com>
Co-authored-by: Srikrishna Jaliparthy <jalipart@amazon.com>
math411 pushed a commit that referenced this pull request Feb 27, 2022
* feature: support for StartPreserveBlock and EndPreserveBlock instructions. (#94)

* prepare release v1.3.0

* update development version to v1.3.1.dev0

* Update copyright headers (#95)

* feature: StartVerbatimBox and EndVerbatimBox (#96)

Added the StartVerbatimBox and EndVerbatimBox instructions.
The code between the start and end instructions will not be modified by
the compiler, thus delineating a "verbatim" box of code.

The astute reader will notice that this is merely a renaming of the
instructions StartVerbatimBlock and EndVerbatimBlock; this change is
marked as a feature to emphasize the incompatibility with v1.3.0.

* prepare release v1.4.0

* update development version to v1.4.1.dev0

* doc: Fix jaqcd typo in README.md (#97)

* prepare release v1.4.0.post0

* update development version to v1.4.1.dev0

* Fix: Pin pydantic and jsonschema versions (#98)

* prepare release v1.4.1

* update development version to v1.4.2.dev0

* feature: Add support for jobs (#99)

* prepare release v1.5.0

* update development version to v1.5.1.dev0

* fix: change annealingDurationRange to a list of floats. (#100)

* prepare release v1.5.1

* update development version to v1.5.2.dev0

* feature: add control-sqrt-not gate (#101)

* feature: add control-sqrt-not gate

Addint this gate makes things like CHSH circuits much more manageable off the bat.

* fix: added tests for CV gate, in line with CY/CZ gates

* fix: updated tox.ini so that unit-tests succeed

* fix: unit tests for CV gate

* fix: revert tox.ini ahead of merge.

Co-authored-by: Mark C <mc@localhost.localdomain>
Co-authored-by: Mark C <mark.carney@gruposantander.com>

* prepare release v1.6.0

* update development version to v1.6.1.dev0

Co-authored-by: Sergei-kag-aws <kag@amazon.com>
Co-authored-by: ci <ci>
Co-authored-by: Cody Wang <speller26@gmail.com>
Co-authored-by: Jacky Ko <60188942+kjacky@users.noreply.github.com>
Co-authored-by: Kshitij Chhabra <kshitijc@users.noreply.github.com>
Co-authored-by: Milan <30416311+krneta@users.noreply.github.com>
Co-authored-by: Mark C <idelta0@gmail.com>
Co-authored-by: Mark C <mc@localhost.localdomain>
Co-authored-by: Mark C <mark.carney@gruposantander.com>
math411 pushed a commit that referenced this pull request Feb 27, 2022
* feature: support for StartPreserveBlock and EndPreserveBlock instructions. (#94)

* prepare release v1.3.0

* update development version to v1.3.1.dev0

* Update copyright headers (#95)

* feature: StartVerbatimBox and EndVerbatimBox (#96)

Added the StartVerbatimBox and EndVerbatimBox instructions.
The code between the start and end instructions will not be modified by
the compiler, thus delineating a "verbatim" box of code.

The astute reader will notice that this is merely a renaming of the
instructions StartVerbatimBlock and EndVerbatimBlock; this change is
marked as a feature to emphasize the incompatibility with v1.3.0.

* prepare release v1.4.0

* update development version to v1.4.1.dev0

* doc: Fix jaqcd typo in README.md (#97)

* prepare release v1.4.0.post0

* update development version to v1.4.1.dev0

* Fix: Pin pydantic and jsonschema versions (#98)

* prepare release v1.4.1

* update development version to v1.4.2.dev0

* feature: Add support for jobs (#99)

* prepare release v1.5.0

* update development version to v1.5.1.dev0

* fix: change annealingDurationRange to a list of floats. (#100)

* prepare release v1.5.1

* update development version to v1.5.2.dev0

* feature: add control-sqrt-not gate (#101)

* feature: add control-sqrt-not gate

Addint this gate makes things like CHSH circuits much more manageable off the bat.

* fix: added tests for CV gate, in line with CY/CZ gates

* fix: updated tox.ini so that unit-tests succeed

* fix: unit tests for CV gate

* fix: revert tox.ini ahead of merge.

Co-authored-by: Mark C <mc@localhost.localdomain>
Co-authored-by: Mark C <mark.carney@gruposantander.com>

* prepare release v1.6.0

* update development version to v1.6.1.dev0

* feature: adding MultiQubitPauliChannel to ir (#103)

* change: Relax requirements from pydantic (#102)

Allow using any version from 1.8.2 to 2.0.0 (excluding). This should be a reasonable balance between stability and flexibility.

* prepare release v1.7.0

* update development version to v1.7.1.dev0

* fix: multiqubit pauli channel with multitarget (#104)

* prepare release v1.7.1

* update development version to v1.7.2.dev0

Co-authored-by: Sergei-kag-aws <kag@amazon.com>
Co-authored-by: ci <ci>
Co-authored-by: Cody Wang <speller26@gmail.com>
Co-authored-by: Jacky Ko <60188942+kjacky@users.noreply.github.com>
Co-authored-by: Kshitij Chhabra <kshitijc@users.noreply.github.com>
Co-authored-by: Milan <30416311+krneta@users.noreply.github.com>
Co-authored-by: Mark C <idelta0@gmail.com>
Co-authored-by: Mark C <mc@localhost.localdomain>
Co-authored-by: Mark C <mark.carney@gruposantander.com>
Co-authored-by: mbeach-aws <85963088+mbeach-aws@users.noreply.github.com>
Co-authored-by: Or Ostrovsky <93072774+orclassiq@users.noreply.github.com>
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.

3 participants