Skip to content

Contraction

Specification of which edges to contract between two CG tensors.

Contraction

Contraction(axes_a: list[int], axes_b: list[int])

Edge-pair specification for contracting two CG tensors.

Parameters:

Name Type Description Default
axes_a list[int]

Edge indices from the first CGSpec to contract.

required
axes_b list[int]

Edge indices from the second CGSpec to contract.

required

Examples:

>>> import yuzuha
>>> # Contract edge 2 of spec_a with edge 0 of spec_b
>>> c = yuzuha.Contraction([2], [0])
>>> # Contract two pairs simultaneously
>>> c2 = yuzuha.Contraction([2, 3], [0, 1])

axes_a property

axes_a: list[int]

Edge indices to contract from the first CGSpec.

Returns:

Type Description
list[int]

Axis indices into spec A.

axes_b property

axes_b: list[int]

Edge indices to contract from the second CGSpec.

Returns:

Type Description
list[int]

Axis indices into spec B.

Description

Contraction records the pairs of edge indices to be contracted when calling compute_xsymbol. Each pair \((i, k)\) indicates that edge \(i\) of the first tensor (spec A) is contracted with edge \(k\) of the second tensor (spec B).

import yuzuha

# Contract edge 2 of spec_a with edge 0 of spec_b
contraction = yuzuha.Contraction([2], [0])

# Contract multiple pairs
contraction2 = yuzuha.Contraction([2, 3], [0, 1])

Fields

Attribute Type Description
axes_a list[int] Edge indices from spec A to contract
axes_b list[int] Edge indices from spec B to contract

Validation

A Contraction is valid if:

  1. axes_a and axes_b have the same length
  2. Each index in axes_a is in range [0, spec_a.num_external())
  3. Each index in axes_b is in range [0, spec_b.num_external())
  4. For every pair \((i, k)\): the spin of edge \(i\) in spec A equals the spin of edge \(k\) in spec B
  5. For every pair \((i, k)\): the direction of edge \(i\) in spec A is opposite to the direction of edge \(k\) in spec B (one incoming, one outgoing)

Violations raise ValueError from compute_xsymbol.

See Also

Notes

Contraction objects are immutable and can be reused across multiple compute_xsymbol calls with compatible specs.

The order of pairs in axes_a and axes_b matters: pair \((i, k)\) at position 0 is treated as the first contraction, which affects the internal fusion tree ordering of the output spec \(C\).