treetensor
Kinetic plasma simulation on tree tensor networks.
The ttn module calls a C++20 runtime in double precision.
The same model runs in the browser as the npm package @tensortree/plasma.
pip install treetensor
Wheels exist for Linux x86_64 and aarch64 (glibc 2.17 or later) and for macOS 14 or later on Apple silicon. Python 3.11 and later are supported.
Landau damping
import math
import ttn as t
x, v = t.periodic("x", 48, [0, 4 * math.pi]), t.periodic("v", 64, [-6, 6])
space, velocity = t.cartesian(x), t.cartesian(v)
density = t.cosine(x, 0.5, offset=1, amplitude=0.04)
electrons = t.species("electrons", charge=-1, mass=1, velocity=velocity,
initial=t.normalized(t.maxwellian(velocity, density=density), space.volume))
fields = t.maxwell(c_squared=16, electric=t.vector(x=-0.08 * t.sine(x, 0.5)))
plasma = t.vlasov(space=space, species=[electrons], fields=fields)
Ex = plasma.observable("Ex", t.component(plasma.fields.electric, "x"))
simulation = (t.run(plasma)
.represent(electrons.f, t.ttn(rank=t.automatic(capacity=48)))
.time(t.fixed_step(0.05, final_time=40))
.compile())
while not simulation.done:
simulation.advance()
field = simulation.tensor(Ex) # NumPy copy over x
energy = simulation.value(plasma.energy.total) # float
Workflow
- Axes.
periodic(name, cells, bounds)anduniform(...)create axes;cartesian(x, y)groups them into a frame with x, y, z components. - Model.
vlasov(space=..., species=[...], fields=...)returns aPlasmawith the distributionspecies.f, the equationgroups, the timeschemeand themass,energyandfieldsobservables. For other equations, create aModeland callstate,group,observable,doughertyandbgkon it. Add every observable to the model (plasma.observable(...)ormodel.observable(...)) before the firstdescribe()orcompile(). - Run.
run(model)collects numerical settings:represent(state, ttn(...) | dense()),time(fixed_step(...) | adaptive_step(...)), and for aModelalsoscheme(...).transport(state, maps.streaming(...)),streaming(state, False)andobserve(...)(keep a value resident, evaluated every step) are optional. - Simulation.
compile()returns aSimulationwithadvance(),retreat(),time,steps,done,report(), andtensor(x)/value(x)for any state or observable of the model. A run and a model can be compiled more than once, for example to compare integrators.
Values
Axes, states and expressions combine with + - * / **; an axis stands for its coordinate, so -v * t.diff(f, x) is the free-streaming term.
Elementary functions (exp, cos, sqrt, bessel_j0, ...) and calculus (diff, grad, curl, integrate, dot, cross, component) accept any of them.
Initial values are usually profiles: gaussian(axis, mean, sigma), cosine(axis, k, amplitude=, offset=, phase=), sine(...), profile(axis, function), samples(axis, values) and vector(x=..., y=..., z=...).
Profiles combine with +, -, * and / by a number, and stay separable, so a TTN state starts without sampling the full grid.
normalized(profile, integral) fixes the integral of an initial value and cannot be combined further.
A profile used in an expression becomes a coefficient table.
sampled(indices, function) and tree_sampled(axes, function) give nonseparable initial values; an expression also works.
Numerics
- Representations:
ttn(tree="automatic" | [[x, y], [z, v]], rank=automatic(capacity=96) | adaptive(...) | fixed(rank=...) | int)ordense(). - Integrators:
strang()(default),lie(),ps_abug(),sgm(),pfg(core_flow="cayley" | "pade22" | "sdirk2"),coupled_midpoint(), andrk4()for dense states.vlasov(..., integrator=t.pfg())selects the kinetic integrator of a recipe. - Schemes for a
Model:advance(group, method),strang_split(a, b)andcompose(a, b). - Time grids:
fixed_step(dt, steps=...)orfixed_step(dt, final_time=...), andadaptive_step(initial_dt, final_time=..., tolerance=..., error=[observables]).
Invalid settings raise ValueError with the path of the offending argument.
help(t.vlasov), help(t.Model) and help(t.run) describe each call.
C++ bindings
ttn.core mirrors the C++ API one to one: Program, make_run, method, representation, physics, examples and compile, which returns a C++ Session.
Use it to reproduce a C++ program exactly; the top-level ttn API builds on it.
TTN_CPU_THREADS sets the number of CPU executor threads.
The live browser demo is at https://itsuwari.github.io/vlasov/.
Metadata
Release files for treetensor 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| treetensor-0.2.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| treetensor-0.2.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| treetensor-0.2.0-cp312-abi3-macosx_14_0_arm64.whl | CPython 3.12 | abi3 | macOS 14.0+ ARM64 | Details |
| treetensor-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.17+ x86-64 | Details |
| treetensor-0.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.17+ ARM64 | Details |
| treetensor-0.2.0-cp311-cp311-macosx_14_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 14.0+ ARM64 | Details |
Total release size: 40.5 MB
Release files / treetensor-0.2.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | treetensor-0.2.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 10.1 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
248a0968be9f401c3d71d3ce92346d2ee0563a8f4d6ce26fa07932f778844159
|
|
BLAKE2b-256 checksum How to use checksums |
c5dec19d3ec4378c33463d8f6d0f83cbdef78d4d7fb12c2d403f74772dbfe7b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / treetensor-0.2.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | treetensor-0.2.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4680ca310ffa0852112e465084225bb956fbf685cd75b41f78ec0a7d6ee8d974
|
|
BLAKE2b-256 checksum How to use checksums |
2f34f7bae3a5b5cb9bb195235a12c1728c855accbaa4fe1bdc3925580121609e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / treetensor-0.2.0-cp312-abi3-macosx_14_0_arm64.whl
| Download URL | treetensor-0.2.0-cp312-abi3-macosx_14_0_arm64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.12 abi3 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9d5e7a25d29fa0be2756608a52390d4376d0210fef421249e518e03591fc07da
|
|
BLAKE2b-256 checksum How to use checksums |
4c711e5e060748f15675c8acb7c027ded1d4261134d4457d956cbdd632f73920
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / treetensor-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | treetensor-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 10.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
3fe530f788aeeb494c70bbbfa0d5f6efd09a35bf43ec91e4bce256fdb1121d57
|
|
BLAKE2b-256 checksum How to use checksums |
ca23317539811e9ecb1c4ba3727fcf99876570e38acd3726daa640840f122480
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / treetensor-0.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | treetensor-0.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
adf69621bcca1200105201530d1f8c1ac8f815adfa381d503efbafb002a8bc00
|
|
BLAKE2b-256 checksum How to use checksums |
0004539d2eab856dd0beb84b0aa93248fc3d45758ad028b7ca151fa8c4fe6061
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / treetensor-0.2.0-cp311-cp311-macosx_14_0_arm64.whl
| Download URL | treetensor-0.2.0-cp311-cp311-macosx_14_0_arm64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.11 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
585fab042b2c2c95d8b488675f2d98b93044ace3714e39ea73c2574ce4c270f9
|
|
BLAKE2b-256 checksum How to use checksums |
c72348de1874b8419bc8234e0553195e67d2cb33fa98878c399ca3ec984034b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|