app.enricher
The enrichment module provides the abstract capability of “enriching” a Node with an openqasm implementation
(See ImplementationNode).
The enrichment can be controlled by specifying Constraints.
Multiple “strategies” can be connected to the backend by implementing EnricherStrategy.
Some services could read implementations from a database or generate them on the fly.
Submodules
- app.enricher.db_enricher
- app.enricher.encode_value
- app.enricher.exceptions
- app.enricher.gates
- app.enricher.literals
- app.enricher.measure
- app.enricher.merger
- app.enricher.models
- app.enricher.operator
- app.enricher.prepare_state
- app.enricher.qiskit_prepare
- app.enricher.splitter
- app.enricher.utils
- app.enricher.workflow
Package Contents
- class app.enricher.ParsedImplementationNode(/, **data: Any)
Special node that holds just a parsed implementation.
- Parameters:
data (Any)
- class app.enricher.Constraints
Constraints to follow during enrichment.
- Parameters:
requested_inputs – Dictionary where the key is the input index and value the type of the node.
optimizeWidth – If the width of the implementation should be optimized.
optimizeDepth – If the depth of the implementation should be optimized.
requested_input_values – Optional literal values resolved from the model for the inputs.
- class app.enricher.ImplementationMetaData
Meta-data of a generated implementation.
- class app.enricher.EnrichmentResult
Result of an enrichment strategy.
- class app.enricher.EnricherStrategy
A single unit capable of enriching some nodes. Each strategy may choose to only support a subset of supported nodes.
- async enrich(node: app.model.CompileRequest.Node, constraints: Constraints | None) collections.abc.Iterable[EnrichmentResult]
Enrich the given node according to the specified constraints. Throws if enrichment is not possible.
- Parameters:
node (app.model.CompileRequest.Node) – The node to enrich.
constraints (Constraints | None) – Constraints to follow during enrichment.
- Returns:
The enriched node.
- Return type:
- async insert_enrichment(node: app.model.CompileRequest.Node, implementation: str, requested_inputs: dict[int, app.model.data_types.LeqoSupportedType], meta_data: app.model.CompileRequest.SingleInsertMetaData, session: sqlalchemy.ext.asyncio.AsyncSession | None = None) bool
Insert an enrichment
ImplementationNodefor a givenNode.- Parameters:
node (app.model.CompileRequest.Node) – The node to insert the enrichment for.
implementation (str) – The implementation to insert
requested_inputs (dict[int, app.model.data_types.LeqoSupportedType]) – The (parsed) requested inputs for that node.
meta_data (app.model.CompileRequest.SingleInsertMetaData) – meta data for that node
session (sqlalchemy.ext.asyncio.AsyncSession | None) – The optional database session to use
- Returns:
Whether the insert was successful.
- Return type:
- class app.enricher.Enricher(*strategies: EnricherStrategy)
Handles multiple
EnricherStrategy.- Parameters:
strategies (EnricherStrategy)
- async try_enrich(node: app.model.CompileRequest.Node, constraints: Constraints | None) app.model.CompileRequest.ImplementationNode | ParsedImplementationNode | None
Tries to enrich a
Nodeaccording to the specifiedConstraints. Returns none on failure.- Parameters:
node (app.model.CompileRequest.Node) – The node to enrich.
constraints (Constraints | None) – Constraints to follow during enrichment.
- Returns:
The enriched node or none.
- Return type:
app.model.CompileRequest.ImplementationNode | ParsedImplementationNode | None
- async enrich(node: app.model.CompileRequest.Node | ParsedImplementationNode, constraints: Constraints | None) app.model.CompileRequest.ImplementationNode | ParsedImplementationNode
Enrich the given
Nodeaccording to the specifiedConstraints. Throws ExceptionGroup containing the exceptions from allEnricherStrategy.- Parameters:
node (app.model.CompileRequest.Node | ParsedImplementationNode) – The node to enrich.
constraints (Constraints | None) – Constraints to follow during enrichment.
- Returns:
Enriched node.
- Raises:
ExceptionGroup – If no strategy could generate an implementation.
- Return type:
app.model.CompileRequest.ImplementationNode | ParsedImplementationNode
- async insert_enrichment(node: app.model.CompileRequest.Node, implementation: str, requested_inputs: dict[int, app.model.data_types.LeqoSupportedType], meta_data: app.model.CompileRequest.SingleInsertMetaData, session: sqlalchemy.ext.asyncio.AsyncSession | None = None) None
Insert the enrichment
ImplementationNodefor the givenNode.- Parameters:
node (app.model.CompileRequest.Node) – The node to insert the enrichment for.
implementation (str) – The implementation to insert
requested_inputs (dict[int, app.model.data_types.LeqoSupportedType]) – The (parsed) requested inputs for that node.
meta_data (app.model.CompileRequest.SingleInsertMetaData) – meta data for that node
session (sqlalchemy.ext.asyncio.AsyncSession | None) – The optional database session to use
- Return type:
None