docs: def draw_circuit(circuit, filename, direction = 'lr',
              hunit = HUNIT, vunit = VUNIT,
              rhmargin = RHMARGIN, rvmargin = RVMARGIN,
              rpermutation_length = RPLENGTH,
              draw_boxes = True,
              permutation_arrows = False):
      """
      Generate a graphic representation of circuit and store them in a file.
      The graphics format is determined from the file extension.
  
      :param circuit: The circuit expression
      :type circuit: ca.Circuit
      :param filename: A filepath to store the output image under. The file name suffix determines the output graphics format
      :type filename: str
      :param direction: The horizontal direction of laying out series products. One of ``'lr'`` and ``'rl'``. This option overrides a negative value for ``hunit``,
       default = ``'lr'``
      :param hunit: The horizontal length unit, default = ``HUNIT``
      :type hunit: float
      :param vunit: The vertical length unit, default = ``VUNIT``
      :type vunit: float
      :param rhmargin: relative horizontal margin, default = ``RHMARGIN``
      :type rhmargin: float
      :param rvmargin: relative vertical margin, default = ``RVMARGIN``
      :type rvmargin: float
      :param rpermutation_length: the relative length of a permutation circuit, default = ``RPLENGTH``
      :type rpermutation_length: float
      :param draw_boxes: Whether to draw indicator boxes to denote subexpressions (Concatenation, SeriesProduct, etc.), default = ``True``
      :type draw_boxes: bool
      :param permutation_arrows: Whether to draw arrows within the permutation visualization, default = ``False``
      :type permutation_arrows: bool
      :return: ``True`` if printing was successful, ``False`` if not.
      :rtype: bool
      """
  
  
      if direction == 'lr':
          hunit = abs(hunit)
  
      elif direction == 'rl':
          hunit = -abs(hunit)
      try:
          c, dims, c_in, c_out = draw_circuit_canvas(circuit, hunit = hunit, vunit = vunit,
                                              rhmargin = rhmargin, rvmargin = rvmargin,
                                              rpermutation_length = rpermutation_length,
                                              draw_boxes = draw_boxes,
                                              permutation_arrows = permutation_arrows)
      except ValueError as e:
          print( ("No graphics returned for circuit {!r}".format(circuit)))
          return False
      ps_suffixes = ['.pdf', '.eps', '.ps']
      gs_suffixes = ['.png', '.jpg']
      if any(filename.endswith(suffix) for suffix in ps_suffixes):
          c.writetofile(filename)
      elif any(filename.endswith(suffix) for suffix in gs_suffixes):
          if GS is None:
              raise FileNotFoundError(
                  "No Ghostscript executable available. Ghostscript is required for "
                  "rendering to {}.".format(", ".join(gs_suffixes))
              )
          c.writeGSfile(filename, gs=GS)
      return True