Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.26k stars 2.37k forks source link

Support to plot multiple statevectors on the same Bloch sphere using plot_bloch_multivector #5021

Open dhruvbhq opened 4 years ago

dhruvbhq commented 4 years ago

What is the expected enhancement?

Using plot_bloch_multivector , to be able to plot multiple statevectors on the same Bloch sphere for easy comparison of change in state.

Vismai-Khanderao commented 4 years ago

I would assume this would require a change to plot_bloch_vector (which plot_bloch_multivector calls) to have support for multiple vectors instead of a single one. Should be a simple change in parameters to accept a list[list[double]], and a parameter in plot_bloch_multivector to run a separate piece of code and pass all bloch_data to plot_bloch_vector.

Though a concern is how to differentiate the vectors, I believe there are only 5 colours and I'm not sure there is a way to label the vectors with a name currently.

mrvee-qC commented 2 years ago

Update for Santa:elf: - QGoGP

:white_check_mark: Issue reproducible! It would be a great learning and visualisation tool if something like this could be added! OP can correct me if this is wrong but here is what may be expected!

Screenshot 1 - Red initial state -> Green final state

bloch_multi

Screenshot 2 - State evolution ->

Colour coding maybe required to be specified for standardization but it can be great to show visualisations of how state evolves!

bloch_multi_with_angle

Example implementation used as a learning tool - https://gitlab.com/qworld/silver

Will update comment/add more comments if cause is found/fixed!

Python version 3.9.7 qiskit-terra version: 0.19.1

maxwell04-wq commented 12 months ago

Hi, If no one is working on this issue, can I take it? I have some experience with visualization and have contributed to Qiskit before, so have a little headstart. The major problem one could face is differentiating array-of-arrays from density matrices. Also, since no working solution is live on Qiskit, I'm assuming that this PR does not solve the issue.

albertnieto commented 10 months ago

As a workaround, this can be done easily using the Sphere class:

bloch_states = {
    "|0⟩": [0, 0, 1],
    "|1⟩": [0, 0, -1],
    "|+⟩": [1, 0, 0],
    "|-⟩": [-1, 0, 0],
    "|i+⟩": [0, 1, 0],
    "|i-⟩": [0, -1, 0]
}
from qiskit.visualization.bloch import Bloch

def plot_bloch_multiple_vector(bloch_data, title='Bloch Sphere', font_size=16):
    fig, ax = plt.subplots(subplot_kw=dict(projection="3d"))

    B = Bloch(axes=ax, font_size=font_size)
    B.zlabel = ['z', '']

    for key, value in bloch_data.items():
        B.add_vectors([value])
        B.add_annotation(value, key)

    B.render(title=title)

    return fig

output

dhruvbhq commented 10 months ago

I am fine if people work on the issue, maybe just check with the maintainers of the code once to get the go-ahead.

albertnieto commented 9 months ago

Can I take this issue?