Skip to content

Commit

Permalink
Remove unused code from MatplotlibDrawer (#6249)
Browse files Browse the repository at this point in the history
* cleaning up ast property from MatplotlibDrawer

* more cleaning

* black file

* reapply
  • Loading branch information
1ucian0 authored Jun 11, 2021
1 parent 5f6db11 commit 4c15d9e
Showing 1 changed file with 32 additions and 54 deletions.
86 changes: 32 additions & 54 deletions qiskit/visualization/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def __init__(
self._set_cregbundle()
self._global_phase = global_phase

self._ast = None
self._n_lines = 0
self._xmax = 0
self._ymax = 0
Expand All @@ -202,15 +201,6 @@ def __init__(
self._lwidth2 = 2.0 * self._scale
self._gate_width = {}

# default is to use character table for text width,
# but get_renderer will work with some mpl backends
"""fig = plt.figure()
if hasattr(fig.canvas, 'get_renderer'):
self._renderer = fig.canvas.get_renderer()
else:
self._renderer = None"""
self._renderer = None

# these char arrays are for finding text_width when not
# using get_renderer method for the matplotlib backend
self._char_list = {
Expand Down Expand Up @@ -336,11 +326,6 @@ def _set_cregbundle(self):
continue
break

@property
def ast(self):
"""AST getter"""
return self._ast

def _load_style(self, style):
current_style = DefaultStyle().style
style_name = "default"
Expand Down Expand Up @@ -424,42 +409,38 @@ def _get_text_width(self, text, fontsize, param=False):
if not text:
return 0.0

if self._renderer:
t = self.plt_mod.text(0.5, 0.5, text, fontsize=fontsize)
return t.get_window_extent(renderer=self._renderer).width / 60.0
else:
math_mode_match = self._mathmode_regex.search(text)
num_underscores = 0
num_carets = 0
if math_mode_match:
math_mode_text = math_mode_match.group(1)
num_underscores = math_mode_text.count("_")
num_carets = math_mode_text.count("^")
text = LatexNodes2Text().latex_to_text(text.replace("$$", ""))

# If there are subscripts or superscripts in mathtext string
# we need to account for that spacing by manually removing
# from text string for text length
if num_underscores:
text = text.replace("_", "", num_underscores)
if num_carets:
text = text.replace("^", "", num_carets)

# This changes hyphen to + to match width of math mode minus sign.
if param:
text = text.replace("-", "+")

f = 0 if fontsize == self._style["fs"] else 1
sum_text = 0.0
for c in text:
try:
sum_text += self._char_list[c][f]
except KeyError:
# if non-ASCII char, use width of 'c', an average size
sum_text += self._char_list["c"][f]
if f == 1:
sum_text *= self._subfont_factor
return sum_text
math_mode_match = self._mathmode_regex.search(text)
num_underscores = 0
num_carets = 0
if math_mode_match:
math_mode_text = math_mode_match.group(1)
num_underscores = math_mode_text.count("_")
num_carets = math_mode_text.count("^")
text = LatexNodes2Text().latex_to_text(text.replace("$$", ""))

# If there are subscripts or superscripts in mathtext string
# we need to account for that spacing by manually removing
# from text string for text length
if num_underscores:
text = text.replace("_", "", num_underscores)
if num_carets:
text = text.replace("^", "", num_carets)

# This changes hyphen to + to match width of math mode minus sign.
if param:
text = text.replace("-", "+")

f = 0 if fontsize == self._style["fs"] else 1
sum_text = 0.0
for c in text:
try:
sum_text += self._char_list[c][f]
except KeyError:
# if non-ASCII char, use width of 'c', an average size
sum_text += self._char_list["c"][f]
if f == 1:
sum_text *= self._subfont_factor
return sum_text

def _param_parse(self, params):
param_parts = []
Expand Down Expand Up @@ -1193,11 +1174,8 @@ def _draw_ops(self, verbose=False):
"sxdg",
"p",
]
_barriers = {"coord": [], "group": []}

#
# generate coordinate manager
#
q_anchors = {}
for key, qubit in self._qubit_dict.items():
q_anchors[key] = Anchor(reg_num=self._n_lines, yind=qubit["y"], fold=self._fold)
Expand Down

0 comments on commit 4c15d9e

Please sign in to comment.