Checks

Metatensor performs shape as well as consistency checks for the metadata during each operation.

There are plans to enable and disable the checks with the functions documented here to bypass some of them, but they are not currently implemented.

metatensor.checks_enabled() bool[source]

Check status if metatensor checks should be performed.

Return type:

bool

metatensor.unsafe_disable_checks()[source]

Disable metatensor checks.

Calling this function permanently disables all metatensor operations checks.

>>> import metatensor as mts
>>> mts.unsafe_disable_checks()
checks disabled
>>> print(mts.checks_enabled())
False

You can also use a compound statement to disable checks only temporarily.

>>> mts.unsafe_enable_checks()
checks enabled
>>> with mts.unsafe_disable_checks():
...     # checks are disabled here
...     print(mts.checks_enabled())
False
>>> print(mts.checks_enabled())
True
metatensor.unsafe_enable_checks()[source]

Enable metatensor checks.

Checks are default enabled. Calling this function permanently enables all metatensor operations checks.

>>> import metatensor as mts
>>> mts.unsafe_enable_checks()
checks enabled
>>> print(mts.checks_enabled())
True

You can also use a compound statement to enable checks only temporarily. This can be useful in nested constructions.

>>> print(mts.checks_enabled())
True
>>> with mts.unsafe_disable_checks():
...     # checks are disabled here
...     print(mts.checks_enabled())
...     with mts.unsafe_enable_checks():
...         # checks enabled here again
...         print(mts.checks_enabled())
False
True
>>> print(mts.checks_enabled())
True