PennyLaneAI / qml

Introductions to key concepts in quantum programming, as well as tutorials and implementations from cutting-edge quantum computing research.
https://pennylane.ai/qml
Apache License 2.0
512 stars 182 forks source link

[sc-63358] How to use Qiskit 1.0 with PennyLane #1104

Closed isaacdevlugt closed 1 week ago

isaacdevlugt commented 1 month ago

Title: How to use Qiskit 1.0 with PL

Shortcut: https://app.shortcut.com/xanaduai/story/63358/how-to-how-to-use-qiskit-1-0-with-pennylane

github-actions[bot] commented 1 month ago

👋 Hey, looks like you've updated some demos!

🐘 Don't forget to update the dateOfLastModification in the associated metadata files so your changes are reflected in Glass Onion (search and recommendations).

Please hide this comment once the field(s) are updated. Thanks!

github-actions[bot] commented 1 month ago

Thank you for opening this pull request.

You can find the built site at this link.

Deployment Info:

Note: It may take several minutes for updates to this pull request to be reflected on the deployed site.

isaacdevlugt commented 3 weeks ago

Nice work @isaacdevlugt! Just a general comment but I'd just like to highlight something that is distinctly neat about using PL over using Qiskit: You don't need to swap between Estimator and Sampler in order to get what you want.

E.g. in Qiskit if you had some circuit and you wanted both the expectation value and the counts (admittedly, this is a bit of a contrived example), you would need to initialize Estimator and Sampler, and then write a lot of repeated, syntactically complicated code (e.g. expval = estimator.run()[0].data.evs anyone?) to do so. In Pennylane? Easy as return qml.expval(obs), qml.counts(obs). Syntactic sugar like this is always nice IMO.

Okay this is interesting! I tried to get this to work, and you can actually extract more than just counts from Sampler:

from qiskit.primitives import StatevectorSampler

sampler = StatevectorSampler()

job_sampler = sampler.run([qc], shots=1024)
result_sampler = job_sampler.result()[0].data.meas.expectation_values(operators) # or call get_counts()

print(result_sampler)
[0.984375   0.96484375 0.96289062]
austingmhuang commented 3 weeks ago

Okay this is interesting! I tried to get this to work, and you can actually extract more than just counts from Sampler:

from qiskit.primitives import StatevectorSampler

sampler = StatevectorSampler()

job_sampler = sampler.run([qc], shots=1024)
result_sampler = job_sampler.result()[0].data.meas.expectation_values(operators) # or call get_counts()

print(result_sampler)
[0.984375   0.96484375 0.96289062]

Previously you were working with SamplerV1, which didn't have this functionality. SamplerV2 has this functionality though so that's why you're seeing a difference.

isaacdevlugt commented 3 weeks ago

We're nearly ready to :shipit:, just need to figure out that pesky figure alignment 🤔

ikurecic commented 2 weeks ago

Another question I have is about emoji in section titles. image I don't recall ever using this approach in PennyLane Demos. Am I missing something, @isaacdevlugt ? Also, removing them might help with some of the rendering issues for the time being.