Capability registry API
quantas.api.registry allows a frontend to discover scientific modules,
passive types, and supported operations without importing implementation
classes or forcing every workflow into one inheritance hierarchy.
from quantas.api import registry
from quantas.api.registry import Capability
for descriptor in registry.list_modules():
print(descriptor.name, sorted(item.value for item in descriptor.capabilities))
qha = registry.get("qha")
run_qha = qha.operation(Capability.RUN)
Capability and descriptor contracts
- class quantas.api.registry.Capability(*values)
Bases:
str,EnumFrontend-neutral operation supported by a public API namespace.
The values describe workflow capabilities rather than implementation classes. Frontends use them to discover operations without importing Click, Rich, Dash, Matplotlib, or module-internal calculators.
Notes
A capability is declared only when the corresponding operation is part of the supported
quantas.apicontract. Scientific modules are not required to implement the same capability set.
- class quantas.api.registry.ModuleDescriptor(name, title, api_module, result_key, capabilities, operations, input_type_name=None, options_type_name=None, result_type_name=None)
Bases:
objectDescribe one public scientific namespace without importing it eagerly.
- Parameters:
- namestr
Stable module identifier used in result metadata.
- titlestr
Human-readable scientific module title.
- api_modulestr
Import path of the public namespace.
- result_keystr or None
Key used in
quantas.models.ResultData, when applicable.- capabilitiesfrozenset of Capability
Operations supported by the namespace.
- operationstuple of tuple
Mapping from capabilities to public function names.
- input_type_name, options_type_name, result_type_namestr or None
Public type aliases resolved lazily from the namespace.
- Parameters:
name (str)
title (str)
api_module (str)
result_key (str | None)
capabilities (frozenset[Capability])
operations (tuple[tuple[Capability, str], ...])
input_type_name (str | None)
options_type_name (str | None)
result_type_name (str | None)
- load()
Import and return the public namespace lazily.
- Returns:
- ModuleType
Imported module identified by
api_module.
- Raises:
- ImportError
If the declared namespace cannot be imported.
- Return type:
ModuleType
- has(capability)
Return whether one capability is declared.
- Parameters:
- capabilityCapability or str
Capability enum member or its stable string value.
- Returns:
- bool
Truewhen the module advertises the capability.
- Raises:
- ValueError
If a string is not a valid
Capabilityvalue.
- Parameters:
capability (Capability | str)
- Return type:
bool
- operation(capability)
Resolve the public function implementing one capability.
- Raises:
- ValueError
If the capability is not declared for this module.
- AttributeError
If the declared public operation is absent.
- Parameters:
capability (Capability | str)
- Return type:
Callable[[…], Any]
- resolve_type(name)
Resolve a declared public type alias lazily.
- Parameters:
- namestr or None
Public type alias in the module namespace.
Nonerepresents an unsupported or inapplicable contract type.
- Returns:
- type or None
Resolved public class, or
Nonewhen no alias was declared.
- Raises:
- AttributeError
If the declared alias is missing from the namespace.
- TypeError
If the resolved object is not a class.
- Parameters:
name (str | None)
- Return type:
type[Any] | None
- property input_type: type[Any] | None
Return the public input type, when applicable.
- Returns:
- type or None
Namespace
Input/dataset class, orNonewhen the workflow has no single input contract.
- property options_type: type[Any] | None
Return the public options type, when applicable.
- Returns:
- type or None
Namespace options class, or
Nonewhen configuration is operation-specific.
- property result_type: type[Any] | None
Return the public scientific result type, when applicable.
- Returns:
- type or None
Typed scientific payload or fit-result class exposed by the namespace, or
Nonewhen no single result type applies.
Discovery
- quantas.api.registry.get(name)
Return one public module descriptor by stable identifier.
- Parameters:
- namestr
Stable module identifier such as
qhaoreos.
- Returns:
- ModuleDescriptor
Public API and capability descriptor.
- Raises:
- KeyError
If the module identifier is unknown.
- Parameters:
name (str)
- Return type:
- quantas.api.registry.iter_modules()
Iterate over public scientific module descriptors.
- Returns:
- iterator of ModuleDescriptor
Lazy iterator over the stable descriptor sequence.
- Return type:
Iterator[ModuleDescriptor]
- quantas.api.registry.list_modules()
Return all public scientific module descriptors.
- Returns:
- tuple of ModuleDescriptor
Immutable descriptors in stable frontend display order.
- Return type:
tuple[ModuleDescriptor, …]
Result dispatch
module_from_result inspects native metadata rather than filename
conventions. open_result dispatches to the public module reader or EOS
archive as appropriate.
- quantas.api.registry.module_from_result(path)
Inspect native HDF5 metadata and return the responsible module.
- Parameters:
- pathstr or Path
Native Quantas HDF5 result or archive.
- Returns:
- ModuleDescriptor
Descriptor selected from the persisted
metadata/modulevalue.
- Raises:
- ValueError
If Quantas metadata are absent.
- KeyError
If the persisted module identifier is unsupported.
- Parameters:
path (str | Path)
- Return type:
- quantas.api.registry.open_result(path, *, writable=False)
Open a native Quantas result using metadata-driven dispatch.
- Parameters:
- pathstr or Path
Native Quantas HDF5 result or archive.
- writablebool, optional
Request writable access. This is supported only by archive-style modules such as EOS.
- Returns:
- Any
quantas.models.ResultDatafor single-shot modules or an active module-specific archive for archive-style workflows.
- Raises:
- ValueError
If writable access is requested for a single-shot result or the module has no registered native reader.
- KeyError
If the persisted module identifier is unsupported.
- Parameters:
path (str | Path)
writable (bool)
- Return type:
Any
Notes
EOS returns an active archive because it stores datasets and immutable fit records rather than one result envelope. Callers must close that archive.