code: def to_matrix(self, n_qubits=-1):
          
          if n_qubits == -1:
              n_qubits = self.max_n() + 1
          mat = I.to_matrix(n_qubits)
          for op in self.ops:
              if op.is_identity:
                  continue
              mat = mat @ op.to_matrix(n_qubits)
          return mat * self.coeff
docs: Convert to the matrix.