Skip to content

Add shift and bitwise operations #31

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

Merged
merged 2 commits into from
Apr 25, 2023

Conversation

jmdewart
Copy link
Contributor

@jmdewart jmdewart commented Apr 13, 2023

The PR adds support for classical shift and bitwise operations.

@CLAassistant
Copy link

CLAassistant commented Apr 13, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jmdewart jmdewart changed the title Add shift and logical operations Add shift and bitwise operations Apr 13, 2023
@jmdewart
Copy link
Contributor Author

I'm not sure how to add support for logical operations, one workaround may be:

prog.set(k, ast.BinaryExpression(op=ast.BinaryOperator["&&"], lhs=ast.Identifier(i), rhs=ast.Identifier(j)))

Another possibility is something like:

def __and__(self, other: AstConvertible) -> OQPyBinaryExpression:
    if _is_bool_type(self) or _is_bool_type(other):
        return self._to_binary("&&", self, other)
    return self._to_binary("&", self, other) 

@PhilReinhold
Copy link
Collaborator

I'm not sure how to add support for logical operations, one workaround may be:

I think based on the existing patterns for "non-overloadable syntax" (e.g. for -> oqpy.ForIn) we could just add a separate function for logical operations, e.g.

def logical_and(*args: AstConvertible) -> OQPyBinaryExpression
    ...

def logical_or(*args: AstConvertible) -> OQPyBinaryExpression
    ...

@jmdewart jmdewart force-pushed the add-shift-and-logical-ops branch from 2fe8f4d to 5be0aa8 Compare April 24, 2023 16:49
Copy link
Collaborator

@PhilReinhold PhilReinhold left a comment

Choose a reason for hiding this comment

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

Nice, LGTM! Any comments @jcjaskula-aws?

@PhilReinhold PhilReinhold merged commit ddffe17 into openqasm:main Apr 25, 2023
yitchen-tim added a commit to ajberdy/oqpy that referenced this pull request May 2, 2023
* Fix code of conduct link (openqasm#27)

Co-authored-by: Jean-Christophe Jaskula <[email protected]>

* Add support for arrays (openqasm#28)

* Add array variable

* Enable indexing

* Add a test

* More tests

* Allow specifying type and dimensions in declaration

* Explicitly test setting with variable

* Typing: allow assignment to indexed expressions

* Union type typealias

* Fix comment, provide OQIndexExpression from the module

* Pydocstyle

Why complain now?

* Add base type to ComplexVar and propagate it to arrays

* Bump setuptools from 65.4.1 to 65.5.1 (openqasm#30)

Bumps [setuptools](https://github.com/pypa/setuptools) from 65.4.1 to 65.5.1.
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/CHANGES.rst)
- [Commits](pypa/setuptools@v65.4.1...v65.5.1)

---
updated-dependencies:
- dependency-name: setuptools
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump cryptography from 37.0.4 to 39.0.1 (openqasm#29)

Bumps [cryptography](https://github.com/pyca/cryptography) from 37.0.4 to 39.0.1.
- [Release notes](https://github.com/pyca/cryptography/releases)
- [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst)
- [Commits](pyca/cryptography@37.0.4...39.0.1)

---
updated-dependencies:
- dependency-name: cryptography
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add shift and bitwise operations (openqasm#31)

* Add shift and logical operations

* Add logical OR and AND

---------

Co-authored-by: Mitch D'Ewart <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Anurag Mishra <[email protected]>
Co-authored-by: Jean-Christophe Jaskula <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: jmdewart <[email protected]>
Co-authored-by: Mitch D'Ewart <[email protected]>
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