Exemple #1
0
 def __eq__(self, other):
     """
     EQUALITY operator.
     """
     if isinstance(other,Qobj) and self.dims == other.dims and \
        self.shape == other.shape and abs(_sp_max_norm(self-other))<1e-14:
         return True
     else:
         return False
Exemple #2
0
 def __eq__(self, other):
     """
     EQUALITY operator.
     """
     if isinstance(other,Qobj) and self.dims == other.dims and \
        self.shape == other.shape and abs(_sp_max_norm(self-other))<1e-14:
         return True
     else:
         return False
Exemple #3
0
    def norm(self, oper_norm='tr', sparse=False, tol=0, maxiter=100000):
        """Returns the norm of a quantum object.

        Norm is L2-norm for kets and trace-norm (by default) for operators.
        Other operator norms may be specified using the `oper_norm` argument.

        Parameters
        ----------
        oper_norm : str
            Which norm to use for operators: trace 'tr', Frobius 'fro',
            one 'one', or max 'max'. This parameter does not affect the norm
            of a state vector.

        sparse : bool
            Use sparse eigenvalue solver for trace norm.  Other norms are not
            affected by this parameter.

        tol : float
            Tolerance for sparse solver (if used) for trace norm. The sparse
            solver may not converge if the tolerance is set too low.

        maxiter : int
            Maximum number of iterations performed by sparse solver (if used)
            for trace norm.

        Returns
        -------
        norm : float
            The requested norm of the operator or state quantum object.


        Notes
        -----
        The sparse eigensolver is much slower than the dense version.
        Use sparse only if memory requirements demand it.

        """
        if self.type == 'oper' or self.type == 'super':
            if oper_norm == 'tr':
                vals = sp_eigs(self,
                               vecs=False,
                               sparse=sparse,
                               tol=tol,
                               maxiter=maxiter)
                return sum(sqrt(abs(vals)**2))
            elif oper_norm == 'fro':
                return _sp_fro_norm(self)
            elif oper_norm == 'one':
                return _sp_one_norm(self)
            elif oper_norm == 'max':
                return _sp_max_norm(self)
            else:
                raise ValueError(
                    "Operator norm must be 'tr', 'fro', 'one', or 'max'.")
        else:
            return _sp_L2_norm(self)
Exemple #4
0
 def norm(self,oper_norm='tr',sparse=False,tol=0,maxiter=100000):
     """Returns the norm of a quantum object. 
     
     Norm is L2-norm for kets and trace-norm (by default) for operators.  
     Other operator norms may be specified using the `oper_norm` argument.
     
     Parameters
     ----------
     oper_norm : str 
         Which norm to use for operators: trace 'tr', Frobius 'fro',one 'one', 
         or max 'max'. This parameter does not affect the norm of a state vector. 
         
     sparse : bool 
         Use sparse eigenvalue solver for trace norm.  Other norms are not
         affected by this parameter.
         
     tol : float 
         Tolerance for sparse solver (if used) for trace norm.  The sparse solver
         may not converge if the tolerance is set too low.
         
     maxiter : int 
         Maximum number of iterations performed by sparse solver (if used) for
         trace norm.
     
     Returns
     -------
     norm : float
         The requested norm of the operator or state quantum object.
     
     
     Notes
     ----- 
     The sparse eigensolver is much slower than the dense version.  
     Use sparse only if memory requirements demand it.
     
     """
     if self.type=='oper' or self.type=='super':
         if oper_norm=='tr':
             vals=sp_eigs(self,vecs=False,sparse=sparse,tol=tol,maxiter=maxiter)
             return sum(sqrt(abs(vals)**2))
         elif oper_norm=='fro':
             return _sp_fro_norm(self)
         elif oper_norm=='one':
             return _sp_one_norm(self)
         elif oper_norm=='max':
             return _sp_max_norm(self)
         else:
             raise ValueError("Operator norm must be 'tr', 'fro', 'one', or 'max'.")
     else:
         return _sp_L2_norm(self)