Commit 872deff9 by Tobias Hangleiter

### Remove qutip dependency and fix dtype not inexact

parent 3ac79667
 ... ... @@ -32,7 +32,6 @@ from itertools import zip_longest from typing import List, Sequence, Tuple, Union import numpy as np import qutip as qt from numpy import linalg, ndarray from .qi import paulis ... ... @@ -272,7 +271,7 @@ def pauli_expm(a: Sequence, nonzero_ind: List[bool]) -> ndarray: \exp(-i(\vec{a}\cdot\vec{\sigma})) = I\cos|\vec{a}| - i(\vec{a}\cdot\vec{\sigma})\sin|\vec{a}| than :meth:qutip.Qobj.expm() or :meth:scipy.linalg.expm. than :meth:scipy.linalg.expm. Parameters ---------- ... ... @@ -333,8 +332,8 @@ def remove_float_errors(arr: ndarray, eps_scale: float = None): return arr def check_phase_eq(psi: Union[qt.Qobj, Sequence], phi: Union[qt.Qobj, Sequence], def check_phase_eq(psi: Sequence, phi: Sequence, eps: float = None, normalized: bool = False) -> Tuple[bool, float]: r""" ... ... @@ -349,7 +348,7 @@ def check_phase_eq(psi: Union[qt.Qobj, Sequence], Parameters ---------- psi, phi : Qobj or array_like psi, phi : array_like Vectors or operators to be compared eps : float The tolerance below which the two objects are treated as equal, i.e., ... ... @@ -360,19 +359,27 @@ def check_phase_eq(psi: Union[qt.Qobj, Sequence], Examples -------- >>> psi = qt.sigmax() >>> phi = qt.sigmax()*np.exp(1j*1.2345) >>> psi = qutil.qi.paulis[1] >>> phi = qutil.qi.paulis[1]*np.exp(1j*1.2345) >>> check_phase_eq(psi, phi) (True, 1.2345) (True, 1.2345000000000603) """ psi, phi = [obj.full() if isinstance(obj, qt.Qobj) else obj for obj in (psi, phi)] if eps is None: # Tolerance the floating point eps times the # of flops for the matrix # multiplication, i.e. for psi and phi n x m matrices 2*n**2*m eps = max(np.finfo(psi.dtype).eps, np.finfo(phi.dtype).eps) *\ np.prod(psi.shape)*phi.shape[-1]*2 try: psi_eps = np.finfo(psi.dtype).eps except ValueError: # data type not inexact psi_eps = 0 try: phi_eps = np.finfo(phi.dtype).eps except ValueError: # data type not inexact phi_eps = 0 eps = max(psi_eps, phi_eps)*np.prod(psi.shape)*phi.shape[-1]*2 if not normalized: # normalization introduces more floating point error eps *= (np.prod(psi.shape)*phi.shape[-1]*2)**2 ... ... @@ -400,8 +407,8 @@ def check_phase_eq(psi: Union[qt.Qobj, Sequence], return abs(norm - modulus) <= eps, phase def dot_HS(U: Union[ndarray, qt.Qobj], V: Union[ndarray, qt.Qobj], def dot_HS(U: ndarray, V: ndarray, eps: float = None) -> float: r"""Return the Hilbert-Schmidt inner product of U and V, ... ... @@ -410,7 +417,7 @@ def dot_HS(U: Union[ndarray, qt.Qobj], Parameters ---------- U, V : Qobj or ndarray U, V : ndarray Objects to compute the inner product of. Returns ... ... @@ -420,17 +427,12 @@ def dot_HS(U: Union[ndarray, qt.Qobj], Examples -------- >>> U, V = qt.sigmax(), qt.sigmay() >>> U, V = qutil.qi.paulis[1:3] >>> dot_HS(U, V) 0.0 >>> dot_HS(U, U) 2.0 2 """ if isinstance(U, qt.Qobj): U = U.full() if isinstance(V, qt.Qobj): V = V.full() if eps is None: # Tolerance is the dtype precision times the number of flops for the # matrix multiplication times two to be on the safe side ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!