Context

class madspace.Context(*args, **kwargs)

Bases: pybind11_object

Owns the trainable globals and loaded matrix elements for one device.

The state a compiled Function runs against: the named, persistent Tensor globals it reads and writes (network weights, VEGAS grids, …) and the MatrixElementApi libraries loaded via load_matrix_element. All globals and matrix elements live on the same device. Training and generation typically use two contexts, one per role, and periodically sync weights with copy_globals_from.

Overloaded function.

  1. __init__(self: madspace._madspace_py.Context, thread_count: typing.SupportsInt = -1) -> None

A context on the CPU, with thread_count worker threads (-1 for the hardware concurrency).

  1. __init__(self: madspace._madspace_py.Context, device: madspace._madspace_py.Device, thread_count: typing.SupportsInt = -1) -> None

A context on device, with thread_count worker threads (-1 for the hardware concurrency).

add_matrix_element(function, name=None, parameters=None)

Add a matrix element implemented in Python, see PythonFunction. Returns its MatrixElementApi. parameters maps parameter names to the values that replace the defaults of PythonFunction.

copy_globals_from(self: madspace._madspace_py.Context, context: madspace._madspace_py.Context) → None

Overwrite every global also present in context with its value there.

define_global(self: madspace._madspace_py.Context, name: str, dtype: madspace._madspace_py.DataType, shape: collections.abc.Sequence[SupportsInt], requires_grad: bool = False) → madspace._madspace_py.Tensor

Create and zero-initialize a new global named name.

delete_global(self: madspace._madspace_py.Context, name: str) → None

Remove the global named name.

device(self: madspace._madspace_py.Context) → madspace._madspace_py.Device

The device every global and matrix element of this context lives on.

get_global(self: madspace._madspace_py.Context, name: str) → madspace._madspace_py.Tensor

The global tensor named name.

global_exists(self: madspace._madspace_py.Context, name: str) → bool

Whether a global named name exists.

global_names(self: madspace._madspace_py.Context) → list[str]

Names of every global.

global_requires_grad(self: madspace._madspace_py.Context, name: str) → bool

Whether the global named name accumulates a gradient during training.

load_globals(self: madspace._madspace_py.Context, dir: str) → None

Define a global from every .npy file in the tar archive file, named after the file.

load_matrix_element(self: madspace._madspace_py.Context, file: str, param_card: str, parameters: collections.abc.Mapping[str, SupportsFloat] = {}) → madspace._madspace_py.MatrixElementApi

Load the UMAMI matrix element from file, initialized with param_card.

Every entry of parameters is then passed to each process instance through umami_set_parameter (real value, e.g. {"bwcutoff": 15.}, the window of the $-excluded propagators); a library that rejects one of them is an error. Caches by file: loading the same file twice returns the same MatrixElementApi.

matrix_element(self: madspace._madspace_py.Context, index: SupportsInt) → madspace._madspace_py.MatrixElementApi

The matrix element previously loaded at position index; see load_matrix_element.

save_globals(self: madspace._madspace_py.Context, dir: str) → None

Write every global to the tar archive file, as one .npy file per name.