utils
triplum.utils ¶
Utilities independent of Triplum's domain and benchmark contracts.
FingerprintedComputationMixin ¶
Identify a configured computation by loaded definitions and selected settings.
Implement fingerprint_config, returning {} for stateless computations. Referenced application helpers contribute automatically; select external content IDs as settings. No instance attributes are implicitly inspected. Override fingerprint for full control.
fingerprint_config ¶
fingerprint_config() -> dict[str, object]
Select semantic settings; Paths identify names, not file contents.
Values support finite scalars, lists/tuples, string-keyed mappings, Paths and nested fingerprint() values. Mapping order is irrelevant: select ordered pairs explicitly if iteration order affects the computation.
Source code in src/triplum/utils/fingerprint.py
715 716 717 718 719 720 721 722 | |
fingerprint ¶
fingerprint() -> str
Return a SHA-256 digest; selected configuration is evaluated each time.
Source code in src/triplum/utils/fingerprint.py
724 725 726 727 728 729 730 731 732 733 734 735 | |
canonical_json ¶
canonical_json(obj: Any) -> str
Source code in src/triplum/utils/cache.py
10 11 | |
content_key ¶
content_key(kind: str, payload: Any) -> str
Source code in src/triplum/utils/cache.py
14 15 16 17 18 19 | |
definition_hash ¶
definition_hash(definition: object) -> str
Hash loaded Python methods, constants, defaults, captures and annotation definitions.
Includes inherited methods and domain Protocol bodies; excludes exact framework helpers. Application helpers and their referenced settings are followed statically. Referenced application classes use the same class projection when supported, otherwise only their name; traced snapshots retain their existing class boundary. External libraries, mutable class attributes and Pydantic schemas are not inferred. Each hash observes current definitions and settings; keep them stable during hashing and execution. Filename and source positions are ignored; interpreter/compiler upgrades can change the digest.
Source code in src/triplum/utils/fingerprint.py
693 694 695 696 697 698 699 700 701 702 703 704 | |
source_hash
cached
¶
source_hash(cls: type) -> str
Hash of a class's source with comments, formatting and docstrings removed.
Source code in src/triplum/utils/fingerprint.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |