quimb.tensor.gating¶
Functionality relating to gating tensor networks, i.e. applying a ‘gate’ - typically a local operator described by a raw array - to one or more indices in the network, maintaining the outer index structure by appropriate reindexing.
Attributes¶
Functions¶
|
|
|
|
|
|
|
Possibly reshape gate |
|
Apply a local 'gate' |
|
|
|
Apply a 'sandwich' gate, |
Module Contents¶
- quimb.tensor.gating._tensor_network_gate_inds_basic(tn: quimb.tensor.tensor_core.TensorNetwork, G, inds, ng, tags, contract, isparam, info, **compress_opts)[source]¶
- quimb.tensor.gating._tensor_network_gate_inds_eager_split(tn, inds, contract, reindex_map, TG, info, compress_opts)[source]¶
- quimb.tensor.gating._tensor_network_gate_inds_lazy_split(tn: quimb.tensor.tensor_core.TensorNetwork, G, inds, ng, tags, contract, **compress_opts)[source]¶
- quimb.tensor.gating._BASIC_GATE_CONTRACT¶
- quimb.tensor.gating._SPLIT_GATE_CONTRACT¶
- quimb.tensor.gating._VALID_GATE_CONTRACT¶
- quimb.tensor.gating.maybe_factor_gate(G, inds, xp=None, tn=None)[source]¶
Possibly reshape gate
G, if it has been supplied as a matrix with ‘fused’ dimensions, into a tensor with separate physical dimensions.
- quimb.tensor.gating.tensor_network_gate_inds(self: quimb.tensor.tensor_core.TensorNetwork, G, inds, contract=False, tags=None, info=None, inplace=False, **compress_opts)[source]¶
Apply a local ‘gate’
G, given as a raw array, to a group of indicesinds, as if applyingG @ x. The indices are propagated to the outside to maintain the original index structure of the tensor network.- Parameters:
G (array_ike) – The gate array to apply, should match or be factorable into the shape
(*phys_dims, *phys_dims).inds (str or sequence or str,) – The index or indices to apply the gate to.
contract (bool or str, optional) –
How to apply the gate:
False: gate is added to network lazily and nothing is contracted, tensor network structure is thus not maintained.True: gate is contracted eagerly with all tensors involved, tensor network structure is thus only maintained if gate acts on a single site only.'split': contract all involved tensors then split the result back into two.'reduce-split': factor the two physical indices into ‘R-factors’ using QR decompositions on the original site tensors, then contract the gate, split it and reabsorb each side. Cheaper than'split'when the tensors on either side have at least 3 bonds.'split-gate': lazily add the gate as withFalse, but split the gate tensor spatially.'swap-split-gate': lazily add the gate as withFalse, but split the gate as if an extra SWAP has been applied.'auto-split-gate': lazily add the gate as withFalse, but maybe apply one of the above options depending on whether they result in a rank reduction.
The named methods are relevant for two site gates only, for single site gates they use the
contract=Trueoption which also maintains the structure of the TN. See below for a pictorial description of each method.tags (str or sequence of str, optional) – Tags to add to the new gate tensor.
info (None or dict, optional) – Used to store extra optional information such as the singular values if not absorbed.
inplace (bool, optional) – Whether to perform the gate operation inplace on the tensor network or not.
compress_opts – Supplied to
tensor_split()for anycontractmethods that involve splitting. Ignored otherwise. Key options include max_bond and cutoff.
- Returns:
G_tn
- Return type:
Notes
The
contractoptions look like the following (for two site gates).contract=False:. . <- inds │ │ GGGGG │╱ │╱ ──●───●── ╱ ╱
contract=True:│╱ │╱ ──GGGGG── ╱ ╱
contract='split':│╱ │╱ │╱ │╱ ──GGGGG── ==> ──G┄┄┄G── ╱ ╱ ╱ ╱ <SVD>
contract='reduce-split':│ │ │ │ GGGGG GGG │ │ │╱ │╱ ==> ╱│ │ ╱ ==> ╱│ │ ╱ │╱ │╱ ──●───●── ──▶─●─●─◀── ──▶─GGG─◀── ==> ──G┄┄┄G── ╱ ╱ ╱ ╱ ╱ ╱ ╱ ╱ <QR> <LQ> <SVD>
For one site gates when one of the above ‘split’ methods is supplied
contract=Trueis assumed.contract='split-gate':│ │ <SVD> G~~~G │╱ │╱ ──●───●── ╱ ╱
contract='swap-split-gate':╲ ╱ ╳ ╱ ╲ <SVD> G~~~G │╱ │╱ ──●───●── ╱ ╱contract='auto-split-gate'chooses between the above two andFalse, depending on whether either results in a lower rank.
- quimb.tensor.gating._tensor_network_gate_sandwich_inds_eager_split(tn, G, Gconj, inds_upper, inds_lower, contract, tags, info, **compress_opts)[source]¶
- quimb.tensor.gating.tensor_network_gate_sandwich_inds(self: quimb.tensor.tensor_core.TensorNetwork, G, inds_upper, inds_lower, contract=False, tags=None, tags_upper=None, tags_lower=None, info=None, inplace=False, **compress_opts)[source]¶
Apply a ‘sandwich’ gate,
Gto two groups of indices in a tensor network, i.e. applyingG @ x @ G†to the indices given respectively byinds_upperandinds_lower, then propagating them to the outside, to maintain the original index structure.- Garray_ike
The gate array to apply, should match or be factorable into the shape
(*phys_dims, *phys_dims).- inds_upperstr or sequence or str,
The upper (ket-like) index or indices to apply the gate to.
- inds_lowerstr or sequence or str,
The lower (bra-like) index or indices to apply the conjugate gate to.
- contractbool or str, optional
How to apply the gate, see
tensor_network_gate_inds()for details and pictorial representations.- tagsstr or sequence of str, optional
Tags to add to both new gate tensors.
- tags_upperstr or sequence of str, optional
Tags to add to the upper gate tensor only.
- tags_lowerstr or sequence of str, optional
Tags to add to the lower gate tensor only.
- infoNone or dict, optional
Used to store extra optional information such as the singular values if not absorbed.
- inplacebool, optional
Whether to perform the gate operation inplace on the tensor network or not.
- compress_opts
Supplied to
tensor_split()for anycontractmethods that involve splitting. Ignored otherwise. Key options include max_bond and cutoff.
- Returns:
G_tn
- Return type: