Repository: Qiskit/qiskit

Issue:
Visualization support for parameterized circuits
Following #2103, gate params can be sympy expressions
```
>>> theta = sympy.Symbol('theta')
>>> qc = qk.QuantumCircuit(cr, qr)
>>> qc.rx(theta, qr[0])
<qiskit.extensions.standard.rx.RXGate object at 0x116d5c1d0>
>>> qc.measure(qr[0], cr[0])
<qiskit.circuit.measure.Measure object at 0x11ed71c50>
>>> print(qc.draw())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/visualization/text.py", line 437, in __str__
    return self.single_string()
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/visualization/text.py", line 462, in single_string
    return "\n".join(self.lines())
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/visualization/text.py", line 497, in lines
    layers = self.build_layers()
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/visualization/text.py", line 820, in build_layers
    self._instruction_to_gate(instruction, layer)
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/visualization/text.py", line 780, in _instruction_to_gate
    BoxOnQuWire(TextDrawing.label_for_box(instruction)))
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/visualization/text.py", line 618, in label_for_box
    params = TextDrawing.params_for_label(instruction)
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/visualization/text.py", line 610, in params_for_label
    return ['%.5g' % i for i in instruction.op.params
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/visualization/text.py", line 611, in <listcomp>
    if not isinstance(i, (numpy.ndarray, sympy.Matrix))]
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/lib/python3.5/site-packages/sympy/core/expr.py", line 256, in __float__
    raise TypeError("can't convert expression to float")
TypeError: can't convert expression to float
```


Discussion:
Is this on all backends or just text?
Ok, I just tested this locally, mpl also fails for the same reason casting trying to cast the sympy expression to a float which it can't do because there is no value. But latex actually works:

![param_tex](https://user-images.githubusercontent.com/2447371/56429144-dd0d6a00-628f-11e9-92f0-f4c28a757b50.png)

without any modifications. I think this is a first where latex is the one without a bug! :)
I'm self-assigning the text part.

Well done latex drawer! :)
Text drawer fix in #2168. When merged, this issue should be renamed to be mpl specific.

Resolving patch:
diff --git a/qiskit/visualization/matplotlib.py b/qiskit/visualization/matplotlib.py
--- a/qiskit/visualization/matplotlib.py
+++ b/qiskit/visualization/matplotlib.py
@@ -787,9 +787,15 @@ def _draw_ops(self, verbose=False):
     def param_parse(v, pimode=False):
         for i, e in enumerate(v):
             if pimode:
-                v[i] = MatplotlibDrawer.format_pi(e)
+                try:
+                    v[i] = MatplotlibDrawer.format_pi(e)
+                except TypeError:
+                    v[i] = str(e)
             else:
-                v[i] = MatplotlibDrawer.format_numeric(e)
+                try:
+                    v[i] = MatplotlibDrawer.format_numeric(e)
+                except TypeError:
+                    v[i] = str(e)
             if v[i].startswith('-'):
                 v[i] = '$-$' + v[i][1:]
         param = ', '.join(v)


Test patch: