2222structure/semantics requirements unique to each file
2323
2424Key Features:
25- - Automatic scope and indentation management
26- - Library import and gate definition tracking
27- - Multiple output formats (QASM circuits, includes, gate definitions)
28- - Resource allocation for qubits and classical bits
29- - Extensible design for custom quantum libraries
25+
26+ - Automatic scope and indentation management
27+ - Library import and gate definition tracking
28+ - Multiple output formats (QASM circuits, includes, gate definitions)
29+ - Resource allocation for qubits and classical bits
30+ - Extensible design for custom quantum libraries
3031
3132Class Extensions:
32- - GateBuilder
33- - QasmBuilder
34- - IncludeBuilder
33+ - GateBuilder
34+ - QasmBuilder
35+ - IncludeBuilder
3536"""
3637
3738
@@ -44,23 +45,25 @@ class FileBuilder:
4445 for specialized builders that generate different types of OpenQASM output.
4546
4647 The FileBuilder maintains several key data structures:
47- - imports: List of library files to include
48- - gate_defs: Dictionary mapping gate names to their definitions
49- - gate_refs: List of available gate names for validation
50- - program: Accumulated program code with proper indentation
51- - scope: Current nesting level for proper code formatting
48+
49+ - imports: List of library files to include
50+ - gate_defs: Dictionary mapping gate names to their definitions
51+ - gate_refs: List of available gate names for validation
52+ - program: Accumulated program code with proper indentation
53+ - scope: Current nesting level for proper code formatting
5254 """
5355
5456 def __init__ (self ):
5557 """
5658 Initialize the base file builder with empty data structures.
5759
5860 Sets up the foundational components needed for code generation:
59- - Empty import list for library dependencies
60- - Empty gate definitions dictionary for custom gates
61- - Empty gate references list for scope validation
62- - Empty program string for accumulating generated code
63- - Zero scope level for proper indentation tracking
61+
62+ - Empty import list for library dependencies
63+ - Empty gate definitions dictionary for custom gates
64+ - Empty gate references list for scope validation
65+ - Empty program string for accumulating generated code
66+ - Zero scope level for proper indentation tracking
6467 """
6568 self .imports = [] # List of library names to import (e.g., "std_gates.inc")
6669 self .gate_defs = {} # Dictionary mapping gate names to definition strings
@@ -125,9 +128,10 @@ class GateBuilder(FileBuilder):
125128 complete circuit structure.
126129
127130 Use cases:
128- - Creating custom gate libraries
129- - Generating reusable quantum subroutines
130- - Building modular quantum components
131+
132+ - Creating custom gate libraries
133+ - Generating reusable quantum subroutines
134+ - Building modular quantum components
131135 """
132136
133137 def import_library (self , lib_class , annotated = False ):
@@ -168,12 +172,13 @@ class QasmBuilder(FileBuilder):
168172 resource allocation and generates standards-compliant OpenQASM code.
169173
170174 Features:
171- - Automatic OpenQASM version header generation
172- - Qubit and classical bit resource management
173- - Dynamic resource allocation with claim methods
174- - Complete circuit structure generation
175- - Library import management
176- - Gate definition embedding
175+
176+ - Automatic OpenQASM version header generation
177+ - Qubit and classical bit resource management
178+ - Dynamic resource allocation with claim methods
179+ - Complete circuit structure generation
180+ - Library import management
181+ - Gate definition embedding
177182 """
178183
179184 def __init__ (self , qubits , clbits = None , version = 3 ):
@@ -256,11 +261,12 @@ def build(self):
256261 Generate the complete OpenQASM circuit code.
257262
258263 Assembles all components into a valid OpenQASM program including:
259- 1. Version header (OPENQASM 3;)
260- 2. Include statements for imported libraries
261- 3. Qubit and classical bit declarations
262- 4. Custom gate definitions
263- 5. Main program code
264+
265+ 1. Version header (OPENQASM 3;)
266+ 2. Include statements for imported libraries
267+ 3. Qubit and classical bit declarations
268+ 4. Custom gate definitions
269+ 5. Main program code
264270
265271 Returns:
266272 str: Complete OpenQASM program ready for execution
@@ -319,10 +325,11 @@ class IncludeBuilder(FileBuilder):
319325 subroutines but do not include qubit declarations or main program logic.
320326
321327 Include files are useful for:
322- - Sharing gate definitions across multiple circuits
323- - Creating domain-specific gate libraries
324- - Modular quantum program development
325- - Standardizing common quantum operations
328+
329+ - Sharing gate definitions across multiple circuits
330+ - Creating domain-specific gate libraries
331+ - Modular quantum program development
332+ - Standardizing common quantum operations
326333 """
327334
328335 def build (self ):
0 commit comments