Context¶
- class madspace.Context(*args, **kwargs)¶
Bases:
pybind11_objectOwns 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.
__init__(self: madspace._madspace_py.Context, thread_count: typing.SupportsInt = -1) -> None
A context on the CPU, with
thread_countworker threads (-1for the hardware concurrency).__init__(self: madspace._madspace_py.Context, device: madspace._madspace_py.Device, thread_count: typing.SupportsInt = -1) -> None
A context on
device, withthread_countworker threads (-1for the hardware concurrency).- add_matrix_element(function, name=None, parameters=None)¶
Add a matrix element implemented in Python, see
PythonFunction. Returns itsMatrixElementApi.parametersmaps parameter names to the values that replace the defaults ofPythonFunction.
- copy_globals_from(self: madspace._madspace_py.Context, context: madspace._madspace_py.Context) None¶
Overwrite every global also present in
contextwith 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
nameexists.
- 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
nameaccumulates a gradient during training.
- load_globals(self: madspace._madspace_py.Context, dir: str) None¶
Define a global from every
.npyfile in the tar archivefile, 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 withparam_card.Every entry of
parametersis then passed to each process instance throughumami_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 byfile: 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.npyfile per name.