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 |
|
Take a diagonal, a trace, or a transpose |
|
Get a single number out of a contraction |
|
Work on a sub-block without copying it |
|
Write into a tensor I am also reading |
|
Capture a calculation once and replay it |
|
Find out why an optimization pass did nothing |
|
Build a correlated method end to end |
|
Translate code I already have in NumPy |
|
Move data between psi4 and Einsums |
|
Add a runtime option to a module |
|
Create a new module |
|
Expose a C++ type to Python |
|
Write my own optimization pass |
Using Einsums
Building a method
Porting existing code
Extending Einsums
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.