tensorial package#
Subpackages#
- tensorial.datasets package
- tensorial.gcnn package
- Subpackages
- Submodules
- tensorial.gcnn.calc module
- tensorial.gcnn.derivatives module
- tensorial.gcnn.keys module
- tensorial.gcnn.losses module
- tensorial.gcnn.metrics module
- tensorial.gcnn.random module
- tensorial.gcnn.typing module
- tensorial.gcnn.utils module
- Module contents
EdgeVectorsEdgewiseDecodingEdgewiseEmbeddingEdgewiseEncodingEdgewiseLinearGradGraphLossGraphMetricIndexedLinearIndexedRescaleJacfwdJacobianLossNequipLayerNequipLayer.activationsNequipLayer.avg_num_neighboursNequipLayer.interaction_blockNequipLayer.invariant_layersNequipLayer.invariant_neuronsNequipLayer.irreps_outNequipLayer.nameNequipLayer.node_features_fieldNequipLayer.num_speciesNequipLayer.parentNequipLayer.radial_activationNequipLayer.radial_num_layersNequipLayer.radial_num_neuronsNequipLayer.resnetNequipLayer.scopeNequipLayer.setup()NequipLayer.skip_connection
NodewiseDecodingNodewiseEmbeddingNodewiseEncodingNodewiseLinearNodewiseReduceRadialBasisEdgeEmbeddingRadialBasisEdgeEncodingRescaleWeightedLossadapt()diff()grad()graph_from_points()graph_metric()hessian()jacfwd()jacobian()jacrev()reduce()shape_check()transform_fn()with_edge_vectors()
- tensorial.geometry package
- Submodules
- tensorial.geometry.distances module
- tensorial.geometry.jax_neighbours module
- tensorial.geometry.np_neighbours module
- tensorial.geometry.unit_cells module
- Module contents
- tensorial.metrics package
- tensorial.reaxkit package
- Subpackages
- Submodules
- tensorial.reaxkit.cli module
- tensorial.reaxkit.config module
- tensorial.reaxkit.evaluate module
- tensorial.reaxkit.from_data module
- tensorial.reaxkit.keys module
- tensorial.reaxkit.train module
- Module contents
FromDataGraphParityPlotterMetricsPrinterMetricsPrinter.MIN_COLUMN_WIDTHMetricsPrinter.NUMBER_DECIMALSMetricsPrinter.disable()MetricsPrinter.do_log()MetricsPrinter.enable()MetricsPrinter.init_train_tqdm()MetricsPrinter.is_disabledMetricsPrinter.is_enabledMetricsPrinter.on_stage_end()MetricsPrinter.on_stage_iter_start()MetricsPrinter.on_stage_start()
ParityPlotterParityPlotter.get_target_predicted()ParityPlotter.on_fit_end()ParityPlotter.on_predict_batch_end()ParityPlotter.on_predict_end()ParityPlotter.on_test_batch_end()ParityPlotter.on_test_end()ParityPlotter.on_train_batch_end()ParityPlotter.on_train_end()ParityPlotter.on_validation_batch_end()ParityPlotter.on_validation_end()ParityPlotter.reset()
ReaxModule
- tensorial.signals package
- tensorial.training package
Submodules#
tensorial.base module#
- class tensorial.base.Attr(irreps)[source]#
Bases:
ModuleIrreps object attribute
- Parameters:
irreps (
Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int,Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int, IntoIrreps]]]]]])
- from_tensor(tensor)[source]#
This can be overwritten to perform the backward transform of create_tensor
- Parameters:
tensor (
IrrepsArray)- Return type:
Any
- irreps: Irreps#
- tensorial.base.as_array(arr)[source]#
- Get a standard JAX array given either:
a numpy.ndarray
an e3nn_jax.IrrepsArray, or
a jax.Array (in which case it is returned unmodified)
- Parameters:
arr¶ – the array to get the value for
arr (
Union[Array,ndarray,bool,number,bool,int,float,complex,IrrepsArray])
- Return type:
Array- Returns:
the JAX array
- tensorial.base.create(tensorial, value)[source]#
- tensorial.base.create(attr, value)
- tensorial.base.create(attr, value)
- tensorial.base.create(attr, value)
- tensorial.base.create_tensor(tensorial, value)[source]#
- tensorial.base.create_tensor(tensorial, value)
- tensorial.base.create_tensor(tensorial, value)
- tensorial.base.create_tensor(tensorial, value)
- tensorial.base.create_tensor(irreps, value)
- tensorial.base.create_tensor(irreps, value)
- tensorial.base.create_tensor(attr, value)
Create a tensor for a tensorial type
- tensorial.base.from_tensor(tensorial, value)[source]#
- tensorial.base.from_tensor(tensorial, value)
- tensorial.base.from_tensor(tensorial, value)
- tensorial.base.from_tensor(tensorial, value)
- tensorial.base.from_tensor(irreps, value)
- tensorial.base.from_tensor(attr, value)
Create a tensor for a tensorial type
- tensorial.base.get(irreps_obj, tensor, attr_name=None)[source]#
- Parameters:
irreps_obj (
type[IrrepsObj])tensor (
Union[Array,ndarray,bool,number,bool,int,float,complex])attr_name (
str)
- Return type:
Union[Array,ndarray,bool,number,bool,int,float,complex]
tensorial.config module#
tensorial.nn module#
- class tensorial.nn.Sequential(layers, parent=<flax.linen.module._Sentinel object>, name=None)[source]#
Bases:
ModuleApplies a sequential chain of modules just like
flax.linen.Sequential_except_ that flax’s version will expand any tuples that it receives when calling the next layer. This doesn’t play nice with types that subclass tuple, for example,jraph.GraphsTuple, because the layers expect to get a GraphsTuple, not the individual values that make it up.Our behaviour is the same as
flax.linen.Sequentialif we get a tuple, but any subclasses thereof are kept intact when calling the next layer.- Parameters:
layers (
Sequence[Module|partial])parent (
Union[Module,Scope,_Sentinel,None])name (
Optional[str])
- layers: Sequence[Module | partial]#
- name: str | None = None#
- parent: Module | Scope | _Sentinel | None = None#
- scope: Scope | None = None#
- setup()[source]#
Initializes a Module lazily (similar to a lazy
__init__).setupis called once lazily on a module instance when a module is bound, immediately before any other methods like__call__are invoked, or before asetup-defined attribute onselfis accessed.This can happen in three cases:
Immediately when invoking
apply(),init()orinit_and_output().Once the module is given a name by being assigned to an attribute of another module inside the other module’s
setupmethod (see__setattr__()):>>> class MyModule(nn.Module): ... def setup(self): ... submodule = nn.Conv(...) ... # Accessing `submodule` attributes does not yet work here. ... # The following line invokes `self.__setattr__`, which gives ... # `submodule` the name "conv1". ... self.conv1 = submodule ... # Accessing `submodule` attributes or methods is now safe and ... # either causes setup() to be called once.
Once a module is constructed inside a method wrapped with
compact(), immediately before another method is called orsetupdefined attribute is accessed.
- Return type:
None
tensorial.nn_utils module#
- tensorial.nn_utils.get_jaxnn_activation(func)[source]#
Returns the activation function with name form the jax.nn module
- Parameters:
func¶ – the name of the function (as used in
jax.nn)func (
Callable[[Array],Array])
- Return type:
Callable[[Array],Array]- Returns:
the activation function
- tensorial.nn_utils.prepare_mask(mask, array)[source]#
Prepare a mask for use with jnp.where(mask, array, …). This needs to be done to make sure the mask is of the right shape to be compatible with such an operation. The other alternative is
jnp.where(mask, array.T, ...).Tbut this sometimes leads to creating a copy when doing one or both of the transposes. I’m not sure why, but this approach seems to avoid the problem.
tensorial.tensors module#
- class tensorial.tensors.AsIrreps(irreps)[source]#
Bases:
Attr- Parameters:
irreps (
Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int,Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int, IntoIrreps]]]]]])
- class tensorial.tensors.CartesianTensor(formula, keep_ir=None, **irreps_dict)[source]#
Bases:
Attr- Parameters:
formula (
str)
- change_of_basis: Array#
- create_tensor(value)[source]#
- Parameters:
value (
Union[Array,ndarray,bool,number,bool,int,float,complex])- Return type:
IrrepsArray
- formula: str#
- from_tensor(tensor)[source]#
Take an irrep tensor and perform the change of basis transformation back to a Cartesian tensor
- Parameters:
tensor¶ – the irrep tensor
tensor (
Float[IrrepsArray, 'irreps']|Float[IrrepsArray, 'batch irreps'])
- Return type:
']|']- Returns:
the Cartesian tensor
- irreps_dict: dict#
- keep_ir: Irreps | list[Irrep] | None#
- class tensorial.tensors.NoOp(irreps)[source]#
Bases:
AttrAn attribute that keeps IrrepsArrays with specified irreps unchanged
- Parameters:
irreps (
Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int,Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int, IntoIrreps]]]]]])
- class tensorial.tensors.OneHot(num_classes)[source]#
Bases:
AttrOne-hot encoding as a direct sum of even scalars
- Parameters:
num_classes (
int)
- create_tensor(value)[source]#
- Parameters:
value (
Int[Array, 'n_vals'])- Return type:
Float[IrrepsArray, 'n_node num_classes']
- property num_classes: int#
- class tensorial.tensors.SphericalHarmonic(irreps, normalise, normalisation=None, *, algorithm=None)[source]#
Bases:
AttrAn attribute that is the spherical harmonics evaluated as some values
- Parameters:
normalisation (
Optional[Literal['integral','component','norm']])algorithm (
tuple[str])
- algorithm: tuple[str] | None = None#
- normalisation: Literal['integral', 'component', 'norm'] | None = None#
- normalise: bool#
tensorial.typing module#
tensorial.utils module#
- tensorial.utils.infer_backend(pytree)[source]#
Try to infer a backend from the passed pytree
- Return type:
ModuleType
- tensorial.utils.ones(irreps, leading_shape=(), dtype=None, np_=<module 'jax.numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/tensorial/envs/latest/lib/python3.13/site-packages/jax/numpy/__init__.py'>)[source]#
Create an IrrepsArray of ones.
- Parameters:
irreps (
Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int,Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int, IntoIrreps]]]]]])leading_shape (
tuple)dtype (
dtype)
- Return type:
IrrepsArray
- tensorial.utils.ones_like(irreps_array)[source]#
Create an IrrepsArray of ones with the same shape as another IrrepsArray.
- Parameters:
irreps_array (
IrrepsArray)- Return type:
IrrepsArray
- tensorial.utils.zeros(irreps, leading_shape=(), dtype=None, np_=<module 'jax.numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/tensorial/envs/latest/lib/python3.13/site-packages/jax/numpy/__init__.py'>)[source]#
Create an IrrepsArray of zeros.
- Parameters:
irreps (
Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int,Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int, IntoIrreps]]]]]])leading_shape (
tuple)dtype (
dtype)
- Return type:
IrrepsArray
Module contents#
Library for machine learning on physical tensors
- class tensorial.AsIrreps(irreps)[source]#
Bases:
Attr- Parameters:
irreps (
Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int,Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int, IntoIrreps]]]]]])
- class tensorial.Attr(irreps)[source]#
Bases:
ModuleIrreps object attribute
- Parameters:
irreps (
Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int,Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int, IntoIrreps]]]]]])
- from_tensor(tensor)[source]#
This can be overwritten to perform the backward transform of create_tensor
- Parameters:
tensor (
IrrepsArray)- Return type:
Any
- irreps: Irreps#
- class tensorial.CartesianTensor(formula, keep_ir=None, **irreps_dict)[source]#
Bases:
Attr- Parameters:
formula (
str)
- change_of_basis: Array#
- create_tensor(value)[source]#
- Parameters:
value (
Union[Array,ndarray,bool,number,bool,int,float,complex])- Return type:
IrrepsArray
- formula: str#
- from_tensor(tensor)[source]#
Take an irrep tensor and perform the change of basis transformation back to a Cartesian tensor
- Parameters:
tensor¶ – the irrep tensor
tensor (
Float[IrrepsArray, 'irreps']|Float[IrrepsArray, 'batch irreps'])
- Return type:
']|']- Returns:
the Cartesian tensor
- irreps_dict: dict#
- keep_ir: Irreps | list[Irrep] | None#
- class tensorial.NoOp(irreps)[source]#
Bases:
AttrAn attribute that keeps IrrepsArrays with specified irreps unchanged
- Parameters:
irreps (
Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int,Union[None,Irrep,MulIrrep,str,Irreps,Sequence[str|Irrep|MulIrrep|tuple[int, IntoIrreps]]]]]])
- class tensorial.OneHot(num_classes)[source]#
Bases:
AttrOne-hot encoding as a direct sum of even scalars
- Parameters:
num_classes (
int)
- create_tensor(value)[source]#
- Parameters:
value (
Int[Array, 'n_vals'])- Return type:
Float[IrrepsArray, 'n_node num_classes']
- property num_classes: int#
- class tensorial.ReaxModule(model, loss_fn, optimizer, scheduler=None, metrics=None, jit=True, donate_graph=False, output=('predictions', 'targets'))[source]#
Bases:
Module[InputT,OutputT_co]Tensorial REAX module.
- Parameters:
model (
Module)loss_fn (
Callable[[TypeVar(OutputT_co, covariant=True),TypeVar(InputT)],Array])optimizer (
GradientTransformation|Callable[[],GradientTransformation])scheduler (
Callable[[Union[Array,ndarray,bool,number,bool,int,float,complex]],Union[Array,ndarray,bool,number,bool,int,float,complex]] |None)metrics (
dict[str,Metric|str] |None)output (
Sequence[str] |None)
Init function.
- Parameters:
model (
Module)loss_fn (
Callable[[TypeVar(OutputT_co, covariant=True),TypeVar(InputT)],Array])optimizer (
GradientTransformation|Callable[[],GradientTransformation])scheduler (
Callable[[Union[Array,ndarray,bool,number,bool,int,float,complex]],Union[Array,ndarray,bool,number,bool,int,float,complex]] |None)metrics (
dict[str,Metric|str] |None)output (
Sequence[str] |None)
- static calculate_metrics(predictions, targets, metrics)[source]#
- Parameters:
predictions (
TypeVar(OutputT_co, covariant=True))targets (
TypeVar(OutputT_co, covariant=True))metrics (
dict[str,Metric|str])
- Return type:
dict[str,Metric]
- configure_model(_stage, batch, /)[source]#
Called at the beginning of each stage.
A chance to configure the model. This method should be idempotent, i.e. calling it a second should do nothing.
- Parameters:
_stage (
Stage)
- property debug: bool#
- on_before_optimizer_step(_optimizer, grad, /)[source]#
Called before
optimizer.step().If using gradient accumulation, the hook is called once the gradients have been accumulated. See:
accumulate_grad_batches.If clipping gradients, the gradients will not have been clipped yet.
- predict_step(batch, _batch_idx, /)[source]#
Make a model prediction and return the result.
- Parameters:
batch (
TypeVar(InputT))_batch_idx (
int)
- Return type:
TypeVar(OutputT_co, covariant=True)
- static step(params, inputs, _targets, model, loss_fn, metrics=None, output=())[source]#
Calculate loss and, optionally metrics.
- Parameters:
params (
PyTree)inputs (
TypeVar(InputT))_targets (
TypeVar(OutputT_co, covariant=True))model (
Callable[[PyTree,TypeVar(InputT)],TypeVar(OutputT_co, covariant=True)])loss_fn (
Callable[[TypeVar(OutputT_co, covariant=True),TypeVar(InputT)],Array])metrics (
MetricCollection|None)output (
tuple[str,...])
- Return type:
tuple[Array,dict]
- test_step(batch, _batch_idx, /)[source]#
Test step.
- Parameters:
batch (
tuple[TypeVar(InputT),TypeVar(OutputT_co, covariant=True)])_batch_idx (
int)
- Return type:
StepOutput|None
- class tensorial.SphericalHarmonic(irreps, normalise, normalisation=None, *, algorithm=None)[source]#
Bases:
AttrAn attribute that is the spherical harmonics evaluated as some values
- Parameters:
normalisation (
Optional[Literal['integral','component','norm']])algorithm (
tuple[str])
- algorithm: tuple[str] | None = None#
- normalisation: Literal['integral', 'component', 'norm'] | None = None#
- normalise: bool#
- tensorial.as_array(arr)[source]#
- Get a standard JAX array given either:
a numpy.ndarray
an e3nn_jax.IrrepsArray, or
a jax.Array (in which case it is returned unmodified)
- Parameters:
arr¶ – the array to get the value for
arr (
Union[Array,ndarray,bool,number,bool,int,float,complex,IrrepsArray])
- Return type:
Array- Returns:
the JAX array
- tensorial.create(tensorial, value)[source]#
- tensorial.create(attr, value)
- tensorial.create(attr, value)
- tensorial.create(attr, value)
- tensorial.create_tensor(tensorial, value)[source]#
- tensorial.create_tensor(tensorial, value)
- tensorial.create_tensor(tensorial, value)
- tensorial.create_tensor(tensorial, value)
- tensorial.create_tensor(irreps, value)
- tensorial.create_tensor(irreps, value)
- tensorial.create_tensor(attr, value)
Create a tensor for a tensorial type
- tensorial.from_tensor(tensorial, value)[source]#
- tensorial.from_tensor(tensorial, value)
- tensorial.from_tensor(tensorial, value)
- tensorial.from_tensor(tensorial, value)
- tensorial.from_tensor(irreps, value)
- tensorial.from_tensor(attr, value)
Create a tensor for a tensorial type
- tensorial.get(irreps_obj, tensor, attr_name=None)[source]#
- Parameters:
irreps_obj (
type[IrrepsObj])tensor (
Union[Array,ndarray,bool,number,bool,int,float,complex])attr_name (
str)
- Return type:
Union[Array,ndarray,bool,number,bool,int,float,complex]