# Buggy code
def _transpilation(
    circuit,
    basis_gates=None,
    coupling_map=None,
    initial_layout=None,
    seed_mapper=None,
    pass_manager=None,
):
    """Perform transpilation of a single circuit.

    Args:
        circuit (QuantumCircuit): A circuit to transpile.
        basis_gates (list[str]): list of basis gate names supported by the
            target. Default: ['u1','u2','u3','cx','id']
        coupling_map (CouplingMap): coupling map (perhaps custom) to target in mapping
        initial_layout (Layout): initial layout of qubits in mapping
        seed_mapper (int): random seed for the swap_mapper
        pass_manager (PassManager): a pass_manager for the transpiler stage

    Returns:
        QuantumCircuit: A transpiled circuit.

    Raises:
        TranspilerError: If the Layout does not matches the circuit
    """
    if (
        initial_layout is not None
        and set(circuit.qregs) != initial_layout.get_registers()
    ):
        raise TranspilerError(
            "The provided initial layout does not match the registers in "
            'the circuit "%s"' % circuit.name
        )

    if pass_manager and not pass_manager.working_list:
        return circuit

    dag = circuit_to_dag(circuit)
    del circuit

    final_dag = transpile_dag(
        dag,
        basis_gates=basis_gates,
        coupling_map=coupling_map,
        initial_layout=initial_layout,
        seed_mapper=seed_mapper,
        pass_manager=pass_manager,
    )

    out_circuit = dag_to_circuit(final_dag)

    return out_circuit


# Traceback (TypeError)
qobj = qk.compile(qc, backend=FakeTokyo())
/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/tools/compiler.py:50: DeprecationWarning: qiskit.compile() is deprecated and will be removed in Qiskit Terra 0.9. Please use qiskit.transpile() to transform circuits and qiskit.assemble_circuits() to produce qobj.
DeprecationWarning)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/tools/compiler.py", line 67, in compile
initial_layout, seed_mapper, pass_manager)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/transpiler.py", line 85, in transpile
'pass_manager': pass_manager})
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/tools/parallel.py", line 93, in parallel_map
return [task(values[0], *task_args, **task_kwargs)]
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/transpiler.py", line 143, in _transpilation
pass_manager=pass_manager)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/transpiler.py", line 234, in transpile_dag
dag = pass_manager.run_passes(dag)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/passmanager.py", line 129, in run_passes
dag = self._do_pass(pass_, dag, passset.options)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/passmanager.py", line 169, in _do_pass
new_dag = pass_.run(dag)
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/passes/optimize_1q_gates.py", line 62, in run
left_parameters = tuple([float(x) for x in left_parameters])
File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/transpiler/passes/optimize_1q_gates.py", line 62, in <listcomp>
left_parameters = tuple([float(x) for x in left_parameters])
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

# Fixed code
def _transpilation(
    circuit,
    basis_gates=None,
    coupling_map=None,
    initial_layout=None,
    seed_mapper=None,
    pass_manager=None,
):
    """Perform transpilation of a single circuit.

    Args:
        circuit (QuantumCircuit): A circuit to transpile.
        basis_gates (list[str]): list of basis gate names supported by the
            target. Default: ['u1','u2','u3','cx','id']
        coupling_map (CouplingMap): coupling map (perhaps custom) to target in mapping
        initial_layout (Layout): initial layout of qubits in mapping
        seed_mapper (int): random seed for the swap_mapper
        pass_manager (PassManager): a pass_manager for the transpiler stage

    Returns:
        QuantumCircuit: A transpiled circuit.

    Raises:
        TranspilerError: If the Layout does not matches the circuit
    """
    if (
        initial_layout is not None
        and set(circuit.qregs) != initial_layout.get_registers()
    ):
        raise TranspilerError(
            "The provided initial layout does not match the registers in "
            'the circuit "%s"' % circuit.name
        )

    if pass_manager and not pass_manager.working_list:
        return circuit

    is_parametric_circuit = bool(circuit.unassigned_variables)

    dag = circuit_to_dag(circuit)
    del circuit

    final_dag = transpile_dag(
        dag,
        basis_gates=basis_gates,
        coupling_map=coupling_map,
        initial_layout=initial_layout,
        skip_numeric_passes=is_parametric_circuit,
        seed_mapper=seed_mapper,
        pass_manager=pass_manager,
    )

    out_circuit = dag_to_circuit(final_dag)

    return out_circuit