# Buggy code
def pi_check(inpt, eps=1e-6, output="text", ndigits=5):
    """Computes if a number is close to an integer
    fraction or multiple of PI and returns the
    corresponding string.

    Args:
        inpt (float): Number to check.
        eps (float): EPS to check against.
        output (str): Options are 'text' (default),
                      'latex', and 'mpl'.
        ndigits (int): Number of digits to print
                       if returning raw inpt.

    Returns:
        str: string representation of output.

    Raises:
        QiskitError: if output is not a valid option.
    """
    inpt = float(inpt)
    if abs(inpt) < 1e-14:
        return str(0)
    val = inpt / np.pi

    if output == "text":
        pi = "pi"
    elif output == "latex":
        pi = "\\pi"
    elif output == "mpl":
        pi = "$\\pi$"
    else:
        raise QiskitError("pi_check parameter output should be text, latex, or mpl")

    if abs(val) >= 1:
        if abs(val % 1) < eps:
            val = int(round(val))
            if val == 1:
                str_out = "{}".format(pi)
            elif val == -1:
                str_out = "-{}".format(pi)
            else:
                str_out = "{}{}".format(val, pi)
            return str_out

    val = np.pi / inpt
    if abs(abs(val) - abs(round(val))) < eps:
        val = int(round(val))
        if val > 0:
            str_out = "{}/{}".format(pi, val)
        else:
            str_out = "-{}/{}".format(pi, abs(val))
        return str_out

    # Look for all fracs in 8
    abs_val = abs(inpt)
    frac = np.where(np.abs(abs_val - FRAC_MESH) < 1e-8)
    if frac[0].shape[0]:
        numer = int(frac[1][0]) + 1
        denom = int(frac[0][0]) + 1
        if inpt < 0:
            numer *= -1

        if numer == 1 and denom == 1:
            str_out = "{}".format(pi)
        elif numer == -1 and denom == 1:
            str_out = "-{}".format(pi)
        elif numer == 1:
            str_out = "{}/{}".format(pi, denom)
        elif numer == -1:
            str_out = "-{}/{}".format(pi, denom)
        elif denom == 1:
            str_out = "{}/{}".format(numer, pi)
        else:
            str_out = "{}{}/{}".format(numer, pi, denom)

        return str_out
    # nothing found
    str_out = "%.{}g".format(ndigits) % inpt
    return str_out


# Traceback (TypeError)
import qiskit as qk
theta = qk.circuit.Parameter('theta')

qc = qk.QuantumCircuit(1)
qc.rz(theta, 0)
qc.rz(2 * theta, 0) # Latex drawer will raise even without this line

qc.draw(output='text')

qc.draw(output='mpl')

qc.draw(output='latex')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-df2fe88c70ca> in <module>
----> 1 qc.draw(output='latex')

~/q/qiskit-terra/qiskit/circuit/quantumcircuit.py in draw(self, scale, filename, style, output, interactive, line_length, plot_barriers, reverse_bits, justify, vertical_compression, idle_wires, with_layout)
601                               vertical_compression=vertical_compression,
602                               idle_wires=idle_wires,
--> 603                               with_layout=with_layout)
604
605     def size(self):

~/q/qiskit-terra/qiskit/visualization/circuit_visualization.py in circuit_drawer(circuit, scale, filename, style, output, interactive, line_length, plot_barriers, reverse_bits, justify, vertical_compression, idle_wires, with_layout)
238                                       justify=justify,
239                                       idle_wires=idle_wires,
--> 240                                       with_layout=with_layout)
241     elif output == 'latex_source':
242         return _generate_latex_source(circuit,

~/q/qiskit-terra/qiskit/visualization/circuit_visualization.py in _latex_circuit_drawer(circuit, scale, filename, style, plot_barriers, reverse_bits, justify, idle_wires, with_layout)
433                                plot_barriers=plot_barriers,
434                                reverse_bits=reverse_bits, justify=justify,
--> 435                                idle_wires=idle_wires, with_layout=with_layout)
436         try:
437

~/q/qiskit-terra/qiskit/visualization/circuit_visualization.py in _generate_latex_source(circuit, filename, scale, style, reverse_bits, plot_barriers, justify, idle_wires, with_layout)
511                                  plot_barriers=plot_barriers,
512                                  reverse_bits=reverse_bits, layout=layout)
--> 513     latex = qcimg.latex()
514     if filename:
515         with open(filename, 'w') as latex_file:

~/q/qiskit-terra/qiskit/visualization/latex.py in latex(self, aliases)
147         """
148         self._initialize_latex_array(aliases)
--> 149         self._build_latex_array(aliases)
150         header_1 = r"""% \documentclass[preview]{standalone}
151 % If the image is too large to fit on this documentclass use

~/q/qiskit-terra/qiskit/visualization/latex.py in _build_latex_array(self, aliases)
478                             elif nm == "rz":
479                                 self._latex[pos_1][column] = "\\gate{R_z(%s)}" % (
--> 480                                     pi_check(op.op.params[0], output='latex'))
481                             elif nm == "reset":
482                                 self._latex[pos_1][column] = (

~/q/qiskit-terra/qiskit/visualization/tools/pi_check.py in pi_check(inpt, eps, output, ndigits)
43         QiskitError: if output is not a valid option.
44     """
---> 45     inpt = float(inpt)
46     if abs(inpt) < 1e-14:
47         return str(0)

~/q/qiskit-terra/qiskit/circuit/parameterexpression.py in __float__(self)
232         if self.parameters:
233             raise TypeError('ParameterExpression with unbound parameters ({}) '
--> 234                             'cannot be cast to a float.'.format(self.parameters))
235
236         return float(self._symbol_expr)

TypeError: ParameterExpression with unbound parameters ({Parameter(theta)}) cannot be cast to a float.

# Fixed code
def pi_check(inpt, eps=1e-6, output="text", ndigits=5):
    """Computes if a number is close to an integer
    fraction or multiple of PI and returns the
    corresponding string.

    Args:
        inpt (float): Number to check.
        eps (float): EPS to check against.
        output (str): Options are 'text' (default),
                      'latex', and 'mpl'.
        ndigits (int): Number of digits to print
                       if returning raw inpt.

    Returns:
        str: string representation of output.

    Raises:
        QiskitError: if output is not a valid option.
    """
    if isinstance(inpt, ParameterExpression):
        return str(inpt)
    inpt = float(inpt)
    if abs(inpt) < 1e-14:
        return str(0)
    val = inpt / np.pi

    if output == "text":
        pi = "pi"
    elif output == "latex":
        pi = "\\pi"
    elif output == "mpl":
        pi = "$\\pi$"
    else:
        raise QiskitError("pi_check parameter output should be text, latex, or mpl")

    if abs(val) >= 1:
        if abs(val % 1) < eps:
            val = int(round(val))
            if val == 1:
                str_out = "{}".format(pi)
            elif val == -1:
                str_out = "-{}".format(pi)
            else:
                str_out = "{}{}".format(val, pi)
            return str_out

    val = np.pi / inpt
    if abs(abs(val) - abs(round(val))) < eps:
        val = int(round(val))
        if val > 0:
            str_out = "{}/{}".format(pi, val)
        else:
            str_out = "-{}/{}".format(pi, abs(val))
        return str_out

    # Look for all fracs in 8
    abs_val = abs(inpt)
    frac = np.where(np.abs(abs_val - FRAC_MESH) < 1e-8)
    if frac[0].shape[0]:
        numer = int(frac[1][0]) + 1
        denom = int(frac[0][0]) + 1
        if inpt < 0:
            numer *= -1

        if numer == 1 and denom == 1:
            str_out = "{}".format(pi)
        elif numer == -1 and denom == 1:
            str_out = "-{}".format(pi)
        elif numer == 1:
            str_out = "{}/{}".format(pi, denom)
        elif numer == -1:
            str_out = "-{}/{}".format(pi, denom)
        elif denom == 1:
            str_out = "{}/{}".format(numer, pi)
        else:
            str_out = "{}{}/{}".format(numer, pi, denom)

        return str_out
    # nothing found
    str_out = "%.{}g".format(ndigits) % inpt
    return str_out