app.processing.pre.size_casting =============================== .. py:module:: app.processing.pre.size_casting .. autoapi-nested-parse:: Allow for smaller inputs by reducing the size of the type in the AST and parsed info. Module Contents --------------- .. py:class:: CreateUnseenNamesVisitor Keep track of all identifier in an AST to create new ones. .. py:method:: visit_Identifier(node: openqasm3.ast.Identifier) -> openqasm3.ast.QASMNode Collect identifier names. .. py:method:: generate_new_name(name: str) -> str Generate a new unused identifier name. .. py:class:: SizeCastTransformer(processed: app.processing.graph.ProcessedProgramNode, requested_sizes: dict[int, int | None], name_factory: CreateUnseenNamesVisitor) Apply the size-reduction casts. :param processed: The ProcessedProgramNode to be modified in-place. :param requested_sizes: Specifying the required sizes for the input indexes. :param name_factory: Used for getting new unseen names. .. py:method:: get_input_index(annotations: list[openqasm3.ast.Annotation]) -> None | int :staticmethod: Parse annotations for input with index. .. py:method:: visit_ClassicalDeclaration(node: openqasm3.ast.ClassicalDeclaration) -> openqasm3.ast.QASMNode | list[openqasm3.ast.QASMNode] Reduce size of a classical input. - Handle int/float: This is done by reducing the size in the declaration and changing its name. Then the old name is declared with old size and assigned to the new name. This seems to be the way that Openqasm 3 handles implicit casts, but there was no concrete example of this in the specification. .. warning:: Qiskit does not support the declaration of int/float yet. Making this currently unusable. - Handle bit: Similar to qubits, declare a dummy register to be concatenated to the now smaller input. This is done in little endian order. .. warning:: The dummy register is not initialized to zero as this is unsupported by qiskit. It is assumed that they are 0 by default. .. py:method:: visit_QubitDeclaration(node: openqasm3.ast.QubitDeclaration) -> openqasm3.ast.QASMNode | list[openqasm3.ast.QASMNode] Reduce size of a qubit input. This is done by splitting the old declaration in two: - one for the linked qubits - one for the clean ancillas Both are created with new identifiers. Then the old name is aliased to a concatenation of the previous variables. The concatenation uses little endian order. .. py:function:: size_cast(node: app.processing.graph.ProcessedProgramNode, requested_sizes: dict[int, int | None]) -> None Reduce the size of inputs in a node. :param node: The node to be modified in-place. :param requested_sizes: Specifying the sizes to cast to by input index.