Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::ComponentFactory Class Referenceexport

Factory for reconstructing components from serialized archives. More...

Static Public Member Functions

template<DeviceType TDeviceType>
static std::shared_ptr< void > createFromArchive (ModelArchive &archive, const std::string &component_name, std::shared_ptr< ExecutionContext< TDeviceType > > exec_context)
 Placeholder: create a component instance from archive.
static std::string getComponentName (const SerializationMetadata &meta)
 Get component name from metadata.
static int64_t getComponentVersion (const SerializationMetadata &meta)
 Get component version from metadata.
static std::string getPrecision (const SerializationMetadata &meta)
 Get optional precision from metadata.
static ComponentType parseComponentType (const SerializationMetadata &meta)
 Parse the built-in component kind from metadata.
static SerializationMetadata readComponentMeta (ModelArchive &archive, const std::string &component_name)

Detailed Description

Factory for reconstructing components from serialized archives.

Provides type-safe helpers that read component metadata using SerializationMetadata abstraction, eliminating JSON exposure in component reconstruction code.

Design Pattern:

  • Uses ModelArchive scoping API for organized access
  • Abstracts serialization format via SerializationMetadata
  • Provides extensible dispatch infrastructure for component types
Examples
/home/runner/work/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx.

Member Function Documentation

◆ createFromArchive()

template<DeviceType TDeviceType>
std::shared_ptr< void > Mila::Dnn::ComponentFactory::createFromArchive ( ModelArchive & archive,
const std::string & component_name,
std::shared_ptr< ExecutionContext< TDeviceType > > exec_context )
inlinestatic

Placeholder: create a component instance from archive.

Full instantiation requires dispatching on both component kind and on-archive precision and is currently unimplemented. This method demonstrates the scoped read pattern and throws on invocation.

Implementation Strategy:

  • Push scope "components/<name>"
  • Read meta/config/tensors using relative paths
  • Dispatch to the concrete Component<...>::fromArchive_ factory
  • Return properly typed component instance
Parameters
archiveModelArchive containing serialized component
component_nameName of component to instantiate
exec_contextExecution context for the component
Returns
Shared pointer to component (placeholder type)
Exceptions
std::runtime_errorAlways throws - dispatch not yet implemented
Note
Returning std::shared_ptr<void> is an intentional placeholder type – replace with the project's chosen type-erased component handle once the dispatch plumbing is implemented.

Future usage pattern:

archive, "fc1", exec_context);
static std::shared_ptr< void > createFromArchive(ModelArchive &archive, const std::string &component_name, std::shared_ptr< ExecutionContext< TDeviceType > > exec_context)
Placeholder: create a component instance from archive.
Definition ComponentFactory.ixx:189
Examples
/home/runner/work/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx.

◆ getComponentName()

std::string Mila::Dnn::ComponentFactory::getComponentName ( const SerializationMetadata & meta)
inlinestatic

Get component name from metadata.

Retrieves the component name field.

Parameters
metaComponent metadata
Returns
Component name
Exceptions
std::runtime_errorif name field is missing
Examples
/home/runner/work/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx.

◆ getComponentVersion()

int64_t Mila::Dnn::ComponentFactory::getComponentVersion ( const SerializationMetadata & meta)
inlinestatic

Get component version from metadata.

Retrieves the component version field for compatibility checking during deserialization.

Parameters
metaComponent metadata
Returns
Version number
Exceptions
std::runtime_errorif version field is missing
Examples
/home/runner/work/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx.

◆ getPrecision()

std::string Mila::Dnn::ComponentFactory::getPrecision ( const SerializationMetadata & meta)
inlinestatic

Get optional precision from metadata.

Retrieves the precision field if present, otherwise returns empty string.

Parameters
metaComponent metadata
Returns
Precision string or empty if not specified
Examples
/home/runner/work/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx.

◆ parseComponentType()

ComponentType Mila::Dnn::ComponentFactory::parseComponentType ( const SerializationMetadata & meta)
inlinestatic

Parse the built-in component kind from metadata.

Convenience helper that looks up the "type" field in the component metadata and maps it to the typed ComponentType enum.

Parameters
metaComponent metadata
Returns
ComponentType enum value
Exceptions
std::runtime_errorif the metadata does not contain a "type" field
std::runtime_errorif the type string is not recognized
auto meta = readComponentMeta(archive, "fc1");
if (type == ComponentType::Linear) { ... }
ComponentType
Canonical list of framework-known component types.
Definition ComponentType.ixx:28
static ComponentType parseComponentType(const SerializationMetadata &meta)
Parse the built-in component kind from metadata.
Definition ComponentFactory.ixx:92
Examples
/home/runner/work/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx.

The documentation for this class was generated from the following file: