def _draw_ops(self, verbose=False):
    _wide_gate = 'u2 u3 cu2 cu3'.split()
    _barriers = {'coord': [], 'group': []}
    next_ops = self._ops.copy()
    if next_ops:
        next_ops.pop(0)
    this_anc = 0
    q_anchors = {}
    for (key, qreg) in self._qreg_dict.items():
        q_anchors[key] = Anchor(reg_num=self._cond['n_lines'], yind=qreg['y'], fold=self._style.fold)
    c_anchors = {}
    for (key, creg) in self._creg_dict.items():
        c_anchors[key] = Anchor(reg_num=self._cond['n_lines'], yind=creg['y'], fold=self._style.fold)
    prev_width = 0
    for (layer_no, layer) in enumerate(self._ops):
        layer_width = 1
        for op in layer:
            if (op['name'] in _wide_gate):
                layer_width = 2
        for op in layer:
            _iswide = (op['name'] in _wide_gate)
            if ('qargs' in op.keys()):
                q_idxs = []
                for qarg in op['qargs']:
                    for (index, reg) in self._qreg_dict.items():
                        if ((reg['group'] == qarg[0]) and (reg['index'] == qarg[1])):
                            q_idxs.append(index)
                            break
            else:
                q_idxs = []
            if ('cargs' in op.keys()):
                c_idxs = []
                for carg in op['cargs']:
                    for (index, reg) in self._creg_dict.items():
                        if ((reg['group'] == carg[0]) and (reg['index'] == carg[1])):
                            c_idxs.append(index)
                            break
            else:
                c_idxs = []
            this_anc = (layer_no + prev_width)
            occupied = q_idxs
            q_list = [ii for ii in range(min(occupied), (max(occupied) + 1))]
            locs = [q_anchors[jj].is_locatable(this_anc, layer_width) for jj in q_list]
            if all(locs):
                for ii in q_list:
                    if ((op['name'] in ['barrier', 'snapshot', 'load', 'save', 'noise']) and (not self.plot_barriers)):
                        q_anchors[ii].set_index((this_anc - 1), layer_width)
                    else:
                        q_anchors[ii].set_index(this_anc, layer_width)
            q_xy = [q_anchors[ii].plot_coord(this_anc, layer_width) for ii in q_idxs]
            c_xy = [c_anchors[ii].plot_coord(this_anc, layer_width) for ii in c_idxs]
            qreg_b = min(q_xy, key=(lambda xy: xy[1]))
            qreg_t = max(q_xy, key=(lambda xy: xy[1]))
            if verbose:
                print(op)
            if (('op' in op.keys()) and hasattr(op['op'], 'param')):
                param = self.param_parse(op['op'].params, self._style.pimode)
            else:
                param = None
            if (('condition' in op.keys()) and op['condition']):
                c_xy = [c_anchors[ii].plot_coord(this_anc, layer_width) for ii in self._creg_dict]
                mask = 0
                for (index, cbit) in enumerate(self._creg):
                    if (cbit.reg == op['condition'][0]):
                        mask |= (1 << index)
                val = op['condition'][1]
                fmt_c = '{{:0{}b}}'.format(len(c_xy))
                cmask = list(fmt_c.format(mask))[::(- 1)]
                fmt_v = '{{:0{}b}}'.format(cmask.count('1'))
                vlist = list(fmt_v.format(val))[::(- 1)]
                v_ind = 0
                xy_plot = []
                for (xy, m) in zip(c_xy, cmask):
                    if (m == '1'):
                        if (xy not in xy_plot):
                            if ((vlist[v_ind] == '1') or self._style.bundle):
                                self._conds(xy, istrue=True)
                            else:
                                self._conds(xy, istrue=False)
                            xy_plot.append(xy)
                        v_ind += 1
                creg_b = sorted(xy_plot, key=(lambda xy: xy[1]))[0]
                self._subtext(creg_b, hex(val))
                self._line(qreg_t, creg_b, lc=self._style.cc, ls=self._style.cline)
            if (op['name'] == 'measure'):
                vv = self._creg_dict[c_idxs[0]]['index']
                self._measure(q_xy[0], c_xy[0], vv)
            elif (op['name'] in ['barrier', 'snapshot', 'load', 'save', 'noise']):
                _barriers = {'coord': [], 'group': []}
                for (index, qbit) in enumerate(q_idxs):
                    q_group = self._qreg_dict[qbit]['group']
                    if (q_group not in _barriers['group']):
                        _barriers['group'].append(q_group)
                    _barriers['coord'].append(q_xy[index])
                if self.plot_barriers:
                    self._barrier(_barriers, this_anc)
            elif (len(q_xy) == 1):
                disp = op['name']
                if param:
                    self._gate(q_xy[0], wide=_iswide, text=disp, subtext='{}'.format(param))
                else:
                    self._gate(q_xy[0], wide=_iswide, text=disp)
            elif (len(q_xy) == 2):
                if (op['name'] in ['cx']):
                    self._ctrl_qubit(q_xy[0])
                    self._tgt_qubit(q_xy[1])
                elif (op['name'] == 'cz'):
                    if self._style.latexmode:
                        self._ctrl_qubit(q_xy[0])
                        self._ctrl_qubit(q_xy[1])
                    else:
                        disp = op['name'].replace('c', '')
                        self._ctrl_qubit(q_xy[0])
                        self._gate(q_xy[1], wide=_iswide, text=disp)
                elif (op['name'] in ['cy', 'ch', 'cu3', 'crz']):
                    disp = op['name'].replace('c', '')
                    self._ctrl_qubit(q_xy[0])
                    if param:
                        self._gate(q_xy[1], wide=_iswide, text=disp, subtext='{}'.format(param))
                    else:
                        self._gate(q_xy[1], wide=_iswide, text=disp)
                elif (op['name'] in ['cu1']):
                    disp = op['name'].replace('c', '')
                    self._ctrl_qubit(q_xy[0])
                    if self._style.latexmode:
                        self._ctrl_qubit(q_xy[1])
                        self._subtext(qreg_b, param)
                    else:
                        self._gate(q_xy[1], wide=_iswide, text=disp, subtext='{}'.format(param))
                elif (op['name'] == 'swap'):
                    self._swap(q_xy[0])
                    self._swap(q_xy[1])
                self._line(qreg_b, qreg_t)
            elif (len(q_xy) == 3):
                if (op['name'] == 'cswap'):
                    self._ctrl_qubit(q_xy[0])
                    self._swap(q_xy[1])
                    self._swap(q_xy[2])
                elif (op['name'] == 'ccx'):
                    self._ctrl_qubit(q_xy[0])
                    self._ctrl_qubit(q_xy[1])
                    self._tgt_qubit(q_xy[2])
                self._line(qreg_b, qreg_t)
            else:
                logger.critical('Invalid gate %s', op)
                raise exceptions.VisualizationError('invalid gate {}'.format(op))
        prev_width = (layer_width - 1)
    anchors = [q_anchors[ii].get_index() for ii in self._qreg_dict]
    if anchors:
        max_anc = max(anchors)
    else:
        max_anc = 0
    n_fold = (max(0, (max_anc - 1)) // self._style.fold)
    if (max_anc > self._style.fold > 0):
        self._cond['xmax'] = (self._style.fold + 1)
        self._cond['ymax'] = (((n_fold + 1) * (self._cond['n_lines'] + 1)) - 1)
    else:
        self._cond['xmax'] = (max_anc + 1)
        self._cond['ymax'] = self._cond['n_lines']
    for ii in range((n_fold + 1)):
        feedline_r = ((n_fold > 0) and (n_fold > ii))
        feedline_l = (ii > 0)
        self._draw_regs_sub(ii, feedline_l, feedline_r)
    if self._style.index:
        for ii in range(max_anc):
            if (self._style.fold > 0):
                x_coord = ((ii % self._style.fold) + 1)
                y_coord = (((- (ii // self._style.fold)) * (self._cond['n_lines'] + 1)) + 0.7)
            else:
                x_coord = (ii + 1)
                y_coord = 0.7
            self.ax.text(x_coord, y_coord, str((ii + 1)), ha='center', va='center', fontsize=self._style.sfs, color=self._style.tc, clip_on=True, zorder=PORDER_TEXT)
def _draw_ops(self, verbose=False):
    _wide_gate = 'u2 u3 cu2 cu3'.split()
    _barriers = {'coord': [], 'group': []}
    next_ops = self._ops.copy()
    if next_ops:
        next_ops.pop(0)
    this_anc = 0
    q_anchors = {}
    for (key, qreg) in self._qreg_dict.items():
        q_anchors[key] = Anchor(reg_num=self._cond['n_lines'], yind=qreg['y'], fold=self._style.fold)
    c_anchors = {}
    for (key, creg) in self._creg_dict.items():
        c_anchors[key] = Anchor(reg_num=self._cond['n_lines'], yind=creg['y'], fold=self._style.fold)
    prev_width = 0
    for (layer_no, layer) in enumerate(self._ops):
        layer_width = 1
        for op in layer:
            if (op['name'] in _wide_gate):
                layer_width = 2
        for op in layer:
            _iswide = (op['name'] in _wide_gate)
            if ('qargs' in op.keys()):
                q_idxs = []
                for qarg in op['qargs']:
                    for (index, reg) in self._qreg_dict.items():
                        if ((reg['group'] == qarg[0]) and (reg['index'] == qarg[1])):
                            q_idxs.append(index)
                            break
            else:
                q_idxs = []
            if ('cargs' in op.keys()):
                c_idxs = []
                for carg in op['cargs']:
                    for (index, reg) in self._creg_dict.items():
                        if ((reg['group'] == carg[0]) and (reg['index'] == carg[1])):
                            c_idxs.append(index)
                            break
            else:
                c_idxs = []
            this_anc = (layer_no + prev_width)
            occupied = q_idxs
            q_list = [ii for ii in range(min(occupied), (max(occupied) + 1))]
            locs = [q_anchors[jj].is_locatable(this_anc, layer_width) for jj in q_list]
            if all(locs):
                for ii in q_list:
                    if ((op['name'] in ['barrier', 'snapshot', 'load', 'save', 'noise']) and (not self.plot_barriers)):
                        q_anchors[ii].set_index((this_anc - 1), layer_width)
                    else:
                        q_anchors[ii].set_index(this_anc, layer_width)
            q_xy = [q_anchors[ii].plot_coord(this_anc, layer_width) for ii in q_idxs]
            c_xy = [c_anchors[ii].plot_coord(this_anc, layer_width) for ii in c_idxs]
            qreg_b = min(q_xy, key=(lambda xy: xy[1]))
            qreg_t = max(q_xy, key=(lambda xy: xy[1]))
            if verbose:
                print(op)
            if (('op' in op.keys()) and hasattr(op['op'], 'param')):
                param = self.param_parse(op['op'].params, self._style.pimode)
            else:
                param = None
            if (('condition' in op.keys()) and op['condition']):
                c_xy = [c_anchors[ii].plot_coord(this_anc, layer_width) for ii in self._creg_dict]
                mask = 0
                for (index, cbit) in enumerate(self._creg):
                    if (cbit.reg == op['condition'][0]):
                        mask |= (1 << index)
                val = op['condition'][1]
                fmt_c = '{{:0{}b}}'.format(len(c_xy))
                cmask = list(fmt_c.format(mask))[::(- 1)]
                fmt_v = '{{:0{}b}}'.format(cmask.count('1'))
                vlist = list(fmt_v.format(val))[::(- 1)]
                v_ind = 0
                xy_plot = []
                for (xy, m) in zip(c_xy, cmask):
                    if (m == '1'):
                        if (xy not in xy_plot):
                            if ((vlist[v_ind] == '1') or self._style.bundle):
                                self._conds(xy, istrue=True)
                            else:
                                self._conds(xy, istrue=False)
                            xy_plot.append(xy)
                        v_ind += 1
                creg_b = sorted(xy_plot, key=(lambda xy: xy[1]))[0]
                self._subtext(creg_b, hex(val))
                self._line(qreg_t, creg_b, lc=self._style.cc, ls=self._style.cline)
            if (op['name'] == 'measure'):
                vv = self._creg_dict[c_idxs[0]]['index']
                self._measure(q_xy[0], c_xy[0], vv)
            elif (op['name'] in ['barrier', 'snapshot', 'load', 'save', 'noise']):
                _barriers = {'coord': [], 'group': []}
                for (index, qbit) in enumerate(q_idxs):
                    q_group = self._qreg_dict[qbit]['group']
                    if (q_group not in _barriers['group']):
                        _barriers['group'].append(q_group)
                    _barriers['coord'].append(q_xy[index])
                if self.plot_barriers:
                    self._barrier(_barriers, this_anc)
            elif (len(q_xy) == 1):
                disp = op['name']
                if param:
                    self._gate(q_xy[0], wide=_iswide, text=disp, subtext='{}'.format(param))
                else:
                    self._gate(q_xy[0], wide=_iswide, text=disp)
            elif (len(q_xy) == 2):
                if (op['name'] in ['cx']):
                    self._ctrl_qubit(q_xy[0])
                    self._tgt_qubit(q_xy[1])
                elif (op['name'] == 'cz'):
                    if self._style.latexmode:
                        self._ctrl_qubit(q_xy[0])
                        self._ctrl_qubit(q_xy[1])
                    else:
                        disp = op['name'].replace('c', )
                        self._ctrl_qubit(q_xy[0])
                        self._gate(q_xy[1], wide=_iswide, text=disp)
                elif (op['name'] in ['cy', 'ch', 'cu3', 'crz']):
                    disp = op['name'].replace('c', )
                    self._ctrl_qubit(q_xy[0])
                    if param:
                        self._gate(q_xy[1], wide=_iswide, text=disp, subtext='{}'.format(param))
                    else:
                        self._gate(q_xy[1], wide=_iswide, text=disp)
                elif (op['name'] in ['cu1']):
                    disp = op['name'].replace('c', )
                    self._ctrl_qubit(q_xy[0])
                    if self._style.latexmode:
                        self._ctrl_qubit(q_xy[1])
                        self._subtext(qreg_b, param)
                    else:
                        self._gate(q_xy[1], wide=_iswide, text=disp, subtext='{}'.format(param))
                elif (op['name'] == 'swap'):
                    self._swap(q_xy[0])
                    self._swap(q_xy[1])
                self._line(qreg_b, qreg_t)
            elif (len(q_xy) == 3):
                if (op['name'] == 'cswap'):
                    self._ctrl_qubit(q_xy[0])
                    self._swap(q_xy[1])
                    self._swap(q_xy[2])
                elif (op['name'] == 'ccx'):
                    self._ctrl_qubit(q_xy[0])
                    self._ctrl_qubit(q_xy[1])
                    self._tgt_qubit(q_xy[2])
                self._line(qreg_b, qreg_t)
            else:
                logger.critical('Invalid gate %s', op)
                raise exceptions.VisualizationError('invalid gate {}'.format(op))
        prev_width = (layer_width - 1)
    anchors = [q_anchors[ii].get_index() for ii in self._qreg_dict]
    if anchors:
        max_anc = max(anchors)
    else:
        max_anc = 0
    n_fold = (max(0, (max_anc - 1)) // self._style.fold)
    if (max_anc > self._style.fold > 0):
        self._cond['xmax'] = (self._style.fold + 1)
        self._cond['ymax'] = (((n_fold + 1) * (self._cond['n_lines'] + 1)) - 1)
    else:
        self._cond['xmax'] = (max_anc + 1)
        self._cond['ymax'] = self._cond['n_lines']
    for ii in range((n_fold + 1)):
        feedline_r = ((n_fold > 0) and (n_fold > ii))
        feedline_l = (ii > 0)
        self._draw_regs_sub(ii, feedline_l, feedline_r)
    if self._style.index:
        for ii in range(max_anc):
            if (self._style.fold > 0):
                x_coord = ((ii % self._style.fold) + 1)
                y_coord = (((- (ii // self._style.fold)) * (self._cond['n_lines'] + 1)) + 0.7)
            else:
                x_coord = (ii + 1)
                y_coord = 0.7
            self.ax.text(x_coord, y_coord, str((ii + 1)), ha='center', va='center', fontsize=self._style.sfs, color=self._style.tc, clip_on=True, zorder=PORDER_TEXT)