app.processing.pre.size_casting

Allow for smaller inputs by reducing the size of the type in the AST and parsed info.

Module Contents

class app.processing.pre.size_casting.CreateUnseenNamesVisitor

Keep track of all identifier in an AST to create new ones.

visit_Identifier(node: openqasm3.ast.Identifier) openqasm3.ast.QASMNode

Collect identifier names.

Parameters:

node (openqasm3.ast.Identifier)

Return type:

openqasm3.ast.QASMNode

generate_new_name(name: str) str

Generate a new unused identifier name.

Parameters:

name (str)

Return type:

str

class app.processing.pre.size_casting.SizeCastTransformer(processed: app.processing.graph.ProcessedProgramNode, requested_sizes: dict[int, int | None], name_factory: CreateUnseenNamesVisitor)

Apply the size-reduction casts.

Parameters:
static get_input_index(annotations: list[openqasm3.ast.Annotation]) None | int

Parse annotations for input with index.

Parameters:

annotations (list[openqasm3.ast.Annotation])

Return type:

None | int

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.

Parameters:

node (openqasm3.ast.ClassicalDeclaration)

Return type:

openqasm3.ast.QASMNode | list[openqasm3.ast.QASMNode]

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.

Parameters:

node (openqasm3.ast.QubitDeclaration)

Return type:

openqasm3.ast.QASMNode | list[openqasm3.ast.QASMNode]

app.processing.pre.size_casting.size_cast(node: app.processing.graph.ProcessedProgramNode, requested_sizes: dict[int, int | None]) None

Reduce the size of inputs in a node.

Parameters:
Return type:

None