Idenso · latest
On this page

TensorNetwork

symbolica.community.tensor Class

TensorNetwork(expr: Any, library: Optional[TensorLibrary] = None)

An executable tensor calculation that retains component data.

Networks combine tensor contractions, sums, products, and elementwise functions. Arithmetic creates new networks. execute() advances a network in place; step() and to_tensor() work on copies. expression() returns the symbolic source, while status reports remaining work.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = network.to_tensor()
result[0, 1]

Constructor

#

Create a network from tensor components or symbolic algebra.

Returns

TensorNetwork

A new network with the corresponding external tensor interface.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.shape

Parameters

NameTypeDefaultDescription
exprAny—

Computation to represent. A Tensor retains its data; a TensorNetwork is copied with its execution progress.

libraryOptional[TensorLibrary]None

Component definitions. Defaults to the built-in four-dimensional Dirac and SU(3) library. Unregistered tensors receive symbolic components.

Member details

axes

Property · read-only#
axes: tuple[Slot | Representation, ...]

External axes in the current component and port-position order.

Returns

tuple of Slot or Representation

Indexed or unresolved axes, respectively. Component coordinates and methods taking axis positions use this order. It follows construction and explicit permute_axes() calls; structure.axes instead gives the canonical signature.

Examples

from symbolica.community.tensor import Representation, TensorName
r = Representation.euc(3)
A = TensorName("A")(r("j"), r("i"))
A.axes == (r("j"), r("i"))
A.permute_axes([1, 0]).axes == A.axes[::-1]

structure

Property · read-only#
structure: TensorStructure

Canonical external signature of the whole tensor.

Returns

TensorStructure

Free axes in canonical order, independent of names and component layout.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.structure.rank

rank

Property · read-only#
rank: int

Number of external tensor axes.

Returns

int

Zero for a scalar.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.rank

is_scalar

Property · read-only#
is_scalar: bool

Whether the tensor has no external axes.

Returns

bool

True exactly when rank is zero.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.is_scalar

shape

Property · read-only#
shape: tuple[int | Expression, ...]

Dimensions in logical axis order.

Returns

tuple of int or Expression

Axis sizes in the order of axes, the current component view.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.shape

status

Property · read-only#
status: ExecutionStatus

Read a snapshot of the remaining graph work without executing it.

Returns

ExecutionStatus

Counts and ready operations at the moment of inspection.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.status.complete

one

Static method#
one() -> TensorNetwork

Construct the scalar 1 network.

Examples

from symbolica.community import tensor as sp
network = sp.TensorNetwork.one()
value = network.to_tensor().scalar()

Returns

TensorNetwork

A rank-zero multiplicative identity.

Examples

from symbolica.community.tensor import TensorNetwork
TensorNetwork.one().result_scalar() == 1

bracket

Static method#
bracket() -> Expression

Return the symbolic function used to group a tensor subexpression.

Returns

Expression

A callable Symbolica head. Its argument is kept as a grouped tensor subexpression when parsed as a network.

Notes

This is useful when constructing raw Symbolica tensor syntax. Tensor-aware operations and simplifiers already understand this grouping.

Examples

from symbolica import S
from symbolica.community.tensor import TensorNetwork
grouped = TensorNetwork.bracket()(S("x") + 1)

broadcast

Static method#
broadcast(str: str) -> Expression

Register a raw Symbolica function for elementwise tensor application.

Returns

Expression

A callable Symbolica function head.

Notes

Prefer BroadcastFunction when applying the function to TensorExpression, Tensor, or TensorNetwork objects so the return type follows the operand.

Examples

from symbolica import S
from symbolica.community.tensor import TensorNetwork
applied = TensorNetwork.broadcast("raw_function")(S("x"))

Parameters

NameTypeDefaultDescription
strstr—

Function name to register with the broadcast tag.

zero

Static method#
zero() -> TensorNetwork

Construct the scalar 0 network.

Examples

from symbolica.community import tensor as sp
network = sp.TensorNetwork.zero()
value = network.to_tensor().scalar()

Returns

TensorNetwork

A rank-zero additive zero.

Examples

from symbolica.community.tensor import TensorNetwork
TensorNetwork.zero().result_scalar() == 0

replace

Method#
replace(pattern: _ScalarInput, rhs: _ReplacementInput, cond: Optional[PatternRestriction | Condition] = None, non_greedy_wildcards: Optional[Sequence[Expression]] = None, level_range: Optional[tuple[int, Optional[int]]] = None, level_is_tree_depth: Optional[bool] = None, allow_new_wildcards_on_rhs: Optional[bool] = None, rhs_cache_size: Optional[int] = None, repeat: Optional[bool] = None) -> TensorNetwork

Replace scalar expressions and symbolic component values in a copy.

Examples

from symbolica.community import tensor as sp
from symbolica import E, S
x = S("docs::x")
network = sp.TensorNetwork(sp.TensorExpression(x + 1))
replaced = network.replace(x, E("2"))

Returns

TensorNetwork

A copy with updated scalar/component expressions. Its external axes and symbolic source descriptor are unchanged.

Examples

from symbolica import S
from symbolica.community.tensor import Tensor, TensorName, Representation
x = S("x")
values = Tensor.dense(TensorName.vector("eval_v")(Representation.euc(2)), [x, x**2])
evaluator = values.evaluator([x], iterations=1, n_cores=1)
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(values).replace(x, 2)
network.to_tensor()[0] == 2

Parameters

NameTypeDefaultDescription
pattern_ScalarInput—

Symbolica pattern to find in scalar algebra and component expressions.

rhs_ReplacementInput—

Replacement expression. Python replacement callbacks are not supported by this network method; use TensorRule with TensorExpression for whole-tensor replacement.

condOptional[PatternRestriction | Condition]None

Restriction applied to candidate matches.

non_greedy_wildcardsOptional[Sequence[Expression]]None

Wildcards that should prefer shorter matches.

level_rangeOptional[tuple[int, Optional[int]]]None

Minimum and maximum matching level; defaults to (0, None).

level_is_tree_depthOptional[bool]None

Count tree depth rather than function nesting. Defaults to False.

allow_new_wildcards_on_rhsOptional[bool]None

Permit unbound wildcard symbols in the replacement. Defaults to False.

rhs_cache_sizeOptional[int]None

Maximum cached right-hand-side substitutions. Defaults to 100.

repeatOptional[bool]None

Repeat replacements until unchanged. Defaults to False.

evaluate

Method#
evaluate(constants: Mapping[Expression, float], functions: Mapping[Expression, Any]) -> TensorNetwork

Numerically evaluate symbolic component values in a network copy.

Returns

TensorNetwork

Network with evaluated component values; contractions are not executed.

Examples

from symbolica import S
from symbolica.community.tensor import Tensor, TensorName, Representation
x = S("x")
values = Tensor.dense(TensorName.vector("eval_v")(Representation.euc(2)), [x, x**2])
evaluator = values.evaluator([x], iterations=1, n_cores=1)
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(values).evaluate({x: 2.0}, {})
network.to_tensor()[1]
f = S("f_network")
data = Tensor.dense(values.expression(), [f(x), x])
network = TensorNetwork(data).evaluate({x: 2.0}, {f: lambda args: args[0] + 1})
network.to_tensor()[0]

Parameters

NameTypeDefaultDescription
constantsMapping[Expression, float]—

Real values for symbolic parameters.

functionsMapping[Expression, Any]—

Symbolica function heads and real-valued Python implementations. A callback receives one list of evaluated argument values and returns a float; for example, lambda args: args[0] ** 2.

execute

Method#
execute(library: Optional[TensorLibrary] = None, function_library: Optional[TensorFunctionLibrary] = None, n_steps: Optional[int] = None, mode: ExecutionMode = ExecutionMode.All) -> None

Advance this network's computation in place.

Returns

None

This network's execution progress and stored intermediate values change.

Notes

Use to_tensor() to evaluate a copy, or step() for an intermediate copy. result_tensor() extracts the result after execution.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.execute()
network.result_tensor()[1, 0]

Parameters

NameTypeDefaultDescription
libraryOptional[TensorLibrary]None

Component definitions. Defaults to the built-in four-dimensional Dirac and SU(3) library. Unregistered tensors receive symbolic components.

function_libraryOptional[TensorFunctionLibrary]None

Numerical implementations of broadcast functions. Defaults to the built-in function library.

n_stepsOptional[int]None

Number of execution rounds. None runs the selected strategy to completion.

modeExecutionModeExecutionMode.All

All uses MinIntermediateCost, which estimates sparse overlap and symbolic intermediate cost when choosing each contraction. Single selects one minimum-degree contraction at a time. Scalar restricts contraction to scalar work. Preprocessing and ready operations may also run in an execution round.

result_tensor

Method#
result_tensor(library: Optional[TensorLibrary] = None) -> Tensor

Read the component tensor from a completed network.

Returns

Tensor

Result components with the source computation's logical axis order.

Raises

RuntimeError

Work remains that prevents extracting one result tensor.

Notes

This does not run pending operations. Call execute() first, or use to_tensor() to execute a copy and extract the result in one operation. Existing component storage is preserved: exact Symbolica expressions are not converted to floating-point values.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.execute()
network.result_tensor().shape

Parameters

NameTypeDefaultDescription
libraryOptional[TensorLibrary]None

Component definitions. Defaults to the built-in four-dimensional Dirac and SU(3) library. Unregistered tensors receive symbolic components.

result_scalar

Method#
result_scalar() -> Expression

Read the scalar value of a completed rank-zero network.

Returns

Expression

Scalar result as Symbolica algebra.

Raises

RuntimeError

The network has not reduced to a scalar result.

Examples

from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(3)
network.execute()
network.result_scalar() == 3

__repr__

Method#
__repr__() -> str

Return a readable object description for inspection.

Examples

from symbolica.community import tensor as sp
r = sp.Representation.euc(2)
A = sp.TensorName("docs::A")(r, r)
tensor = sp.Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
network = tensor("i", "j") * tensor("j", "k")
text = repr(network)

__str__

Method#
__str__() -> str

Return a readable text representation.

Examples

from symbolica.community import tensor as sp
r = sp.Representation.euc(2)
A = sp.TensorName("docs::A")(r, r)
tensor = sp.Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
network = tensor("i", "j") * tensor("j", "k")
text = str(network)

_repr_latex_

Method#
_repr_latex_() -> str

No description is available for this member.

_repr_pretty_

Method#
_repr_pretty_(pretty: Any, cycle: bool) -> None

No description is available for this member.

Parameters

NameTypeDefaultDescription
prettyAny——
cyclebool——

to_dot

Method#
to_dot() -> str

Export the current network graph in Graphviz DOT syntax.

Returns

str

Graph description containing the current tensor nodes and connections.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
source = network.to_dot()

to_linnest

Method#
to_linnest(*, config: Optional[RenderSettings] = None) -> str

Export a self-contained Typst document embedding the native SVG graph.

Returns

str

Typst source containing the complete SVG and its typeset labels.

Notes

This depicts the current graph, including execution progress. For the symbolic computation in tensor notation, use formatted() or to_svg(). Graph geometry is drawn in Rust. Static exports reuse completed measurements, otherwise use optional Typst or estimated MathML label sizes.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
output = network.to_linnest()

Parameters

NameTypeDefaultDescription
configOptional[RenderSettings]None

Graph layout and rendering options. Omit for the standard network view.

render

Method#
render(*, config: Optional[RenderSettings] = None) -> DiagramView

Render a displayable snapshot of the current network graph.

Returns

DiagramRender

Interactive graph snapshot with SVG/HTML exports and notebook display.

Notes

This depicts the current graph, including execution progress. For the symbolic computation in tensor notation, use formatted() or to_svg(). Graph geometry is drawn in Rust. Static exports reuse completed measurements, otherwise use optional Typst or estimated MathML label sizes.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
output = network.render()

Parameters

NameTypeDefaultDescription
configOptional[RenderSettings]None

Graph layout and rendering options. Omit for the standard network view.

format_tensor

Method#
format_tensor(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None) -> str

Produce compact plain-text tensor notation.

Returns

str

Readable tensor text, suitable for logs or terminal output.

Notes

Only ports layout and default spacing are supported in this source format. Use to_html() or to_svg() for other layouts and custom gaps.

This formats the symbolic source expression, independent of execution progress. Use render() or to_html() for the network graph.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
output = network.format_tensor()

Parameters

NameTypeDefaultDescription
show_dimensionsOptional[bool]None

Override settings.show_dimensions for this call. None retains the selected settings, whose default omits dimensions.

settingsOptional[DisplaySettings]None

Tensor notation and display choices. Defaults to DisplaySettings().

to_typst

Method#
to_typst(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None) -> str

Produce static Typst math source.

Returns

str

Typst source without an enclosing document; no compilation is performed.

Notes

Only ports layout and default spacing are supported in this source format. Use to_html() or to_svg() for other layouts and custom gaps.

This formats the symbolic source expression, independent of execution progress. Use render() or to_html() for the network graph.

Static Typst output remains available independently of the HTML explorer.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
output = network.to_typst()

Parameters

NameTypeDefaultDescription
show_dimensionsOptional[bool]None

Override settings.show_dimensions for this call. None retains the selected settings, whose default omits dimensions.

settingsOptional[DisplaySettings]None

Tensor notation and display choices. Defaults to DisplaySettings().

formatted

Method#
formatted(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None, notation_source: Optional[str] = None) -> FormattedOutput

Create a lazy rich display value for a notebook.

Returns

FormattedOutput

Each requested backend renders the complete source expression once and caches it.

Notes

This formats the symbolic source expression, independent of execution progress, retaining a snapshot of that source. Use render() or to_html() for the network graph.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
output = network.formatted()

Parameters

NameTypeDefaultDescription
show_dimensionsOptional[bool]None

Override settings.show_dimensions for this call. None retains the selected settings, whose default omits dimensions.

settingsOptional[DisplaySettings]None

Tensor notation and display choices. Defaults to DisplaySettings().

notation_sourceOptional[str]None

Custom Typst notation source used by the rich renderer. This is Typst code, not a filename; omit it for the supplied tensor notation.

to_html

Method#
to_html(*, config: Optional[RenderSettings] = None, browser: Optional[str] = None) -> str

Display the current network graph and execution status.

Returns

str

Interactive HTML graph with its progress summary.

Notes

This depicts the current graph, including execution progress. For the symbolic computation in tensor notation, use formatted() or to_svg(). Graph geometry is drawn in Rust. Static exports reuse completed measurements, otherwise use optional Typst or estimated MathML label sizes.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
output = network.to_html()

Parameters

NameTypeDefaultDescription
configOptional[RenderSettings]None

Graph layout and rendering options. Omit for the standard network view.

browserOptional[str]None—

to_svg

Method#
to_svg(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None, notation_source: Optional[str] = None) -> str

Render static mathematical tensor notation to SVG. Requires the optional typst Python package. For the network diagram without that compiler, use network.render().to_svg() instead.

Returns

str

SVG markup suitable for embedding or saving to a file.

Notes

SVG export uses the optional Python package typst (typst-py). Pass the returned markup to the notebook's SVG display facility. Raises ImportError if the optional typst-py package is unavailable, or RuntimeError if compilation fails.

This formats the symbolic source expression, independent of execution progress. Use render() or to_html() for the network graph.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
output = network.to_svg()

Parameters

NameTypeDefaultDescription
show_dimensionsOptional[bool]None

Override settings.show_dimensions for this call. None retains the selected settings, whose default omits dimensions.

settingsOptional[DisplaySettings]None

Tensor notation and display choices. Defaults to DisplaySettings().

notation_sourceOptional[str]None

Custom Typst notation source used by the rich renderer. This is Typst code, not a filename; omit it for the supplied tensor notation.

_mime_

Method#
_mime_() -> Any

No description is available for this member.

_repr_mimebundle_

Method#
_repr_mimebundle_(include: Optional[Sequence[str]] = None, exclude: Optional[Sequence[str]] = None) -> Any

No description is available for this member.

Parameters

NameTypeDefaultDescription
includeOptional[Sequence[str]]None—
excludeOptional[Sequence[str]]None—

expression

Method#
expression() -> TensorExpression

Return the symbolic source computation of this network.

Returns

TensorExpression

A symbolic tensor with the same external axes.

Notes

Execution progress and replacement of component values do not rewrite this source expression. Use result_tensor after execution to inspect values.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.expression().rank

index

Method#
index(*indices: _IndexInput, intern: Optional[Literal['indices', 'flattened']] = None) -> TensorNetwork

Assign labels to the unresolved external axes.

Returns

TensorNetwork

An indexed network retaining the component data; the original is unchanged.

Notes

Existing explicit labels are left in place. Use reindex to replace them.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
indexed = network.index("i", "j")
indexed.rank

Parameters

NameTypeDefaultDescription
indices_IndexInput——
internOptional[Literal['indices', 'flattened']]None

Encode unknown function-valued index labels before checking the tensor structure. "indices" retains reversible payloads; "flattened" creates readable names. Both preserve index tags and leave scalar arguments and tensor heads intact. Native index forms, including named, scoped, and open indices, remain unchanged. None accepts native index forms without encoding unknown function labels.

reindex

Method#
reindex(*indices: _IndexInput, intern: Optional[Literal['indices', 'flattened']] = None) -> TensorNetwork

Assign labels to all external axes.

Returns

TensorNetwork

An indexed network retaining the component data; the original is unchanged.

Notes

Existing labels are replaced as well as unresolved axes.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
indexed = network.reindex("i", "j")
indexed.rank

Parameters

NameTypeDefaultDescription
indices_IndexInput——
internOptional[Literal['indices', 'flattened']]None

Encode unknown function-valued index labels before checking the tensor structure. "indices" retains reversible payloads; "flattened" creates readable names. Both preserve index tags and leave scalar arguments and tensor heads intact. Native index forms, including named, scoped, and open indices, remain unchanged. None accepts native index forms without encoding unknown function labels.

rename_indices

Method#
rename_indices(mapping: dict[int | str | Expression | Slot, _IndexInput], *, intern: Optional[Literal['indices', 'flattened']] = None) -> TensorNetwork

Rename selected external labels without changing the tensor rank.

Returns

TensorNetwork

A new value with renamed axes; the original is unchanged.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
indexed = network.index("i", "j")
renamed = indexed.rename_indices({"i": "k"})
renamed.rank

Parameters

NameTypeDefaultDescription
mappingdict[int | str | Expression | Slot, _IndexInput]—

Old label to new label. A Slot key also restricts the representation. Keys must identify existing external axes. Each axis may be renamed once; renaming must preserve the external interface.

internOptional[Literal['indices', 'flattened']]None

Encode unknown function-valued index labels before checking the tensor structure. "indices" retains reversible payloads; "flattened" creates readable names. Both preserve index tags and leave scalar arguments and tensor heads intact. Native index forms, including named, scoped, and open indices, remain unchanged. None accepts native index forms without encoding unknown function labels.

permute_axes

Method#
permute_axes(axes: Sequence[int]) -> TensorNetwork

Reorder the external axes in logical component order.

Returns

TensorNetwork

A new tensor view with the reordered interface and correspondingly reordered component access.

Notes

This permutes axes; it does not conjugate component values.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
transposed = network.permute_axes([1, 0])
transposed.shape

Parameters

NameTypeDefaultDescription
axesSequence[int]—

Each current axis position exactly once, in the desired new order. For a matrix, [1, 0] exchanges the two axes.

__copy__

Method#
__copy__() -> TensorNetwork

Implement copy.copy using an independent TensorNetwork copy.

Returns

TensorNetwork

Copy of the component data and execution progress.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
import copy
copied = copy.copy(network)

__call__

Method#
__call__(*indices: _IndexInput, intern: Optional[Literal['indices', 'flattened']] = None) -> TensorNetwork

Assign labels to the unresolved external axes.

Returns

TensorNetwork

An indexed network retaining the component data; the original is unchanged.

Notes

Equivalent to index(*indices).

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
indexed = network("i", "j")
indexed.rank

Parameters

NameTypeDefaultDescription
indices_IndexInput——
internOptional[Literal['indices', 'flattened']]None

Encode unknown function-valued index labels before checking the tensor structure. "indices" retains reversible payloads; "flattened" creates readable names. Both preserve index tags and leave scalar arguments and tensor heads intact. Native index forms, including named, scoped, and open indices, remain unchanged. None accepts native index forms without encoding unknown function labels.

__neg__

Method#
__neg__() -> TensorNetwork

Negate every tensor component.

Returns

TensorNetwork

Negated symbolic algebra retaining component data lazily.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
negated = -network

__add__

Method#
__add__(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Add tensors with compatible external interfaces.

Returns

TensorNetwork

New lazy calculation; operands are unchanged.

Notes

Scalar zero acts as the additive identity. Other scalars can be added only to rank-zero tensors.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = network + network

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Other operand. Component data are retained in a lazy network.

__radd__

Method#
__radd__(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Implement reflected addition.

Returns

TensorNetwork

New lazy calculation; operands are unchanged.

Notes

Scalar zero acts as the additive identity. Other scalars can be added only to rank-zero tensors.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = network + network

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Other operand. Component data are retained in a lazy network.

__sub__

Method#
__sub__(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Subtract tensors with compatible external interfaces.

Returns

TensorNetwork

New lazy calculation; operands are unchanged.

Notes

Subtraction requires matching tensor axes; a nonzero scalar cannot be subtracted from a tensor with external axes.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = network - network

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Other operand. Component data are retained in a lazy network.

__rsub__

Method#
__rsub__(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Implement reflected subtraction.

Returns

TensorNetwork

New lazy calculation; operands are unchanged.

Notes

Subtraction requires matching tensor axes; a nonzero scalar cannot be subtracted from a tensor with external axes.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = network - network

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Other operand. Component data are retained in a lazy network.

__mul__

Method#
__mul__(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Multiply tensors, contracting unambiguous compatible axes.

Returns

TensorNetwork

New lazy calculation; operands are unchanged.

Notes

Matching explicit labels contract. Compatible unresolved axes are paired only when the choice is unambiguous. Use outer(), contract_ports(), or compose() to make the intended pairing explicit.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = network * 2

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Other operand. Component data are retained in a lazy network.

__rmul__

Method#
__rmul__(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Implement reflected multiplication.

Returns

TensorNetwork

New lazy calculation; operands are unchanged.

Notes

Matching explicit labels contract. Compatible unresolved axes are paired only when the choice is unambiguous. Use outer(), contract_ports(), or compose() to make the intended pairing explicit.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = 2 * network

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Other operand. Component data are retained in a lazy network.

__truediv__

Method#
__truediv__(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Divide tensor components by a scalar expression.

Returns

TensorNetwork

New lazy calculation; operands are unchanged.

Notes

The denominator must be scalar. For scalar divided by tensor, the tensor must also have rank zero.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = network / 2

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Other operand. Component data are retained in a lazy network.

__rtruediv__

Method#
__rtruediv__(lhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Implement reflected division.

Returns

TensorNetwork

New lazy calculation; operands are unchanged.

Notes

The denominator must be scalar. For scalar divided by tensor, the tensor must also have rank zero.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
result = 2 / TensorNetwork(3)

Parameters

NameTypeDefaultDescription
lhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Other operand. Component data are retained in a lazy network.

outer

Method#
outer(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Form an outer product without implicit contractions between the operands.

Returns

TensorNetwork

A lazy outer product retaining the operands' component data.

Notes

Use this when compatible unresolved axes should remain independent. Choose explicit distinct labels if you need to refer to them separately.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
product = network.outer(network)
product.rank

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Tensor whose axes follow this tensor's axes.

contract_ports

Method#
contract_ports(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork], *, left: int, right: int) -> TensorNetwork

Contract one chosen pair of axes between two tensors.

Returns

TensorNetwork

A lazy contraction retaining component data.

Notes

Other axes remain external. Axis numbers refer to axes.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
contracted = network.contract_ports(network, left=1, right=0)
contracted.rank

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Tensor to contract with this tensor.

leftint—

Zero-based axis positions in this tensor and rhs, respectively. The representations must be compatible under contraction.

rightint—

Zero-based axis positions in this tensor and rhs, respectively. The representations must be compatible under contraction.

compose

Method#
compose(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork], *, left: tuple[int, int], right: tuple[int, int]) -> TensorNetwork

Multiply two tensors along explicitly selected matrix channels.

Returns

TensorNetwork

A lazy ordered matrix product retaining component data.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
product = network.compose(network, left=(0, 1), right=(0, 1))
product.rank

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Next factor in the ordered matrix product.

lefttuple[int, int]—

(input_axis, output_axis) in this tensor and rhs, respectively. The left output contracts with the right input. Other axes are retained as spectator axes.

righttuple[int, int]—

(input_axis, output_axis) in this tensor and rhs, respectively. The left output contracts with the right input. Other axes are retained as spectator axes.

dot

Method#
dot(rhs: _ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]) -> TensorNetwork

Contract two rank-one tensors using their representation pairing.

Returns

TensorNetwork

A lazy scalar contraction, including the metric signs of the space.

Examples

from symbolica.community.tensor import TensorName, Tensor, TensorNetwork, Representation
vector = Tensor.dense(TensorName.vector("dot_v")(Representation.euc(2)), [1.0, 2.0])
TensorNetwork(vector).dot(vector).to_tensor().scalar() == 5

Parameters

NameTypeDefaultDescription
rhs_ScalarInput | TensorExpression | TensorNetwork | Tensor | FactorProjector[TensorExpression] | FactorProjector[TensorNetwork]—

Rank-one tensor in a compatible space.

trace

Method#
trace(*, channel: Optional[tuple[int, int]] = None) -> TensorNetwork

Close a pair of matrix axes on this tensor.

Returns

TensorNetwork

The traced tensor; spectator axes remain external.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.trace(channel=(0, 1)).is_scalar

Parameters

NameTypeDefaultDescription
channelOptional[tuple[int, int]]None

(input_axis, output_axis) to contract. If omitted, the matrix channel must be uniquely determined by the representations. Specify it when more than one pairing is possible.

copy

Method#
copy() -> TensorNetwork

Copy this network and its current execution progress.

Returns

TensorNetwork

An independent copy. Changes to it do not alter the original.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
copied = network.copy()
copied.shape == network.shape

step

Method#
step(library: Optional[TensorLibrary] = None, *, function_library: Optional[TensorFunctionLibrary] = None) -> TensorNetwork

Run one execution round on a copy of this network.

Returns

TensorNetwork

Next intermediate computation; this network remains unchanged.

Notes

The round uses ExecutionMode.Single and includes the usual preprocessing; it is not a promise to remove exactly one graph node.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
intermediate = network.step()
intermediate.shape

Parameters

NameTypeDefaultDescription
libraryOptional[TensorLibrary]None

Component definitions. Defaults to the built-in four-dimensional Dirac and SU(3) library. Unregistered tensors receive symbolic components.

function_libraryOptional[TensorFunctionLibrary]None

Numerical implementations of broadcast functions. Defaults to the built-in function library.

to_tensor

Method#
to_tensor(library: Optional[TensorLibrary] = None, *, function_library: Optional[TensorFunctionLibrary] = None) -> Tensor

Evaluate an independent copy of this network and return its components.

Returns

Tensor

Resulting components in logical axis order. Dimensions must be concrete.

Notes

The original network and its execution progress and the supplied libraries are unchanged.

Examples

from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import TensorNetwork
network = TensorNetwork(tensor)
network.to_tensor().shape

Parameters

NameTypeDefaultDescription
libraryOptional[TensorLibrary]None

Component definitions. Defaults to the built-in four-dimensional Dirac and SU(3) library. Unregistered tensors receive symbolic components.

function_libraryOptional[TensorFunctionLibrary]None

Numerical implementations of broadcast functions. Defaults to the built-in function library.