@@ -62,14 +62,17 @@ Main Compilation Function
6262 circuit.cx(0 , 1 )
6363 circuit.cx(1 , 2 )
6464
65- # Basic compilation
66- compiled = compile (circuit)
65+ # Basic compilation (returns CompileResult dict)
66+ result = compile (circuit)
67+ circuit_ir = result[" circuit" ] # IR object
68+ compiled_source = result[" compiled_source" ] # None or source string
6769
6870 # Specify optimization
69- compiled = compile (
71+ result = compile (
7072 circuit,
7173 options = {' optimization_level' : 2 }
7274 )
75+ circuit_ir = result[" circuit" ]
7376
7477 **Example 2: Pulse Circuit Compilation **:
7578
@@ -86,13 +89,15 @@ Main Compilation Function
8689 " anharmonicity" : [- 330e6 , - 320e6 ]
8790 })
8891
89- # Compile to TQASM (auto-detects pulse operations)
90- result = compile (circuit, output = " tqasm" )
91- # Returns TQASM code as string
92+ # Compile to QASM3 (returns CompileResult dict)
93+ result = compile (circuit, output = " qasm3" )
94+ qasm3_code = result[" compiled_source" ] # QASM3 string with defcal
95+ circuit_ir = result[" circuit" ] # Original circuit IR
9296
9397 # Or compile to pulse IR (preserves waveform objects)
9498 result = compile (circuit, output = " pulse_ir" )
95- # Returns Circuit with pulse operations
99+ pulse_ir = result[" compiled_source" ] # PulseProgram IR object
100+ circuit_ir = result[" circuit" ]
96101
97102 **Example 3: Cloud Submission (homebrew_s2) **:
98103
@@ -111,10 +116,93 @@ Main Compilation Function
111116 })
112117
113118 # Compile to TQASM (auto-converts to tyxonq_homebrew_tqasm for homebrew_s2)
114- tqasm_code = compile (circuit, output = " tqasm" )
119+ result = compile (circuit, output = " tqasm" )
120+ tqasm_code = result[" compiled_source" ] # TQASM string (QASM2 compatible)
115121
116122 # Submit to cloud
117- result = circuit.run()
123+ result = circuit.run(shots = 100 )
124+
125+ Pulse Compilation Function
126+ ==========================
127+
128+ .. autofunction :: tyxonq.compiler.compile_pulse
129+
130+ **Signature **:
131+
132+ .. code-block :: python
133+
134+ def compile_pulse (
135+ pulse_program , # PulseProgram to compile
136+ output : str = " pulse_ir" , # Output format: "pulse_ir", "tqasm", "openqasm3"
137+ device_params : Dict = None , # Device parameters (qubit_freq, anharmonicity, etc.)
138+ calibrations : Dict = None , # Custom pulse calibrations
139+ device : str = None , # Target device for format selection
140+ options : Dict = None , # Compilation options (inline_pulses, etc.)
141+ ** kwargs
142+ ) -> PulseCompileResult
143+
144+ ** Returns** :
145+
146+ ``PulseCompileResult `` TypedDict with three fields:
147+
148+ .. code-block :: python
149+
150+ {
151+ " pulse_program" : PulseProgram, # Original PulseProgram IR
152+ " compiled_pulse_schedule" : Optional[str ], # Compiled schedule (TQASM/QASM3) or IR object
153+ " metadata" : Dict[str , Any] # Compilation metadata
154+ }
155+
156+ **Output Format Options **:
157+
158+ - ``"pulse_ir" `` (default): TyxonQ native Pulse IR
159+ - compiled_pulse_schedule: PulseProgram IR object
160+ - ``"tqasm" `` / ``"tqasm0.2" ``: TQASM 0.2 format (cloud-ready)
161+ - compiled_pulse_schedule: TQASM string with defcal
162+ - ``"openqasm3" ``: OpenQASM 3.0 with pulse extensions
163+ - compiled_pulse_schedule: QASM3 string with defcal
164+
165+ **Example 1: Basic Pulse Compilation **:
166+
167+ .. code-block :: python
168+
169+ from tyxonq.core.ir.pulse import PulseProgram
170+ from tyxonq.compiler import compile_pulse
171+
172+ # Create pulse program
173+ prog = PulseProgram(1 )
174+ prog.drag(0 , amp = 1.0 , duration = 160 , sigma = 40 , beta = 0.2 , qubit_freq = 5.0e9 )
175+
176+ # Compile to Pulse IR (default)
177+ result = compile_pulse(prog, device_params = {
178+ " qubit_freq" : [5.0e9 ],
179+ " anharmonicity" : [- 330e6 ]
180+ })
181+ pulse_ir = result[" pulse_program" ] # PulseProgram IR
182+ schedule = result[" compiled_pulse_schedule" ] # None (IR format)
183+
184+ **Example 2: Compile to TQASM for Cloud **:
185+
186+ .. code-block :: python
187+
188+ # Compile to TQASM with full defcal definitions
189+ result = compile_pulse(
190+ prog,
191+ output = " tqasm" ,
192+ device_params = {
193+ " qubit_freq" : [5.0e9 ],
194+ " anharmonicity" : [- 330e6 ]
195+ },
196+ options = {" inline_pulses" : True } # Include full defcal definitions
197+ )
198+ tqasm_code = result[" compiled_pulse_schedule" ] # TQASM string with defcal
199+
200+ # Submit to cloud
201+ circuit = Circuit(1 )
202+ task = circuit.device(provider = " tyxonq" , device = " homebrew_s2" ).run(
203+ source = tqasm_code,
204+ shots = 100
205+ )
118206
119207 Optimization Levels
120208===================
@@ -565,4 +653,25 @@ See Also
565653- :doc: `/user_guide/compiler/index ` - Compiler User Guide
566654- :doc: `/api/core/index ` - Core API
567655- :doc: `/api/devices/index ` - Devices API
656+ - :doc: `/examples/basic_examples ` - Compilation Examples
657+ # Benchmark different levels
658+ for level in [0, 1, 2, 3]:
659+ start = time.time()
660+ compiled = circuit.compile(optimization_level=level)
661+ duration = time.time() - start
662+
663+ print(f"Level {level}:")
664+ print(f" Time: {duration:.3f}s")
665+ print(f" Depth: {compiled.depth()}")
666+ print(f" Gates: {compiled.size()}")
667+
668+ See Also
669+ ========
670+
671+ - :doc: `/user_guide/compiler/index ` - Compiler User Guide
672+ - :doc: `/api/core/index ` - Core API
673+ - :doc: `/api/devices/index ` - Devices API
674+ - :doc: `/examples/basic_examples ` - Compilation Examples
675+ - :doc: `/api/core/index ` - Core API
676+ - :doc: `/api/devices/index ` - Devices API
568677- :doc: `/examples/basic_examples ` - Compilation Examples
0 commit comments