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

change: Increase types module coverage to 100% and fix related bugs #595

Merged

Conversation

laurencap
Copy link
Contributor

@laurencap laurencap commented Jul 5, 2023

Issue #, if available:

Description of changes:

Increase code coverage to 100% for types modules of AutoQASM

  • Remove unused code
  • Add lots of tests: various parameter type annotations and various return type annotations
    where various means: bit, bool, int, float, array, program.Program and some other random input to check implicit handling
  • Discovered some bugs:
    • bugfix for returned values that are never instantiated
    • bugfix for return variables initialized with length 0 instead of matching subroutine call return size
    • opened issue for bug: return constant value yields no instructions or incomplete instructions
    • opened issue for bug: passing arguments directly to function call doesn't give the generated variable a name
    • opened issue for bug: Array lengths are hardcoded in subroutine parameter types

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.

@laurencap laurencap requested a review from a team as a code owner July 5, 2023 20:01
@laurencap laurencap requested a review from rmshaffer July 5, 2023 20:01
@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

❗ No coverage uploaded for pull request base (feature/autoqasm@4114432). Click here to learn what that means.
The diff coverage is n/a.

@@                 Coverage Diff                 @@
##             feature/autoqasm     #595   +/-   ##
===================================================
  Coverage                    ?   99.21%           
===================================================
  Files                       ?      146           
  Lines                       ?     8489           
  Branches                    ?     1836           
===================================================
  Hits                        ?     8422           
  Misses                      ?       49           
  Partials                    ?       18           

Copy link
Member

@speller26 speller26 left a comment

Choose a reason for hiding this comment

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

I think this PR does more than just raise coverage; can you include the source change details and change the PR/commit name accordingly?

Comment on lines -123 to -179
@wrap_value.register
def _(node: python_ast.Name, **kwargs: dict):
return oqpy.classical_types.Identifier(node.id)


@wrap_value.register
def _(node: python_ast.BinOp, **kwargs: dict):
return wrap_value(node.op, left=node.left, right=node.right)


@wrap_value.register
def _(node: python_ast.Add, **kwargs: dict):
left = kwargs["left"]
right = kwargs["right"]
return oqpy.base.OQPyBinaryExpression(
getattr(qasm_ast.BinaryOperator, "+"),
wrap_value(left),
wrap_value(right),
)


@wrap_value.register
def _(node: python_ast.Sub, **kwargs: dict):
left = kwargs["left"]
right = kwargs["right"]
return oqpy.base.OQPyBinaryExpression(
getattr(qasm_ast.BinaryOperator, "-"),
wrap_value(left),
wrap_value(right),
)


@wrap_value.register
def _(node: python_ast.Call, **kwargs: dict):
if node.func.id == "range":
arg_values = [wrap_value(arg) for arg in node.args]
return range(*arg_values)


@wrap_value.register
def _(node: python_ast.Compare, **kwargs: dict):
if len(node.ops) > 1:
raise NotImplementedError(node)
op = node.ops[0]
op_map = {
python_ast.Eq: "==",
python_ast.NotEq: "!=",
python_ast.Lt: "<",
python_ast.LtE: "<=",
python_ast.Gt: ">",
python_ast.GtE: ">=",
}
return oqpy.base.OQPyBinaryExpression(
getattr(qasm_ast.BinaryOperator, op_map[type(op)]),
wrap_value(node.left),
wrap_value(node.comparators[0]),
)
Copy link
Member

Choose a reason for hiding this comment

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

Why the removals?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused code, and no known way to reach these code paths. I'd consider this unsupported.

@speller26
Copy link
Member

Codecov Report

❗ No coverage uploaded for pull request base (feature/autoqasm@4114432). Click here to learn what that means.
The diff coverage is n/a.

@@                 Coverage Diff                 @@
##             feature/autoqasm     #595   +/-   ##
===================================================
  Coverage                    ?   99.21%           
===================================================
  Files                       ?      146           
  Lines                       ?     8489           
  Branches                    ?     1836           
===================================================
  Hits                        ?     8422           
  Misses                      ?       49           
  Partials                    ?       18           

I wonder why there's no more diff coverage information...

@laurencap laurencap changed the title change: Increase types module coverage to 100% change: Increase types module coverage to 100% and fix related bugs Jul 5, 2023
@laurencap laurencap requested a review from speller26 July 5, 2023 20:30
Copy link
Member

@speller26 speller26 left a comment

Choose a reason for hiding this comment

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

One suggestion, feel free to take or leave

@laurencap laurencap merged commit d994357 into amazon-braket:feature/autoqasm Jul 5, 2023
28 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.

3 participants