app.enricher ============ .. py:module:: app.enricher .. autoapi-nested-parse:: The enrichment module provides the abstract capability of "enriching" a :class:`~app.model.CompileRequest.Node` with an openqasm implementation (See :class:`~app.model.CompileRequest.ImplementationNode`). The enrichment can be controlled by specifying :class:`~app.enricher.Constraints`. Multiple "strategies" can be connected to the backend by implementing :class:`~app.enricher.EnricherStrategy`. Some services could read implementations from a database or generate them on the fly. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/app/enricher/db_enricher/index /autoapi/app/enricher/encode_value/index /autoapi/app/enricher/exceptions/index /autoapi/app/enricher/gates/index /autoapi/app/enricher/literals/index /autoapi/app/enricher/measure/index /autoapi/app/enricher/merger/index /autoapi/app/enricher/models/index /autoapi/app/enricher/operator/index /autoapi/app/enricher/prepare_state/index /autoapi/app/enricher/splitter/index /autoapi/app/enricher/utils/index Package Contents ---------------- .. py:class:: ParsedImplementationNode(/, **data: Any) Special node that holds just a parsed implementation. .. py:class:: Constraints Constraints to follow during enrichment. :param requested_inputs: Dictionary where the key is the input index and value the type of the node. :param optimizeWidth: If the width of the implementation should be optimized. :param optimizeDepth: If the depth of the implementation should be optimized. .. py:class:: ImplementationMetaData Meta-data of a generated implementation. .. py:class:: EnrichmentResult Result of an enrichment strategy. .. py:class:: EnricherStrategy A single unit capable of enriching some nodes. Each strategy may choose to only support a subset of supported nodes. .. py:method:: enrich(node: app.model.CompileRequest.Node, constraints: Constraints | None) -> collections.abc.Iterable[EnrichmentResult] :async: Enrich the given node according to the specified constraints. Throws if enrichment is not possible. :param node: The node to enrich. :param constraints: Constraints to follow during enrichment. :return: The enriched node. .. py:method:: 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 :async: Insert an enrichment :class:`~app.model.CompileRequest.ImplementationNode` for a given :class:`~app.model.CompileRequest.Node`. :param node: The node to insert the enrichment for. :param implementation: The implementation to insert :param requested_inputs: The (parsed) requested inputs for that node. :param meta_data: meta data for that node :param session: The optional database session to use :return: Whether the insert was successful. .. py:class:: Enricher(*strategies: EnricherStrategy) Handles multiple :class:`~app.enricher.EnricherStrategy`. .. py:method:: try_enrich(node: app.model.CompileRequest.Node, constraints: Constraints | None) -> app.model.CompileRequest.ImplementationNode | ParsedImplementationNode | None :async: Tries to enrich a :class:`~app.model.CompileRequest.Node` according to the specified :class:`~app.enricher.Constraints`. Returns none on failure. :param node: The node to enrich. :param constraints: Constraints to follow during enrichment. :return: The enriched node or none. .. py:method:: enrich(node: app.model.CompileRequest.Node | ParsedImplementationNode, constraints: Constraints | None) -> app.model.CompileRequest.ImplementationNode | ParsedImplementationNode :async: Enrich the given :class:`~app.model.CompileRequest.Node` according to the specified :class:`~app.enricher.Constraints`. Throws ExceptionGroup containing the exceptions from all :class:`~app.enricher.EnricherStrategy`. :param node: The node to enrich. :param constraints: Constraints to follow during enrichment. :return: Enriched node. :raises ExceptionGroup: If no strategy could generate an implementation. .. py:method:: 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 :async: Insert the enrichment :class:`~app.model.CompileRequest.ImplementationNode` for the given :class:`~app.model.CompileRequest.Node`. :param node: The node to insert the enrichment for. :param implementation: The implementation to insert :param requested_inputs: The (parsed) requested inputs for that node. :param meta_data: meta data for that node :param session: The optional database session to use