<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_pdf(source, texinputs=[], builder=None):
 """Builds a LaTeX source to PDF. Will automatically instantiate an available builder (or raise a :class:`exceptions.RuntimeError` if none are available) and build the supplied source with it. Parameters are passed on to the builder's :meth:`~latex.build.LatexBuilder.build_pdf` function. :param builder: Specify which builder should be used - ``latexmk``, ``pdflatex`` or ``xelatexmk``. """

    if builder is None:
        builders = PREFERRED_BUILDERS
    elif builder not in BUILDERS:
        raise RuntimeError('Invalid Builder specified')
    else:
        builders = (builder, )

    for bld in builders:
        bld_cls = BUILDERS[bld]
        builder = bld_cls()
        if not builder.is_available():
            continue
        return builder.build_pdf(source, texinputs)
    else:
        raise RuntimeError('No available builder could be instantiated. '
                           'Please make sure LaTeX is installed.')