  We define the model of quantum circuits with density matrices, where
non-unitary gates are allowed. Measurements in the middle of the computation,
noise and decoherence are implemented in a natural way in this model, which is
shown to be equivalent in computational power to standard quantum circuits.
  The main result in this paper is a solution for the subroutine problem: The
general function that a quantum circuit outputs is a probabilistic function,
but using pure state language, such a function can not be used as a black box
in other computations. We give a natural definition of using general
subroutines, and analyze their computational power.
  We suggest convenient metrics for quantum computing with mixed states. For
density matrices we analyze the so called ``trace metric'', and using this
metric, we define and discuss the ``diamond metric'' on superoperators. These
metrics enable a formal discussion of errors in the computation.
  Using a ``causality'' lemma for density matrices, we also prove a simple
lower bound for probabilistic functions.
