Skip to content

Commit

Permalink
Add default line length for jupyter (Qiskit#1400)
Browse files Browse the repository at this point in the history
When running the text circuit drawer in jupyter the default line length
was being setting with the get_terminal_size() call. However this was
returning the size of the terminal used to launch jupyter, not the cell
size. So this could cause issues if your terminal is much smaller or
much larger than the cell size. To fix this issue this commit adds a
default of 80 characters for the default line length when running in
jupyter so it'll always fit in the cell.
  • Loading branch information
mtreinish authored Dec 4, 2018
1 parent ed81390 commit 125fb72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions qiskit/tools/visualization/_circuit_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ def circuit_drawer(circuit,
line_length (int): Sets the length of the lines generated by `text`
output type. This useful when the drawing does not fit in the
console. If None (default), it will try to guess the console width
using shutil.get_terminal_size(). If you don't want pagination at
all, set `line_length=-1`.
using shutil.get_terminal_size(). However, if you're running in
jupyter the default line length is set to 80 characters. If you
don't want pagination at all, set `line_length=-1`.
reverse_bits (bool): When set to True reverse the bit order inside
registers for the output visualization.
plot_barriers (bool): Enable/disable drawing barriers in the output
Expand Down
6 changes: 5 additions & 1 deletion qiskit/tools/visualization/_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""

from shutil import get_terminal_size
import sys

from ._error import VisualizationError

Expand Down Expand Up @@ -460,7 +461,10 @@ def lines(self, line_length=None):
if line_length is None:
line_length = self.line_length
if line_length is None:
line_length, _ = get_terminal_size()
if ('ipykernel' in sys.modules) and ('spyder' not in sys.modules):
line_length = 80
else:
line_length, _ = get_terminal_size()

noqubits = len(self.qregs)
layers = self.build_layers()
Expand Down

0 comments on commit 125fb72

Please sign in to comment.