vprusso/toqito

Add tests for toqito/state_ops/schmidt_decomposition.py: 84, 138-140, 142->146, 147-155, 157->161

Closed this issue · 0 comments

raise ValueError(
"InvalidDim: The value of `dim` must evenly divide"
" `len(vec)`; please provide a `dim` array "
"containing the dimensions of the subsystems."
)

if dim is None:
dim_x = rho.shape
sqrt_dim = np.round(np.sqrt(dim_x))
dim = np.array([[sqrt_dim[0], sqrt_dim[0]], [sqrt_dim[1], sqrt_dim[1]]])

if isinstance(dim, list):
dim = np.array(dim)

if isinstance(dim, int):
dim = np.array([dim, len(rho) / dim])
if np.abs(dim[1] - np.round(dim[1])) >= 2 * len(rho) * eps:
raise ValueError(
"InvalidDim: If `dim` is an integer, `rho` must be square"
" and `dim` must evenly divide `len(rho)`;"
" please provide a `dim` array containing"
" the dimensions of the subsystems."
)
dim[1] = np.round(dim[1])

if min(dim.shape) == 1 or len(dim.shape) == 1:
dim = np.array([dim, dim])