Base Services
The base services module defines the fundamental service abstractions used throughout the Hiten framework.
Persistence Service
_PersistenceServiceBase()
Mixin offering a uniform persistence API around plain callables. Handles save, load, and load-in-place operations.
- class hiten.algorithms.types.services.base._PersistenceServiceBase(*, save_fn, load_fn, load_inplace_fn=None)[source]
Bases:
ABC
Mixin offering a uniform persistence API around plain callables.
- Parameters:
save_fn (Callable[..., Any]) – The function to save the object.
load_fn (Callable[..., Any]) – The function to load the object.
load_inplace_fn (Optional[Callable[..., Any]] = None) – The function to load the object in place.
- save(target, filepath, **kwargs)[source]
Save the object to a file.
- Parameters:
target (Any) – The object to save.
filepath (Any) – The path to the file to save the object to.
- Return type:
Dynamics Service
_DynamicsServiceBase()
Mixin offering a uniform dynamics API around plain callables. Provides caching and domain-specific computations.
- class hiten.algorithms.types.services.base._DynamicsServiceBase(domain_obj)[source]
Bases:
ABC
Mixin offering a uniform dynamics API around plain callables.
- Parameters:
domain_obj (Any) – The domain object.
- cache
The cache service.
- Type:
- get_or_create(key, factory)[source]
Get or create a cache value.
- Parameters:
key (Any) – The cache key.
factory (Callable[[], CacheValueT]) – The factory function to create the cache value.
- Return type:
CacheValueT
- __getitem__(key)[source]
Get a cache value.
- Parameters:
key (Any) – The cache key.
- Return type:
CacheValueT
- __setitem__(key, value)[source]
Set a cache value.
- Parameters:
key (Any) – The cache key.
value (CacheValueT) – The cache value.
- Return type:
CacheValueT
- reset(key=None)[source]
Reset the cache.
- Parameters:
key (Any, optional) – The cache key to reset. If None, the entire cache is cleared.
- Return type:
None
Cache Service
_CacheServiceBase()
Helper providing lazy caching for dynamics-oriented adapters. Manages cache operations and key generation.
- class hiten.algorithms.types.services.base._CacheServiceBase[source]
Bases:
Generic
[CacheValueT
]Helper providing lazy caching for dynamics-oriented adapters.
- Parameters:
_cache (Dict[Any, CacheValueT]) – The cache dictionary.
- get_or_create(key, factory)[source]
Get or create a cache value.
- Parameters:
key (Any) – The cache key.
factory (Callable[[], CacheValueT]) – The factory function to create the cache value.
- Return type:
CacheValueT
- get(key)[source]
Get a cache value.
- Parameters:
key (Any) – The cache key.
- Return type:
CacheValueT
- set(key, value)[source]
Set a cache value.
- Parameters:
key (Any) – The cache key.
value (CacheValueT) – The cache value.
- Return type:
CacheValueT
- reset(key=None)[source]
Reset the cache.
- Parameters:
key (Any, optional) – The cache key to reset. If None, the entire cache is cleared.
- Return type:
None
Service Bundle
_ServiceBundleBase()
Lightweight helper for service bundles offering ergonomic helpers. Coordinates multiple services for domain objects.
- class hiten.algorithms.types.services.base._ServiceBundleBase(domain_obj)[source]
Bases:
ABC
Lightweight helper for service bundles offering ergonomic helpers.
- Parameters:
domain_obj (Any) – The domain object.
- __getitem__(service_name)[source]
Get a service by name.
This method allows dynamic access to any service in the service bundle.
- Parameters:
service_name (str) – The name of the service to retrieve (e.g., ‘correction’, ‘continuation’)
- Returns:
The requested service instance
- Return type:
Any
- Raises:
AttributeError – If the requested service is not available
- abstractmethod classmethod default(domain_obj)[source]
Create a default service bundle.
- Parameters:
domain_obj (Any) – The domain object.
- Return type:
Create a service bundle with a shared dynamics service.
- Parameters:
domain_obj (Any) – The domain object.
dynamics (_DynamicsServiceBase) – The dynamics service.
- Return type: