qbraid_algorithms.qtran.FileBuilder

class qbraid_algorithms.qtran.FileBuilder

Base class for all OpenQASM code builders.

Provides core functionality for managing imports, gate definitions, program content, and scope tracking. This class serves as the foundation for specialized builders that generate different types of OpenQASM output.

The FileBuilder maintains several key data structures:

  • imports: List of library files to include

  • gate_defs: Dictionary mapping gate names to their definitions

  • gate_refs: List of available gate names for validation

  • program: Accumulated program code with proper indentation

  • scope: Current nesting level for proper code formatting

__init__()

Initialize the base file builder with empty data structures.

Sets up the foundational components needed for code generation:

  • Empty import list for library dependencies

  • Empty gate definitions dictionary for custom gates

  • Empty gate references list for scope validation

  • Empty program string for accumulating generated code

  • Zero scope level for proper indentation tracking

Methods

__init__()

Initialize the base file builder with empty data structures.

import_library(lib_class[, annotated])

Import and initialize a quantum gate library.

program_append(line)

Append a line of code to the program with proper indentation.