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 measurements operations #405

Merged
merged 12 commits into from
Feb 9, 2024
Merged

Support for measurements operations #405

merged 12 commits into from
Feb 9, 2024

Conversation

obliviateandsurrender
Copy link
Contributor

This adds functionality to support measurements present in a qiskit's QuantumCircuit object or allows to override it using a keyword argument to the converter load function.

Example -

# Building a Qiskit Circuit
qc = qk.QuantumCircuit(2, 2)
qc.h(0)
#qc.measure(0, 0)
qc.rz(0.543, [0])
qc.cx(0, 1)
qc.measure_all()

# Using the `load` functionality in PL
with qml.tape.OperationRecorder() as recorder:
    load(qc, measurements=None)()

>>> recorder.items()
((Hadamard(wires=[0]), {}),
 (measure(wires=[0]), {}),
 (RZ(0.543, wires=[0]), {}),
 (CNOT(wires=[0, 1]), {}),
 (Barrier(wires=[]), {}),
 (measure(wires=[0]), {}),
 (measure(wires=[1]), {}))

# Override it using the `keyword` argument
measurements = [qml.expval(qml.PauliZ(0)), qml.vn_entropy([0])]
with qml.tape.operation_recorder.AnnotatedQueue() as queue:
    load(qc, measurements=measurements)()
>>> queue
AnnotatedQueue([(Hadamard(wires=[0]), {}),
                (measure(wires=[0]), {}),
                (RZ(0.543, wires=[0]), {}),
                (CNOT(wires=[0, 1]), {}),
                (Barrier(wires=[]), {}),
                (expval(PauliZ(wires=[0])), {}),
                (vnentropy(wires=[0]), {})])

@obliviateandsurrender
Copy link
Contributor Author

[sc-56072]

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.

Thanks @obliviateandsurrender ! A couple of comments/suggestions, see what you think :)

tests/test_converter.py Outdated Show resolved Hide resolved
pennylane_qiskit/converter.py Show resolved Hide resolved
pennylane_qiskit/converter.py Outdated Show resolved Hide resolved
pennylane_qiskit/converter.py Show resolved Hide resolved
tests/test_converter.py Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7cbfd9c) 100.00% compared to head (01a4da5) 100.00%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #405   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          312       331   +19     
=========================================
+ Hits           312       331   +19     

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

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.

Thanks @obliviateandsurrender! Looks good to me :)

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

changelog?

@albi3ro albi3ro merged commit ff2e352 into master Feb 9, 2024
8 checks passed
@albi3ro albi3ro deleted the add-meas-support branch February 9, 2024 16:49
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.

None yet

4 participants