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

add qasm measurement #555

Merged
merged 5 commits into from
Jun 12, 2024
Merged

add qasm measurement #555

merged 5 commits into from
Jun 12, 2024

Conversation

MashAliK
Copy link
Contributor

@MashAliK MashAliK commented Jun 7, 2024

For PennyLaneAI/pennylane#5646.
Updated load_qasm to take optional measurements as an argument and added the ability for it to make mid-circuit measurements.
Tests added in tests/test_converter.py.

@trbromley
Copy link
Contributor

Thanks @MashAliK! 🤩 I've requested reviews from our team.

# only X and CNOT queued (not 4 x qml.measure)
assert len(recorder.queue) == 2
# X and CNOT queued with 4 x qml.measure
assert len(recorder.queue) == 6
Copy link
Contributor

Choose a reason for hiding this comment

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

this is what "breaks" by defaulting to None instead of [] above

@lillian542
Copy link
Contributor

This is looking good, thanks @MashAliK 🎉 There are some failing tests, but I don't think they are related to your PR (most of them definitely aren't). We'll work on getting that updated and get back to you soon, don't worry about it for now.

Don't forget to update the changelog to include the change, and list yourself as a contributor! This should definitely go under "Improvements". As mentioned above, we may also want to include a second entry for it in "Breaking changes" - let's see what people think makes sense.

Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

The testing issue from the master branch should be resolved very soon!

In the meantime, there are a couple of minor checks that are failing for documentation and formatting that should be updated here, so I've left a few comments :)

"""Loads a PennyLane template from a QASM string.
Args:
qasm_string (str): the name of the QASM string
measurements (None | pennylane.measurements.MeasurementProcess | list[pennylane.measurements.MeasurementProcess]):
the PennyLane `measurements <https://docs.pennylane.ai/en/stable/introduction/measurements.html>`_
that override the terminal measurements that may be present in the input circuit
Copy link
Contributor

Choose a reason for hiding this comment

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

Something here is causing Sphinx build for the docs to fail - I think you need to add a blank line here before the Returns section for the docs to render correctly

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, looks like the build succeeds now!

tests/test_converter.py Outdated Show resolved Hide resolved
tests/test_converter.py Outdated Show resolved Hide resolved
tests/test_converter.py Outdated Show resolved Hide resolved
Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Thanks @MashAliK, good work! Leaving a couple of suggestions similar to Lillian's.

"""Loads a PennyLane template from a QASM string.
Args:
qasm_string (str): the name of the QASM string
measurements (None | pennylane.measurements.MeasurementProcess | list[pennylane.measurements.MeasurementProcess]):
the PennyLane `measurements <https://docs.pennylane.ai/en/stable/introduction/measurements.html>`_
that override the terminal measurements that may be present in the input circuit
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
that override the terminal measurements that may be present in the input circuit
that override the terminal measurements that may be present in the input circuit


def test_qasm_measure(self):
"""Tests that measurements specified as an argument are added to the converted circuit."""
qasm_string = 'include "qelib1.inc";' "qreg q[2];" "creg c[2];" "h q[0];" "cx q[0], q[1];"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we rewrite the string as the one below in test_qasm_mid_circuit_measure? (i.e., one instruction in one line)

@MashAliK
Copy link
Contributor Author

@lillian542 @obliviateandsurrender Thanks for the suggestions!
I've made an update to try to resolve these problems.

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (530a6af) to head (9405906).
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #555   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          553       554    +1     
=========================================
+ Hits           553       554    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Looks good to go!

Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

Nice work @MashAliK!

@lillian542 lillian542 merged commit a5415ae into PennyLaneAI:master Jun 12, 2024
14 checks passed
trbromley pushed a commit to PennyLaneAI/pennylane that referenced this pull request Jun 12, 2024
**Context:**
Update to `from_qasm` to work with an update to the `pennylane-qiskit`
library (PennyLaneAI/pennylane-qiskit#555) so
that optional measurements can be added as a function argument and
mid-circuit measurements convert correctly.

**Description of the Change:**
Added optional `measurements` argument to `from_qasm`.

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
#5646

---------

Co-authored-by: lillian542 <[email protected]>
Co-authored-by: Utkarsh <[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.

4 participants