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

Equivalent 'plot distribution' functionality similar to qiskit implemented for PennyLane for quick circuit probability outputs. #5193

Open
JustinWoodring opened this issue Feb 10, 2024 · 8 comments
Labels
enhancement ✨ New feature or request

Comments

@JustinWoodring
Copy link
Contributor

Feature details

Users of qiskit will recognize that the 'plot_distribution' functionality represents a convenient way to visualize circuit output probabilities with minimal configuration.

Similar to how draw_mpl automatically outputs a circuit diagram in PennyLane, equivalent functionality for plotting probability distributions based on the qml probs output for a circuit would be very convenient.

I would like to implement this feature myself but I wanted to get a consensus on whether this would be a wanted or accepted feature before I begin the work.

Implementation

I believe that creating a function for qml.plot_probabilities(circuit) or something similar which takes the output of a circuit return qml.probs() would be a good way to implement this but there are perhaps better ways.

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

https://docs.quantum.ibm.com/api/qiskit/qiskit.visualization.plot_distribution

@JustinWoodring JustinWoodring added the enhancement ✨ New feature or request label Feb 10, 2024
@JustinWoodring
Copy link
Contributor Author

As I stated in the thread I would like to work on this if consensus is established that this would be a desirable feature if implemented

@trbromley
Copy link
Contributor

Thanks @JustinWoodring for posting, we definitely appreciate feature requests and subsequent code contributions.

In this case, I'd first like to understand a little more about the motivations for this feature. One option is to use qml.probs() in a QNode and then to manually create a Matplotlib bar chart. What are the main challenges with this approach?

We've generally tried to steer away from providing convenience wrappers, especially around Matplotlib, because it can limit the ability for users to customize their plot and it can also generate more work in testing.

One thing we could do is have a how-to guide (e.g., here) focused around all of the things you can do with visualization in PennyLane.

@JustinWoodring
Copy link
Contributor Author

The main motivation is certainly convenience. In my opinion this provides a simple way to way rapidly visualize the results. Although there are slower more manual means of creating these charts, a fast visual is very useful to reduce the work especially while prototyping an algorithm, where work is focused more on the general outcome and less on the exact visual presentation of the outcome.

To clarify this isn't something to reduce users' ability to plot but rather a simple, quick way to get a probability distribution that is properly labeled and sized without the need for manual engineering of a plot.

A how-to guide could potentially be adequate. Obviously I'll leave that decision to your discretion.

@trbromley
Copy link
Contributor

Thanks for the extra context @JustinWoodring. If you have a QNode that already returns a probability distribution with qml.probs(), I'm not sure that having a qml.plot_probabilities(circuit) will add much more than just manually calling Matplotlib's bar-chart drawer.

However, if you have a QNode that returns something else (e.g., an expectation value), but you quickly want to look at the probabilities, then perhaps a qml.probabilities(circuit) could work, similar to qml.matrix(circuit). Though this starts to encroach on some existing open questions about how to easily swap between different measurement processes in a QNode.

For now, a strong how-to guide that covers visualization functionality might actually be quite a value-add for users. If you're interested in contributing that then we can definitely talk more, but no worries if not!

@CatalinaAlbornoz
Copy link
Contributor

I second Tom's idea that a how-to guide around visualizations would be great.

@JustinWoodring
Copy link
Contributor Author

I'd be happy to contribute a how-to guide! I think even something as simple as that could very helpful for pennylane novices looking to interpret results efficiently. :)

@CatalinaAlbornoz
Copy link
Contributor

Awesome @JustinWoodring! We look forward to seeing your guide.

@CatalinaAlbornoz
Copy link
Contributor

@JustinWoodring as a guide for writing this how-to, make sure to read this PR description. It will give you a lot of insights on what we would expect from a how-to.

You can take this demo as an example!

I hope these resources help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants