How-To Guides#

Each page here answers a task rather than explaining a feature. The User Guide teaches the concepts in order and is the better place to start if Einsums is new to you. Come here when you know roughly what you want and need the specific way to do it.

The code on the contractions, views, graphs, and porting-from-NumPy pages is exercised by the documentation snippet tests in docs/doctests/, so what those pages say something returns, prints, or throws is measured output rather than expectation. The other pages are checked against the source but are not run as tests.

Find your task#

I want to

See

Contract two tensors and know which kernel ran

Contractions

Take a diagonal, a trace, or a transpose

Contractions

Get a single number out of a contraction

Contractions

Work on a sub-block without copying it

Views and Slicing

Write into a tensor I am also reading

Contractions

Capture a calculation once and replay it

Compute Graphs

Find out why an optimization pass did nothing

Compute Graphs

Build a correlated method end to end

Build a Spin-Orbital CCSD

Translate code I already have in NumPy

Porting from NumPy

Move data between psi4 and Einsums

Working with psi4

Add a runtime option to a module

Add a Runtime Option

Create a new module

Add a Module

Expose a C++ type to Python

Expose a Type to Python

Write my own optimization pass

Write an Optimization Pass

Building a method

Porting existing code

Two conventions used throughout#

Specs use a semicolon. An Einsums contraction spec separates the two operands with ; and not with the comma NumPy uses. "ik;kj->ij" and the equivalent "ij <- ik ; kj" are both accepted. In C++ the spec is checked while your code compiles, so a malformed one is a compile error rather than a surprise at run time.

Graph work prefers RuntimeTensor. einsums::RuntimeTensor is the tensor type the ComputeGraph is built around, and it is what the Python bindings expose, so a C++ capture and its Python equivalent read the same. The statically ranked einsums::Tensor works in a capture as well, and is the natural choice for eager code whose ranks are known while you write it.

What does matter in a capture is saying which graph-owned tensors are results rather than scratch, because the optimizer removes computations nothing reads. Say which tensors are results covers it, and it is the one mistake on these pages that can pass without an error.