Skip to content

Add .draw() method to quantum_info.Operator class #10154

@diemilio

Description

@diemilio

What should we add?

It would be very convenient to have a draw method for the Operator class similar to what is available for the Statevector and DensityMatrix classes. A good start would be to just add text representations (repr, text, latex_source and latex), but more could be added later if needed, like a visual representation of Pauli decompositions, cityscape plot of the op matrix, etc. (I believe the state visualizations work for operators as well, so some of these will be minimal work too).

Having this feature will also allow the user to set a predefine way of displaying things locally in the user config file. Not sure if this would have to be a separate PR since it will require its own testing, release notes, etc.

I can implement this if there is any interest. I would just need some guidance on what would be the best way to organize the code. In the case of the Statevector class, the draw method calls the state_drawer function which lives under visualization.state_visualization. Not sure if for Operator something similar would have to be done, or if everything could just be defined under the draw method itself since a __repr__ method already exists, and latex_source and latex only need to call the array_to_latex function.

The only representation remaining would be text, which ideally could be implemented just by reusing the visualization.state_visualization.TextMatrix class, but currently this does not support operators. This line errors out because the Operator class does not have a .dims attribute, so either that would need to be modified, or a __str__ method could be defined for Operator and simply use that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions