Skip to content

PyQASM Integration for sdk - #808

Merged
ryanhill1 merged 18 commits into
mainfrom
pyqasm-integration
Dec 13, 2024
Merged

ryanhill1 merged 18 commits into
mainfrom
pyqasm-integration

Conversation

@TheGupta2012

@TheGupta2012 TheGupta2012 commented Oct 24, 2024 •

Copy link
Copy Markdown
Member

Summary of changes

Changes to the qbraid.passes.qasm

  • Removed analyze.py, format.py and unfold.py modules and migrated functionality and respective tests to pyqasm
  • Functions exclusively required by the sdk in compat.py and decompose.py are kept as is, others moved to pyqasm along with the tests
  • OpenQasm2Program and OpenQasm3Program classes now use the pyqasm methods
  • TODO : rebase method and corresponding tests are marked to be moved to the pyqasm module as part of the rebase PR

Changes to the qbraid.programs

  • qbraid/programs/typer.py catches pyqasm parsing exceptions and raises qbraid custom qasm exceptions. Relevant tests are updated.

Updates to coverage for transpiler

  • Only MS gate in braket is not supported right now, due to a bug in implementation.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey there! It looks like the changelog might need an update.

Please take a moment to edit the CHANGELOG.md with:

  • A brief, one-to-two sentence summary of your changes.
  • A link back to this PR for reference.
  • (Optional) A small working example if you've added new features.

@TheGupta2012
TheGupta2012 marked this pull request as draft October 24, 2024 09:22
@TheGupta2012
TheGupta2012 force-pushed the pyqasm-integration branch 2 times, most recently from 73d6dbb to b1d48a2 Compare November 18, 2024 08:14
@TheGupta2012
TheGupta2012 marked this pull request as ready for review November 18, 2024 08:14
@TheGupta2012

TheGupta2012 commented Nov 18, 2024 •

Copy link
Copy Markdown
Member Author

Will need to release pyqasm==0.1.0 for tests to pass. Passing locally with pyqasm installed from source in testing env

Comment thread qbraid/programs/gate_model/qasm2.py Resolved
Comment thread qbraid/programs/typer.py Resolved
Comment thread requirements-dev.txt Resolved
Comment thread tests/fixtures/braket/gates.py Resolved
Comment thread tests/transpiler/test_transpiler.py Resolved
Comment thread qbraid/programs/typer.py Resolved
Comment thread qbraid/runtime/native/provider.py Resolved
Comment thread requirements.txt Resolved
Comment on lines +326 to +313
ms(1.1,0,0) q[0], q[1];
""",
"Invalid phase value",
),
(
"""
OPENQASM 3.0;
qubit[2] q;
ms(0,-1.5) q[0], q[1];
ms(0,-1.5,0) q[0], q[1];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If OpenQASM supports optional argument to gate definitions, we will want to test both including optional argument and not including it. And if a default value is required, it should be 0.25, not 0.

@TheGupta2012 TheGupta2012 Dec 4, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Afaik, OpenQASM does not support optional args to gates.

  • Either we have two gate definitions for ms with distinct names or,
  • Stick to the max number of args and use x in the arg which is not required such that the term using this arg vanishes when we provide x.

Note that 0.25 might be a default for ionq but not for other providers which support ms gate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Summarizing our conversation about this and putting on record: I think we decided best approach was to add support for both a two and a three parameter ms gate in pyqasm, distinguishing between the two based on the include statement e.g. with a custom ionqnative.inc to signal 0.25 default

@TheGupta2012
TheGupta2012 force-pushed the pyqasm-integration branch 6 times, most recently from a968763 to a8eb767 Compare December 5, 2024 07:19
@codecov

codecov Bot commented Dec 5, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 97.24771% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...nspiler/conversions/openqasm3/openqasm3_to_ionq.py 62.50% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ryanhill1 ryanhill1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rename_qasm_registers was removed with release 0.8.7 so you can take that function out. Additionally, need to satisfy the following code coverage which has dropped. There likely have been testing functions deleted that you may be able to reuse. Because all these had tests running previously

qbraid/passes/qasm/compat.py                                     117     13    89%   136, 159-160, 185, 195, 201-202, 213, 224-230
qbraid/passes/qasm/decompose.py                                   89      1    99%   245
qbraid/programs/gate_model/pytket.py                              84      1    99%   112
qbraid/programs/gate_model/qasm3.py                               55      4    93%   63, 87, 93, 98
qbraid/transpiler/conversions/cirq/cirq_quil_output.py           249      6    98%   366-367, 376-377, 386-387
qbraid/transpiler/conversions/openqasm3/openqasm3_to_ionq.py     107     10    91%   101-102, 148-149, 165-166, 193-194, 210, 248
qbraid/transpiler/conversions/qasm2/cirq_custom.py                73     13    82%   61-65, 123, 126-127, 147-151
qbraid/transpiler/conversions/qasm2/qasm2_to_qasm3.py              9      1    89%   32

@ryanhill1 ryanhill1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These updates look great! It's getting super close. As of your latest commit, it still looks like we're missing ~21 lines of code coverage:

Name                                                           Stmts   Miss  Cover   Missing
--------------------------------------------------------------------------------------------
qbraid/passes/qasm/compat.py                                     127      2    98%   222-223
qbraid/passes/qasm/decompose.py                                   91      1    99%   253
qbraid/programs/gate_model/pytket.py                              84      1    99%   112
qbraid/transpiler/conversions/cirq/cirq_quil_output.py           249      6    98%   366-367, 376-377, 386-387
qbraid/transpiler/conversions/openqasm3/openqasm3_to_ionq.py      98      4    96%   102-103, 195, 233
qbraid/transpiler/conversions/qasm2/cirq_custom.py                73      7    90%   61-65, 126-127
--------------------------------------------------------------------------------------------
TOTAL                                                           7004     21    99%

I know it's annoying, but we need to meet that pytest standard before merging. Like I mentioned before, easiest way is probably just to look through the tests that have been deleted, find the ones that previously hit the lines that are now missing, and re-work them to fit the new format. Or, if you think it would be quicker to write new tests from scratch for this missed lines, that works too.

Comment thread tests/transpiler/cirq/test_from_qasm.py Resolved
Comment on lines +326 to +313
ms(1.1,0,0) q[0], q[1];
""",
"Invalid phase value",
),
(
"""
OPENQASM 3.0;
qubit[2] q;
ms(0,-1.5) q[0], q[1];
ms(0,-1.5,0) q[0], q[1];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Summarizing our conversation about this and putting on record: I think we decided best approach was to add support for both a two and a three parameter ms gate in pyqasm, distinguishing between the two based on the include statement e.g. with a custom ionqnative.inc to signal 0.25 default

Comment thread qbraid/programs/__init__.py Resolved
@ryanhill1

ryanhill1 commented Dec 11, 2024 •

Copy link
Copy Markdown
Member

Let's also bump project version to 0.9.0.dev in this PR.

And also, could you describe in more detail the braket MS gate bug?

@TheGupta2012

Copy link
Copy Markdown
Member Author

These updates look great! It's getting super close. As of your latest commit, it still looks like we're missing ~21 lines of code coverage:

Name                                                           Stmts   Miss  Cover   Missing
--------------------------------------------------------------------------------------------
qbraid/passes/qasm/compat.py                                     127      2    98%   222-223
qbraid/passes/qasm/decompose.py                                   91      1    99%   253
qbraid/programs/gate_model/pytket.py                              84      1    99%   112
qbraid/transpiler/conversions/cirq/cirq_quil_output.py           249      6    98%   366-367, 376-377, 386-387
qbraid/transpiler/conversions/openqasm3/openqasm3_to_ionq.py      98      4    96%   102-103, 195, 233
qbraid/transpiler/conversions/qasm2/cirq_custom.py                73      7    90%   61-65, 126-127
--------------------------------------------------------------------------------------------
TOTAL                                                           7004     21    99%

I know it's annoying, but we need to meet that pytest standard before merging. Like I mentioned before, easiest way is probably just to look through the tests that have been deleted, find the ones that previously hit the lines that are now missing, and re-work them to fit the new format. Or, if you think it would be quicker to write new tests from scratch for this missed lines, that works too.

Okay, I requested re-review as I saw that codecov bot showed all modified lines are covered. Will add more tests!

@TheGupta2012

Copy link
Copy Markdown
Member Author

Let's also bump project version to 0.9.0.dev in this PR.

And also, could you describe in more detail the braket MS gate bug?

The braket MS bug was coming while testing coverage from braket to qiskit. I checked the unitary matrices for Qiskit MS Gate (XX interaction is equivalent to 2 qubit MS gate for qiskit) and braket MS gate. The difference is the phase angle in the sine terms but a weird thing is that it passes for other packages.

@TheGupta2012

Copy link
Copy Markdown
Member Author

Also any idea why is the coverage for 3.10 and 3.11 different from 3.12 CI / Test action?

@ryanhill1

Copy link
Copy Markdown
Member

@TheGupta2012 Yeah it's because pyquil and pyqubo aren't compatible with Python 3.12. So when tox.ini does it's setup using requirements-dev.txt those dependencies are only installed if python < 3.12, and thus those pytests are skipped

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.

2 participants