2
$\begingroup$
import qiskit.quantum_info as qi 
circuit = QuantumCircuit(...)
state = qi.Statevector.from_instruction(circuit)

to get the state of my quantum circuit.

state.draw(output='latex') then gives a nice representation of my state.

This works pretty well. The only issue is that when the states get a bit long the output starts looking like this:

Note how the dots in the middle indicates parts are missing

Some parts of the state are missing, replaced by dots. How do I force qiskit to display the entire state? Is there some way of increasing the size of the output cell? I'm using a jupyter notebook.

$\endgroup$

1 Answer 1

0
$\begingroup$

Statevector.draw method calls state_drawer function which in turn depends on _state_to_latex_ket function to generate the Latex representation.

_state_to_latex_ket function accepts max_size parameter to set the maximum number of non-zero terms in the expression which defaults to $12$.

As per documentation, if we set max_size to a large enough value when calling Statevector.draw, it should be passed to _state_to_latex_ket and the state shouldn't be truncated. However, it is not. It seems like a bug.

A workaround is to use _state_to_latex_ket directly as follows:

from IPython.display import Latex
from qiskit.visualization import state_visualization

prefix = "$$\\begin{align}"
suffix = "\\end{align}$$"
state_to_latex = state_visualization._state_to_latex_ket(state.data, max_size = 128)

Latex(prefix + state_to_latex + suffix)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.