Skip to content

Commit 76d0148

Browse files
committed
tweak docstrings
1 parent 0af5f5f commit 76d0148

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

docs/changelog.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Release notes for `quimb`.
77

88
**Breaking Changes**
99

10-
- move belief propagation to `quimb.tensor.belief_propagation`
11-
- calling `tn.contract()` when an non-zero value has been accrued into `tn.exponent` now automatically re-absorbs that exponent.
10+
- move belief propagation to [`quimb.tensor.belief_propagation`](quimb.tensor.belief_propagation)
11+
- calling [`tn.contract()`](quimb.tensor.tensor_core.TensorNetwork.contract) when an non-zero value has been accrued into `tn.exponent` now automatically re-absorbs that exponent.
1212

1313
**Enhancements:**
1414

quimb/tensor/tensor_core.py

+33-33
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def tensor_contract(
274274
If `True`, return the exponent of the result, log10, as well as the
275275
rescaled 'mantissa'. Useful for very large or small values.
276276
exponent : float, optional
277-
If supplied, a base exponent to add to the result exponent.
277+
If supplied, an overall base exponent to scale the result by.
278278
contract_opts
279279
Passed to ``cotengra.array_contract``.
280280
@@ -3593,8 +3593,8 @@ def _tensor_network_gate_inds_basic(
35933593
trn = tr_L @ tr_Q
35943594

35953595
# if singular values are returned (``absorb=None``) check if we should
3596-
# return them via ``info``, e.g. for ``SimpleUpdate`
3597-
if maybe_svals and info is not None:
3596+
# return them further via ``info``, e.g. for ``SimpleUpdate`
3597+
if maybe_svals and (info is not None):
35983598
s = next(iter(maybe_svals)).data
35993599
info["singular_values", bix] = s
36003600

@@ -7189,9 +7189,9 @@ def gauge_all_simple(
71897189
tol : float, optional
71907190
The convergence tolerance for the singular values.
71917191
smudge : float, optional
7192-
The smudge factor to add to the singular values when gauging.
7192+
A small value to add to the singular values when gauging.
71937193
power : float, optional
7194-
The power to raise the singular values to when gauging.
7194+
A power to raise the singular values to when gauging.
71957195
damping : float, optional
71967196
The damping factor to apply to the gauging updates.
71977197
gauges : dict, optional
@@ -8218,8 +8218,14 @@ def contract_compressed(
82188218
Whether to compress pairs of tensors that are effectively matrices.
82198219
compress_exclude : set[int], optional
82208220
An explicit set of tensor ids to exclude from compression.
8221-
equalize_norms : bool or float, optional
8222-
Whether to equalize the norms of the tensors after each operation.
8221+
strip_exponent : bool, optional
8222+
Whether the strip an overall exponent, log10, from the *final*
8223+
contraction. If a TensorNetwork is returned, this exponent is
8224+
accumulated in the `exponent` attribute. If a Tensor or scalar is
8225+
returned, the exponent is returned separately.
8226+
equalize_norms : bool or "auto", optional
8227+
Whether to equalize the norms of the tensors *during* the
8228+
contraction. By default ("auto") this follows `strip_exponent`.
82238229
The overall scaling is accumulated, log10, into `tn.exponent`. If
82248230
`True`, at the end this exponent is redistributed. If a float,
82258231
this is the target norm to equalize tensors to, e.g. `1.0`, and the
@@ -8846,11 +8852,10 @@ def contract(
88468852
output_inds=None,
88478853
optimize=None,
88488854
get=None,
8849-
backend=None,
8850-
preserve_tensor=False,
88518855
max_bond=None,
88528856
strip_exponent=False,
8853-
exponent=True,
8857+
preserve_tensor=False,
8858+
backend=None,
88548859
inplace=False,
88558860
**kwargs,
88568861
):
@@ -8897,20 +8902,17 @@ def contract(
88978902
with detailed information such as flop cost. The symbol-map is
88988903
also added to the ``quimb_symbol_map`` attribute.
88998904
8900-
backend : {'auto', 'numpy', 'jax', 'cupy', 'tensorflow', ...}, optional
8901-
Which backend to use to perform the contraction. Supplied to
8902-
`cotengra`.
8905+
strip_exponent : bool, optional
8906+
Whether the strip an overall exponent, log10, from the *final*
8907+
contraction. If a TensorNetwork is returned, this exponent is
8908+
accumulated in the `exponent` attribute. If a Tensor or scalar is
8909+
returned, the exponent is returned separately.
89038910
preserve_tensor : bool, optional
89048911
Whether to return a tensor regardless of whether the output object
89058912
is a scalar (has no indices) or not.
8906-
strip_exponent : bool, optional
8907-
If contracting the entire tensor network, whether to strip a log10
8908-
exponent and return it separately. This is useful for very large or
8909-
small values.
8910-
exponent : float, optional
8911-
The current exponent to scale the whole contraction by. If ``True``
8912-
this taken from `tn.exponent`. If `False` then this is ignored.
8913-
If a float, this is the exponent to use.
8913+
backend : {'auto', 'numpy', 'jax', 'cupy', 'tensorflow', ...}, optional
8914+
Which backend to use to perform the contraction. Supplied to
8915+
`cotengra`.
89148916
inplace : bool, optional
89158917
Whether to perform the contraction inplace. This is only valid
89168918
if not all tensors are contracted (which doesn't produce a TN).
@@ -8945,8 +8947,6 @@ def contract(
89458947
raise NotImplementedError
89468948
if kwargs.pop("backend", None) is not None:
89478949
raise NotImplementedError
8948-
if exponent is not True:
8949-
raise NotImplementedError
89508950

89518951
return self.contract_compressed(
89528952
max_bond=max_bond,
@@ -8959,9 +8959,6 @@ def contract(
89598959
# contraction pattern (e.g. 1D along the line)
89608960
if self._CONTRACT_STRUCTURED:
89618961

8962-
if exponent is not True:
8963-
raise NotImplementedError
8964-
89658962
if (tags is ...) or isinstance(tags, slice):
89668963
return self.contract_structured(
89678964
tags,
@@ -8973,15 +8970,10 @@ def contract(
89738970
# contracting everything to single output
89748971
if all_tags and not inplace:
89758972

8976-
if exponent is True:
8977-
exponent = self.exponent
8978-
elif exponent is False:
8979-
exponent = 0.0
8980-
89818973
return tensor_contract(
89828974
*self.tensor_map.values(),
89838975
strip_exponent=strip_exponent,
8984-
exponent=exponent,
8976+
exponent=self.exponent,
89858977
**kwargs
89868978
)
89878979

@@ -8999,9 +8991,9 @@ def contract_cumulative(
89998991
self,
90008992
tags_seq,
90018993
output_inds=None,
9002-
preserve_tensor=False,
90038994
strip_exponent=False,
90048995
equalize_norms="auto",
8996+
preserve_tensor=False,
90058997
inplace=False,
90068998
**contract_opts,
90078999
):
@@ -9018,6 +9010,14 @@ def contract_cumulative(
90189010
The indices to specify as outputs of the contraction. If not given,
90199011
and the tensor network has no hyper-indices, these are computed
90209012
automatically as every index appearing once.
9013+
strip_exponent : bool, optional
9014+
Whether the strip an overall exponent, log10, from the *final*
9015+
contraction. If a TensorNetwork is returned, this exponent is
9016+
accumulated in the `exponent` attribute. If a Tensor or scalar is
9017+
returned, the exponent is returned separately.
9018+
equalize_norms : bool or "auto", optional
9019+
Whether to equalize the norms of the tensors *during* the
9020+
contraction. By default ("auto") this follows `strip_exponent`.
90219021
preserve_tensor : bool, optional
90229022
Whether to return a tensor regardless of whether the output object
90239023
is a scalar (has no indices) or not.

0 commit comments

Comments
 (0)