Convert to the matrix.

def to_matrix(self, n_qubits=-1):
        """Convert to the matrix."""
        if n_qubits == -1:
            n_qubits = self.max_n() + 1
        return sum(term.to_matrix(n_qubits) for term in self.terms)