compress
Compression of a single MPS or MPO.
A thin wrapper around portc.stack.src for one-train stacks:
- MPO randomized compression.
- MPS randomized compression.
funccompress(tensor, chi_out, *, cutoff=0.0, oversample=1.0, dtype=None, seed=None, device='cpu', resources=None, optimize=DEFAULT_OPTIMIZE) -> list[np.ndarray]Applies the Successive Randomized Compression (SRC) algorithm.
Equivalent to src(tensor, ...); see portc.stack.src for the
conventions. The train type is inferred from the rank of the first site
tensor:
- MPS:
tensoris an MPS. Results in an MPS. - MPO:
tensoris an MPO. Results in an MPO.
Raises
TypeError: Ifchi_outis not an integer, the input tensor type is unsupported, oroptimizeis neither a name nor aPathOptimizer.ValueError: Ifchi_outis not positive, ifcutoffis not in[0.0, 1.0), ifoversampleis not finite and at least 1.0, if the train is not open-boundary, if a sub-three-site train is not exactly two sites, ifoptimizenames no opt_einsum path optimizer, or ifdeviceis not recognised.ImportError: Ifdevice="gpu"but cupy is not installed.
paramtensorSequence[Site]The site arrays of the tensor network to compress (MPS or MPO).
paramchi_outint | np.integerThe desired maximum bond dimension of the output tensor network.
paramcutofffloat= 0.0Relative singular-value cutoff for adaptive bond truncation.
Discards singular values below cutoff * sigma_max; see
portc.stack.src. Set to 0.0 (default) to disable cutoff
trimming. Ignored for two sites.
paramoversamplefloat | None= 1.0Multiplicative sketch-size factor, finite and at least 1.0,
or None for the paper's recommendation; see
portc.stack.src. Defaults to 1.0, no oversampling.
paramdtypeDTypeLike | None= NoneData type of the random sketches. Defaults to the promoted floating dtype of the inputs; an explicit dtype can promote the result.
paramseedint | None= NoneAn optional seed for the random number generator.
paramdevicestr= 'cpu'"cpu" (default, numpy) or "gpu" (cupy). Requires
the optional cupy dependency for GPU execution.
paramresourcesResources | None= NoneMemory budgets and scratch space; see portc.stack.src.
paramoptimizestr | PathOptimizer= DEFAULT_OPTIMIZEThe opt_einsum path optimizer of the contractions, a name or a
PathOptimizer; see portc.stack.src. Defaults to "dp".
Returns
listThe site arrays of the compressed tensor network (MPS or MPO), in right-canonical form, or left-canonical form when oversampling (three sites or more).