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

Support for ExplicitPredicate, ExplicitModifier, MultiBitOp #162

Merged
merged 12 commits into from
Apr 10, 2024

Conversation

Asa-Kosto-QTM
Copy link
Collaborator

@Asa-Kosto-QTM Asa-Kosto-QTM commented Apr 5, 2024

Description

Expand support for custom tket classical operation types in phir

Fixes #159, closes #25

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog with any user-facing changes

@qartik

This comment was marked as outdated.

@qartik qartik marked this pull request as draft April 5, 2024 16:17
@qartik qartik marked this pull request as ready for review April 5, 2024 19:47
@qartik qartik requested review from cqc-alec and neal-erickson and removed request for cqc-alec April 5, 2024 19:47
pytket/phir/phirgen.py Outdated Show resolved Hide resolved
@qartik qartik requested a review from qciaran April 5, 2024 19:51
qartik
qartik previously approved these changes Apr 7, 2024
pytket/phir/phirgen.py Outdated Show resolved Hide resolved
pytket/phir/phirgen.py Outdated Show resolved Hide resolved
tests/test_phirgen.py Outdated Show resolved Hide resolved
@qartik qartik force-pushed the 159-expand-classical-ops branch 3 times, most recently from c466dc9 to 798ef4b Compare April 9, 2024 18:55
@qartik qartik requested a review from cqc-alec April 9, 2024 19:40
qartik
qartik previously approved these changes Apr 9, 2024
pytket/phir/phirgen.py Outdated Show resolved Hide resolved
pytket/phir/phirgen.py Outdated Show resolved Hide resolved
pytket/phir/phirgen.py Show resolved Hide resolved
pytket/phir/phirgen.py Outdated Show resolved Hide resolved
pytket/phir/phirgen.py Outdated Show resolved Hide resolved
return {
"cop": "&",
"args": [
{"cop": "==", "args": [arg_to_bit(arg), bval]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to be careful of endianness here. The conditional value in pytket is little-endian, e.g. a value of 2 on the bits [a[0], a[1]] means a[0] == 0 && a[1] == 1. Does PHIR use the same convention?

Copy link
Member

@qartik qartik Apr 10, 2024

Choose a reason for hiding this comment

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

@qciaran would you be able to confirm. I forgot to mention you at #162 (comment), I also had my doubts.

Copy link
Member

Choose a reason for hiding this comment

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

I agree though that the default choice should be little-endian here. While Ciaran confirms, I am pushing the change to update the behavior.

Copy link
Member

Choose a reason for hiding this comment

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

@cqc-alec although I wonder if the bits are explicitly specified like:

        condition_bits=[Bit("b", 1), Bit("b", 2)],
        condition_value=2,

ie, [b[1], b[2]] == 2 (pytket translation of above in the phir comment), is the intention from pytket still that they will be reordered and considered little-endian? I'd imagine the user to write condition_bits=[Bit("b", 2), Bit("b", 1)] if they wanted b[2]=1 and b[1]=0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes that is the intention: the order in which the bits are given corresponds to the little-endian binary expansion of the value. In your example, the condition is b[1] == 0 && b[2] == 1.

Copy link
Collaborator

@qciaran qciaran Apr 10, 2024

Choose a reason for hiding this comment

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

Yeah, in PHIR a[0]==0 && a[1]==1 is the integer value 2. Or: {"cop": "=", "args": [2], "returns": ["b"]} results in b[0]==0 & b[1]==1
Sounds like that should be mentioned in the spec, womp womp.

Copy link
Member

Choose a reason for hiding this comment

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

Filed CQCL/phir#77, this PR seems ready to be merged.

tests/test_phirgen.py Outdated Show resolved Hide resolved
Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com>
@qartik qartik requested a review from cqc-alec April 10, 2024 14:27
Copy link
Collaborator

@qciaran qciaran left a comment

Choose a reason for hiding this comment

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

LGTM

@qartik qartik changed the title 159 expand classical ops Support for ExplicitPredicate, ExplicitModifier, MultiBitOp` Apr 10, 2024
@qartik qartik merged commit bac76d6 into main Apr 10, 2024
6 checks passed
@qartik qartik deleted the 159-expand-classical-ops branch April 10, 2024 15:41
@qartik qartik changed the title Support for ExplicitPredicate, ExplicitModifier, MultiBitOp` Support for ExplicitPredicate, ExplicitModifier, MultiBitOp Apr 10, 2024
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.

Additional Classical Operations Support for more classical operations in phir generation
4 participants